mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 11:48:59 +08:00
Update Readme
Apply style to code
This commit is contained in:
parent
4d6bac193a
commit
02264b8da5
@ -88,7 +88,7 @@ Check wiki : https://github.com/luc-github/ESP3D/wiki/Direct-ESP3D-commands
|
||||
Feedback on 2.0 was : ESP3D being a library is not really useful and make setup more complex, so now we are back to simple application.
|
||||
|
||||
1. Please follow installation of the ESP core you want to use : [ESP8266 core version](https://github.com/esp8266/Arduino) or [ESP32 core version](https://github.com/espressif/arduino-esp32)
|
||||
2. Add libraries
|
||||
2. Add manually libraries present in libraries directory -these versions are verified to work with ESP3D
|
||||
If you want async webserver (currently not recommended due to reliability issues):
|
||||
* ESPAsyncWebServer from @me-no-dev
|
||||
if you target ESP8266
|
||||
@ -98,14 +98,14 @@ if you target ESP32:
|
||||
Specific for ESP32
|
||||
* ESP32SSDP
|
||||
If you want sync webserver (recommended as stable):
|
||||
* arduinoWebSockets fron @Links2004
|
||||
* arduinoWebSockets from @Links2004
|
||||
|
||||
If you want OLED support:
|
||||
* oled-ssd1306 from @squix78
|
||||
|
||||
If you want DHT11/22 support:
|
||||
* DHT_sensor_library_for_ESPx from @beegee-tokyo
|
||||
3. Compile project from examples\basicesp3d\basicesp3d.ino) according target: ESP8266 board or ESP32 board, please review config.h to enable disable a feature, by default athenticatio is disabled and all others are enabled.
|
||||
3. Compile project esp3d.ino according target: ESP8266 board or ESP32 board, please review config.h to enable disable a feature, by default athenticatio is disabled and all others are enabled.
|
||||
* for ESP8266 set CPU freq to 160MHz for better (https://github.com/luc-github/ESP3D/wiki/Install-Instructions)
|
||||
4. Upload the data content on ESP3D file system
|
||||
* Using SPIFFS uploader, this plugin and install instructions is available on each ESP core - please refere to it
|
||||
|
@ -710,7 +710,9 @@ void handle_web_command (AsyncWebServerRequest *request)
|
||||
ESPCOM::processFromSerial (true);
|
||||
LOG ("End PurgeSerial\r\n")
|
||||
can_process_serial = false;
|
||||
request->onDisconnect([request](){can_process_serial = true;});
|
||||
request->onDisconnect([request]() {
|
||||
can_process_serial = true;
|
||||
});
|
||||
//send command
|
||||
LOG ("Send Command\r\n")
|
||||
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
||||
@ -1112,7 +1114,9 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
LOG("Upload Start\r\n")
|
||||
String command = "M29";
|
||||
String resetcmd = "M110 N0";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
resetcmd = "N0 M110";
|
||||
}
|
||||
lineNb=1;
|
||||
//close any ongoing upload and get current line number
|
||||
if(!sendLine2Serial (command,1, &lineNb)) {
|
||||
@ -1262,7 +1266,8 @@ void handle_onevent_connect(AsyncEventSourceClient *client)
|
||||
}
|
||||
}
|
||||
|
||||
void handle_Websocket_Event(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
void handle_Websocket_Event(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len)
|
||||
{
|
||||
//Handle WebSocket event
|
||||
}
|
||||
|
||||
|
@ -150,17 +150,12 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
LOG("you are User\r\n");
|
||||
}
|
||||
#ifdef DEBUG_ESP3D
|
||||
if ( auth_type == LEVEL_ADMIN)
|
||||
{
|
||||
if ( auth_type == LEVEL_ADMIN) {
|
||||
LOG("admin identified\r\n");
|
||||
}
|
||||
else {
|
||||
if( auth_type == LEVEL_USER)
|
||||
{
|
||||
} else {
|
||||
if( auth_type == LEVEL_USER) {
|
||||
LOG("user identified\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG("guest identified\r\n");
|
||||
}
|
||||
}
|
||||
@ -458,15 +453,25 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
time(&now);
|
||||
localtime_r(&now, &tmstruct);
|
||||
stmp = String((tmstruct.tm_year)+1900) + "-";
|
||||
if (((tmstruct.tm_mon)+1) < 10) stmp +="0";
|
||||
if (((tmstruct.tm_mon)+1) < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(( tmstruct.tm_mon)+1) + "-";
|
||||
if (tmstruct.tm_mday < 10) stmp +="0";
|
||||
if (tmstruct.tm_mday < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_mday) + " ";
|
||||
if (tmstruct.tm_hour < 10) stmp +="0";
|
||||
if (tmstruct.tm_hour < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_hour) + ":";
|
||||
if (tmstruct.tm_min < 10) stmp +="0";
|
||||
if (tmstruct.tm_min < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_min) + ":";
|
||||
if (tmstruct.tm_sec < 10) stmp +="0";
|
||||
if (tmstruct.tm_sec < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_sec);
|
||||
ESPCOM::println(stmp.c_str(), output, espresponse);
|
||||
}
|
||||
@ -701,8 +706,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
break;
|
||||
#endif
|
||||
//display ESP3D EEPROM version detected
|
||||
case 300:
|
||||
{
|
||||
case 300: {
|
||||
uint8_t v = CONFIG::get_EEPROM_version();
|
||||
ESPCOM::println (String(v).c_str(), output, espresponse);
|
||||
}
|
||||
@ -1555,16 +1559,18 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
}
|
||||
int32_t linenb = 1;
|
||||
cmd_params.trim() ;
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb))ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
else { //it may failed because of skip if repetier so let's reset numbering first
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb)) {
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
} else { //it may failed because of skip if repetier so let's reset numbering first
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
//reset numbering
|
||||
String cmd = "M110 N0";
|
||||
if (sendLine2Serial (cmd, -1, NULL)) {
|
||||
linenb = 1;
|
||||
//if success let's try again to send the command
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb))ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
else {
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb)) {
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
} else {
|
||||
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
||||
response = false;
|
||||
}
|
||||
@ -1887,7 +1893,9 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
|
||||
ESPCOM::print (F (" # hostname:"), output, espresponse);
|
||||
ESPCOM::print (shost, output, espresponse);
|
||||
if (WiFi.getMode() == WIFI_AP) ESPCOM::print (F("(AP mode)"), output, espresponse);
|
||||
if (WiFi.getMode() == WIFI_AP) {
|
||||
ESPCOM::print (F("(AP mode)"), output, espresponse);
|
||||
}
|
||||
|
||||
ESPCOM::println ("", output, espresponse);
|
||||
}
|
||||
|
@ -142,7 +142,8 @@ void CONFIG::InitFirmwareTarget()
|
||||
SetFirmwareTarget (UNKNOWN_FW) ;
|
||||
}
|
||||
}
|
||||
void CONFIG::InitOutput(){
|
||||
void CONFIG::InitOutput()
|
||||
{
|
||||
byte bflag = 0;
|
||||
if (!CONFIG::read_byte (EP_OUTPUT_FLAG, &bflag ) ) {
|
||||
bflag = 0;
|
||||
@ -150,7 +151,8 @@ void CONFIG::InitOutput(){
|
||||
CONFIG::output_flag = bflag;
|
||||
}
|
||||
|
||||
bool CONFIG::is_locked(byte flag){
|
||||
bool CONFIG::is_locked(byte flag)
|
||||
{
|
||||
return ((CONFIG::output_flag & flag) == flag);
|
||||
}
|
||||
|
||||
@ -163,8 +165,9 @@ void CONFIG::InitDirectSD()
|
||||
bool CONFIG::InitBaudrate(long value)
|
||||
{
|
||||
long baud_rate = 0;
|
||||
if (value > 0)baud_rate = value;
|
||||
else {
|
||||
if (value > 0) {
|
||||
baud_rate = value;
|
||||
} else {
|
||||
if ( !CONFIG::read_buffer (EP_BAUD_RATE, (byte *) &baud_rate, INTEGER_LENGTH) ) {
|
||||
return false;
|
||||
}
|
||||
@ -248,7 +251,8 @@ void CONFIG::esp_restart (bool async)
|
||||
};
|
||||
}
|
||||
#ifdef DHT_FEATURE
|
||||
void CONFIG::InitDHT(bool refresh) {
|
||||
void CONFIG::InitDHT(bool refresh)
|
||||
{
|
||||
if (!refresh) {
|
||||
byte bflag = DEFAULT_DHT_TYPE;
|
||||
int ibuf = DEFAULT_DHT_INTERVAL;
|
||||
@ -261,7 +265,9 @@ void CONFIG::InitDHT(bool refresh) {
|
||||
}
|
||||
CONFIG::DHT_interval = ibuf;
|
||||
}
|
||||
if (CONFIG::DHT_type != 255) dht.setup(ESP_DHT_PIN,(DHTesp::DHT_MODEL_t)CONFIG::DHT_type); // Connect DHT sensor to GPIO ESP_DHT_PIN
|
||||
if (CONFIG::DHT_type != 255) {
|
||||
dht.setup(ESP_DHT_PIN,(DHTesp::DHT_MODEL_t)CONFIG::DHT_type); // Connect DHT sensor to GPIO ESP_DHT_PIN
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void CONFIG::InitPins()
|
||||
@ -502,7 +508,8 @@ char * CONFIG::mac2str (uint8_t mac [WL_MAC_ADDR_LENGTH])
|
||||
}
|
||||
|
||||
|
||||
bool CONFIG::set_EEPROM_version(uint8_t v){
|
||||
bool CONFIG::set_EEPROM_version(uint8_t v)
|
||||
{
|
||||
byte byte_buffer[6];
|
||||
byte_buffer[0]='E';
|
||||
byte_buffer[1]='S';
|
||||
@ -513,10 +520,13 @@ bool CONFIG::set_EEPROM_version(uint8_t v){
|
||||
return CONFIG::write_buffer (EP_EEPROM_VERSION, byte_buffer, 6);
|
||||
}
|
||||
|
||||
uint8_t CONFIG::get_EEPROM_version(){
|
||||
uint8_t CONFIG::get_EEPROM_version()
|
||||
{
|
||||
byte byte_buffer[6];
|
||||
long baud_rate;
|
||||
if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) return EEPROM_V0;
|
||||
if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) {
|
||||
return EEPROM_V0;
|
||||
}
|
||||
if ((byte_buffer[0]=='E') && (byte_buffer[1]=='S') && (byte_buffer[2]=='P')&& (byte_buffer[3]=='3') && (byte_buffer[4]=='D')) {
|
||||
return byte_buffer[5];
|
||||
}
|
||||
@ -530,10 +540,13 @@ uint8_t CONFIG::get_EEPROM_version(){
|
||||
return EEPROM_V0;
|
||||
}
|
||||
|
||||
bool CONFIG::adjust_EEPROM_settings(){
|
||||
bool CONFIG::adjust_EEPROM_settings()
|
||||
{
|
||||
uint8_t v = get_EEPROM_version();
|
||||
bool bdone =false;
|
||||
if (v == EEPROM_CURRENT_VERSION) return true;
|
||||
if (v == EEPROM_CURRENT_VERSION) {
|
||||
return true;
|
||||
}
|
||||
if (v == 1) {
|
||||
bdone =true;
|
||||
#ifdef SDCARD_FEATURE
|
||||
@ -984,8 +997,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
||||
//if higher than 1MB take out SPIFFS
|
||||
if (flashsize > 1024 * 1024) {
|
||||
flashsize = (1024 * 1024)-ESP.getSketchSize()-1024;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
flashsize = flashsize - ESP.getSketchSize()-info.totalBytes-1024;
|
||||
}
|
||||
ESPCOM::print(formatBytes(flashsize).c_str(), output, espresponse);
|
||||
|
@ -504,11 +504,15 @@ const uint16_t Setting[][2] = {
|
||||
class AsyncResponseStream;
|
||||
typedef AsyncResponseStream ESPResponseStream;
|
||||
#else
|
||||
class ESPResponseStream{
|
||||
class ESPResponseStream
|
||||
{
|
||||
public:
|
||||
bool header_sent;
|
||||
String buffer_web;
|
||||
ESPResponseStream(){header_sent=false;};
|
||||
ESPResponseStream()
|
||||
{
|
||||
header_sent=false;
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -86,7 +86,8 @@ DHTesp dht;
|
||||
#endif
|
||||
|
||||
//Contructor
|
||||
Esp3D::Esp3D() {
|
||||
Esp3D::Esp3D()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -286,16 +287,27 @@ void Esp3D::process()
|
||||
if (now_oled - last_oled_update > 1000) {
|
||||
last_oled_update = now_oled;
|
||||
//refresh signal
|
||||
if ((WiFi.getMode() == WIFI_OFF) || !wifi_config.WiFi_on) OLED_DISPLAY::display_signal(-1);
|
||||
else OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
if ((WiFi.getMode() == WIFI_OFF) || !wifi_config.WiFi_on) {
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
} else {
|
||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
}
|
||||
//if line 0 is > 85 refresh
|
||||
if(OLED_DISPLAY::L0_size >85)OLED_DISPLAY::display_text(OLED_DISPLAY::L0.c_str(), 0, 0, 85);
|
||||
if(OLED_DISPLAY::L0_size >85) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L0.c_str(), 0, 0, 85);
|
||||
}
|
||||
//if line 1 is > 128 refresh
|
||||
if(OLED_DISPLAY::L1_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L1.c_str(), 0, 16, 128);
|
||||
if(OLED_DISPLAY::L1_size >128) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L1.c_str(), 0, 16, 128);
|
||||
}
|
||||
//if line 2 is > 128 refresh
|
||||
if(OLED_DISPLAY::L2_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L2.c_str(), 0, 32, 128);
|
||||
if(OLED_DISPLAY::L2_size >128) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L2.c_str(), 0, 32, 128);
|
||||
}
|
||||
//if line 3 is > 128 refresh
|
||||
if(OLED_DISPLAY::L3_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L3.c_str(), 0, 48, 128);
|
||||
if(OLED_DISPLAY::L3_size >128) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L3.c_str(), 0, 48, 128);
|
||||
}
|
||||
OLED_DISPLAY::update_lcd();
|
||||
}
|
||||
}
|
||||
|
@ -73,13 +73,17 @@ const char ESP3D_Logo[] = {
|
||||
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
void OLED_DISPLAY::splash(){
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
void OLED_DISPLAY::splash()
|
||||
{
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
esp_display.drawXbm(33, 10, ESP3D_Logo_width, ESP3D_Logo_height, ESP3D_Logo);
|
||||
update_lcd();
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::begin(){
|
||||
void OLED_DISPLAY::begin()
|
||||
{
|
||||
//For Embeded OLED on Wifi kit 32
|
||||
#if HELTEC_EMBEDDED_PIN > 0
|
||||
pinMode(HELTEC_EMBEDDED_PIN,OUTPUT);
|
||||
@ -94,19 +98,29 @@ void OLED_DISPLAY::begin(){
|
||||
#endif
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::setCursor(int col, int row){
|
||||
if (col!=-1) OLED_DISPLAY::col = col;
|
||||
if (row!=-1) OLED_DISPLAY::row = row;
|
||||
void OLED_DISPLAY::setCursor(int col, int row)
|
||||
{
|
||||
if (col!=-1) {
|
||||
OLED_DISPLAY::col = col;
|
||||
}
|
||||
void OLED_DISPLAY::print(String & s){
|
||||
if (row!=-1) {
|
||||
OLED_DISPLAY::row = row;
|
||||
}
|
||||
}
|
||||
void OLED_DISPLAY::print(String & s)
|
||||
{
|
||||
OLED_DISPLAY::print(s.c_str());
|
||||
}
|
||||
void OLED_DISPLAY::print(const char * s){
|
||||
void OLED_DISPLAY::print(const char * s)
|
||||
{
|
||||
display_text(s, col, row);
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::display_signal(int value, int x, int y) {
|
||||
if(CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
void OLED_DISPLAY::display_signal(int value, int x, int y)
|
||||
{
|
||||
if(CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
//clear area only
|
||||
esp_display.setColor(BLACK);
|
||||
esp_display.fillRect(x, y, x + 46, 16);
|
||||
@ -150,8 +164,11 @@ void OLED_DISPLAY::display_signal(int value, int x, int y) {
|
||||
}
|
||||
|
||||
|
||||
void OLED_DISPLAY::display_progress(int value, int x, int y) {
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
void OLED_DISPLAY::display_progress(int value, int x, int y)
|
||||
{
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
esp_display.setFont(ArialMT_Plain_10);
|
||||
esp_display.setColor(BLACK);
|
||||
esp_display.fillRect(x, y, x + 128, 16);
|
||||
@ -161,8 +178,11 @@ void OLED_DISPLAY::display_progress(int value, int x, int y) {
|
||||
esp_display.drawString(x+102, y - 1, p.c_str());
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w) {
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w)
|
||||
{
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
esp_display.setColor(BLACK);
|
||||
esp_display.fillRect(x, y, x + w, 2);
|
||||
esp_display.setColor(WHITE);
|
||||
@ -171,7 +191,8 @@ void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w) {
|
||||
|
||||
//max is 128 by default but can be 85 for first line
|
||||
|
||||
void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) {
|
||||
void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max)
|
||||
{
|
||||
static int shift_pos[4] = {-1, -1, -1, -1};
|
||||
static int t[4] = {0, 0, 0, 0};
|
||||
|
||||
@ -180,19 +201,16 @@ void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) {
|
||||
OLED_DISPLAY::L1 = txt;
|
||||
OLED_DISPLAY::L1_size = esp_display.getStringWidth( txt);
|
||||
p=1;
|
||||
}
|
||||
else if (y==32){
|
||||
} else if (y==32) {
|
||||
OLED_DISPLAY::L2 = txt;
|
||||
OLED_DISPLAY::L2_size = esp_display.getStringWidth( txt);
|
||||
p=2;
|
||||
}
|
||||
else if (y==0){
|
||||
} else if (y==0) {
|
||||
max = 85;
|
||||
OLED_DISPLAY::L0 = txt;
|
||||
OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt);
|
||||
p=0;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
OLED_DISPLAY::L3 = txt;
|
||||
OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt);
|
||||
p=3;
|
||||
@ -222,10 +240,12 @@ void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) {
|
||||
esp_display.drawString(x, y, Stxt.c_str());
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::update_lcd(){
|
||||
void OLED_DISPLAY::update_lcd()
|
||||
{
|
||||
esp_display.display();
|
||||
}
|
||||
void OLED_DISPLAY::clear_lcd(){
|
||||
void OLED_DISPLAY::clear_lcd()
|
||||
{
|
||||
esp_display.clear();
|
||||
}
|
||||
int OLED_DISPLAY::col = 0;
|
||||
|
@ -118,7 +118,8 @@ long ESPCOM::baudRate(tpipe output)
|
||||
#endif
|
||||
return br;
|
||||
}
|
||||
size_t ESPCOM::available(tpipe output){
|
||||
size_t ESPCOM::available(tpipe output)
|
||||
{
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
case SERIAL_PIPE:
|
||||
@ -140,9 +141,14 @@ size_t ESPCOM::available(tpipe output){
|
||||
break;
|
||||
}
|
||||
}
|
||||
size_t ESPCOM::write(tpipe output, uint8_t d){
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && (block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) return 0;
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL))return 0;
|
||||
size_t ESPCOM::write(tpipe output, uint8_t d)
|
||||
{
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && (block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) {
|
||||
return 0;
|
||||
}
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL)) {
|
||||
return 0;
|
||||
}
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
case SERIAL_PIPE:
|
||||
@ -213,16 +219,26 @@ void ESPCOM::print (String & data, tpipe output, ESPResponseStream *espresponse
|
||||
}
|
||||
void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresponse)
|
||||
{
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && ( block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) return;
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL))return;
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && ( block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) {
|
||||
return;
|
||||
}
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL)) {
|
||||
return;
|
||||
}
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
if ((TCP_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_TCP))return;
|
||||
if ((TCP_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_TCP)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef WS_DATA_FEATURE
|
||||
if ((WS_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_WSOCKET))return;
|
||||
if ((WS_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
if ((OLED_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
if ((OLED_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
@ -268,8 +284,7 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
|
||||
}
|
||||
break;
|
||||
#ifdef WS_DATA_FEATURE
|
||||
case WS_PIPE:
|
||||
{
|
||||
case WS_PIPE: {
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
//Todo
|
||||
#else
|
||||
@ -280,8 +295,7 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
|
||||
#endif
|
||||
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
case OLED_PIPE:
|
||||
{
|
||||
case OLED_PIPE: {
|
||||
if (!ESPCOM::block_2_oled) {
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
|
||||
OLED_DISPLAY::print(data);
|
||||
@ -291,14 +305,17 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case PRINTER_PIPE:
|
||||
{
|
||||
case PRINTER_PIPE: {
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n")))ESPCOM::print(data, OLED_PIPE);
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
|
||||
ESPCOM::print(data, OLED_PIPE);
|
||||
}
|
||||
#endif
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_M117)) {
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n")))ESPCOM::print ("M117 ", DEFAULT_PRINTER_PIPE);
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
|
||||
ESPCOM::print ("M117 ", DEFAULT_PRINTER_PIPE);
|
||||
}
|
||||
ESPCOM::print (data, DEFAULT_PRINTER_PIPE);
|
||||
}
|
||||
}
|
||||
@ -384,9 +401,13 @@ bool ESPCOM::processFromSerial (bool async)
|
||||
#ifdef WS_DATA_FEATURE
|
||||
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) web_interface->web_socket.textAll(sbuf, len);
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) {
|
||||
web_interface->web_socket.textAll(sbuf, len);
|
||||
}
|
||||
#else
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET) && socket_server)socket_server->sendBIN(current_socket_id,sbuf,len);
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET) && socket_server) {
|
||||
socket_server->sendBIN(current_socket_id,sbuf,len);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -59,14 +59,14 @@
|
||||
#include "syncwebserver.h"
|
||||
WebSocketsServer * socket_server;
|
||||
|
||||
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
|
||||
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length)
|
||||
{
|
||||
|
||||
switch(type) {
|
||||
case WStype_DISCONNECTED:
|
||||
//USE_SERIAL.printf("[%u] Disconnected!\n", num);
|
||||
break;
|
||||
case WStype_CONNECTED:
|
||||
{
|
||||
case WStype_CONNECTED: {
|
||||
IPAddress ip = socket_server->remoteIP(num);
|
||||
//USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
|
||||
String s = "CURRENT_ID:" + String(num);
|
||||
@ -159,10 +159,15 @@ void handle_login()
|
||||
}
|
||||
|
||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||
if (auth_level == LEVEL_GUEST) auths = F("guest");
|
||||
else if (auth_level == LEVEL_USER) auths = F("user");
|
||||
else if (auth_level == LEVEL_ADMIN) auths = F("admin");
|
||||
else auths = F("???");
|
||||
if (auth_level == LEVEL_GUEST) {
|
||||
auths = F("guest");
|
||||
} else if (auth_level == LEVEL_USER) {
|
||||
auths = F("user");
|
||||
} else if (auth_level == LEVEL_ADMIN) {
|
||||
auths = F("admin");
|
||||
} else {
|
||||
auths = F("???");
|
||||
}
|
||||
|
||||
//check is it is a submission or a query
|
||||
if (web_interface->web_server.hasArg("SUBMIT")) {
|
||||
@ -207,8 +212,11 @@ void handle_login()
|
||||
String newpassword = web_interface->web_server.arg("NEWPASSWORD");
|
||||
if (CONFIG::isLocalPasswordValid(newpassword.c_str())) {
|
||||
int pos=0;
|
||||
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) pos = EP_ADMIN_PWD;
|
||||
else pos = EP_USER_PWD;
|
||||
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) {
|
||||
pos = EP_ADMIN_PWD;
|
||||
} else {
|
||||
pos = EP_USER_PWD;
|
||||
}
|
||||
if (!CONFIG::write_string(pos,newpassword.c_str())) {
|
||||
msg_alert_error=true;
|
||||
smsg = F("Error: Cannot apply changes");
|
||||
@ -261,7 +269,9 @@ void handle_login()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (code == 200) smsg = F("Ok");
|
||||
if (code == 200) {
|
||||
smsg = F("Ok");
|
||||
}
|
||||
|
||||
//build JSON
|
||||
String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\"";
|
||||
@ -559,8 +569,11 @@ void SPIFFSFileupload()
|
||||
if(upload.status == UPLOAD_FILE_START) {
|
||||
String upload_filename = upload.filename;
|
||||
String sizeargname = upload_filename + "S";
|
||||
if (upload_filename[0] != '/') filename = "/" + upload_filename;
|
||||
else filename = upload.filename;
|
||||
if (upload_filename[0] != '/') {
|
||||
filename = "/" + upload_filename;
|
||||
} else {
|
||||
filename = upload.filename;
|
||||
}
|
||||
//according User or Admin the root is different as user is isolate to /user when admin has full access
|
||||
if(auth_level != LEVEL_ADMIN) {
|
||||
upload_filename = filename;
|
||||
@ -685,8 +698,11 @@ void WebUpdateUpload()
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
} else {
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESPCOM::println (F ("Update 0%%"), PRINTER_PIPE);
|
||||
else ESPCOM::println (F ("Update 0%"), PRINTER_PIPE);
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
|
||||
ESPCOM::println (F ("Update 0%%"), PRINTER_PIPE);
|
||||
} else {
|
||||
ESPCOM::println (F ("Update 0%"), PRINTER_PIPE);
|
||||
}
|
||||
}
|
||||
//Upload write
|
||||
//**************
|
||||
@ -699,7 +715,9 @@ void WebUpdateUpload()
|
||||
String s = "Update ";
|
||||
s+= String(last_upload_update);
|
||||
s+= "%";
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) s+= "%";
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
|
||||
s+= "%";
|
||||
}
|
||||
ESPCOM::println (s.c_str(), PRINTER_PIPE);
|
||||
}
|
||||
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||
@ -711,8 +729,11 @@ void WebUpdateUpload()
|
||||
} else if(upload.status == UPLOAD_FILE_END) {
|
||||
if(Update.end(true)) { //true to set the size to the current progress
|
||||
//Now Reboot
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESPCOM::println (F("Update 100%%"), PRINTER_PIPE);
|
||||
else ESPCOM::println (F("Update 100%"), PRINTER_PIPE);
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
|
||||
ESPCOM::println (F("Update 100%%"), PRINTER_PIPE);
|
||||
} else {
|
||||
ESPCOM::println (F("Update 100%"), PRINTER_PIPE);
|
||||
}
|
||||
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
||||
}
|
||||
} else if(upload.status == UPLOAD_FILE_ABORTED) {
|
||||
@ -993,8 +1014,7 @@ void handle_web_command()
|
||||
break;
|
||||
}
|
||||
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
|
||||
if (!current_line.startsWith( "ok "))
|
||||
{
|
||||
if (!current_line.startsWith( "ok ")) {
|
||||
buffer2send +=current_line;
|
||||
buffer2send +="\n";
|
||||
}
|
||||
@ -1177,7 +1197,9 @@ void SDFile_serial_upload()
|
||||
LOG("Upload Start\r\n")
|
||||
String command = "M29";
|
||||
String resetcmd = "M110 N0";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
resetcmd = "N0 M110";
|
||||
}
|
||||
lineNb=1;
|
||||
//close any ongoing upload and get current line number
|
||||
if(!sendLine2Serial (command,1, &lineNb)) {
|
||||
|
@ -76,18 +76,22 @@ long id_connection = 0;
|
||||
uint8_t Checksum(const char * line, uint16_t lineSize)
|
||||
{
|
||||
uint8_t checksum_val =0;
|
||||
for (uint16_t i=0; i < lineSize; i++) checksum_val = checksum_val ^ ((uint8_t)line[i]);
|
||||
for (uint16_t i=0; i < lineSize; i++) {
|
||||
checksum_val = checksum_val ^ ((uint8_t)line[i]);
|
||||
}
|
||||
return checksum_val;
|
||||
}
|
||||
|
||||
String CheckSumLine(const char* line, uint32_t linenb){
|
||||
String CheckSumLine(const char* line, uint32_t linenb)
|
||||
{
|
||||
String linechecksum = "N" + String(linenb)+ " " + line;
|
||||
uint8_t crc = Checksum(linechecksum.c_str(), linechecksum.length());
|
||||
linechecksum+="*"+String(crc);
|
||||
return linechecksum;
|
||||
}
|
||||
|
||||
bool purge_serial(){
|
||||
bool purge_serial()
|
||||
{
|
||||
uint32_t start = millis();
|
||||
uint8_t buf [51];
|
||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||
@ -106,7 +110,9 @@ bool purge_serial(){
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
String s = (const char *)buf;
|
||||
//repetier never stop sending data so no need to wait if have 'wait' or 'busy'
|
||||
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1))return true;
|
||||
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {
|
||||
return true;
|
||||
}
|
||||
LOG("Purge interrupted\r\n")
|
||||
}
|
||||
CONFIG::wait (5);
|
||||
@ -116,13 +122,17 @@ bool purge_serial(){
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wait_for_data(uint32_t timeout){
|
||||
size_t wait_for_data(uint32_t timeout)
|
||||
{
|
||||
uint32_t start = millis();
|
||||
while ((ESPCOM::available(DEFAULT_PRINTER_PIPE) < 2) && ((millis()-start) < timeout))CONFIG::wait (10);
|
||||
while ((ESPCOM::available(DEFAULT_PRINTER_PIPE) < 2) && ((millis()-start) < timeout)) {
|
||||
CONFIG::wait (10);
|
||||
}
|
||||
return ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||
}
|
||||
|
||||
uint32_t Get_lineNumber(String & response){
|
||||
uint32_t Get_lineNumber(String & response)
|
||||
{
|
||||
int32_t l = 0;
|
||||
String sresend = "Resend:";
|
||||
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
@ -156,12 +166,20 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
||||
String line2send;
|
||||
String sok = "ok";
|
||||
String sresend = "Resend:";
|
||||
if (newlinenb) *newlinenb = linenb;
|
||||
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)sresend = "rs N";
|
||||
if (newlinenb) {
|
||||
*newlinenb = linenb;
|
||||
}
|
||||
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
sresend = "rs N";
|
||||
}
|
||||
if (linenb != -1) {
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) sok+=" " + String(linenb);
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
sok+=" " + String(linenb);
|
||||
}
|
||||
line2send = CheckSumLine(line.c_str(),linenb);
|
||||
} else line2send = line;
|
||||
} else {
|
||||
line2send = line;
|
||||
}
|
||||
//purge serial as nothing is supposed to interfere with upload
|
||||
purge_serial();
|
||||
LOG ("Send line ")
|
||||
|
@ -175,7 +175,8 @@ void WIFI_CONFIG::Safe_Setup()
|
||||
|
||||
|
||||
//wifi event
|
||||
void onWiFiEvent(WiFiEvent_t event){
|
||||
void onWiFiEvent(WiFiEvent_t event)
|
||||
{
|
||||
|
||||
switch (event) {
|
||||
case WIFI_EVENT_STAMODE_CONNECTED:
|
||||
@ -477,7 +478,9 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
WiFi.setSleepMode ( (WiFiSleepType_t) sleep_mode);
|
||||
#else
|
||||
//for backward compatibility
|
||||
if ((wifi_ps_type_t) sleep_mode == WIFI_PS_MAX_MODEM)sleep_mode=WIFI_PS_MIN_MODEM;
|
||||
if ((wifi_ps_type_t) sleep_mode == WIFI_PS_MAX_MODEM) {
|
||||
sleep_mode=WIFI_PS_MIN_MODEM;
|
||||
}
|
||||
esp_wifi_set_ps ( (wifi_ps_type_t) sleep_mode);
|
||||
#endif
|
||||
delay (100);
|
||||
@ -562,8 +565,9 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
ESPCOM::print("Connected", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
} else if (WiFi.getMode() != WIFI_STA) {
|
||||
ESPCOM::print("AP Ready", OLED_PIPE);
|
||||
}
|
||||
else if (WiFi.getMode() != WIFI_STA) ESPCOM::print("AP Ready", OLED_PIPE);
|
||||
#endif
|
||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user