From 99578de54286e5917fa0d272361233197adcafcc Mon Sep 17 00:00:00 2001 From: Luc Date: Sun, 4 Dec 2016 17:13:42 +0100 Subject: [PATCH] Add a check and counter if printer is heating to avoid to go in long loop when sending command --- esp3d/command.cpp | 9 +++++---- esp3d/command.h | 2 +- esp3d/webinterface.cpp | 14 +++++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/esp3d/command.cpp b/esp3d/command.cpp index 70f3c600..b1d1ab23 100644 --- a/esp3d/command.cpp +++ b/esp3d/command.cpp @@ -484,12 +484,13 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) } } -void COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) +bool COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) { String buffer2; LOG("Check Command:") LOG(buffer) LOG("\r\n") + bool is_temp = false; //feed the WD for safety delay(0); //if direct access to SDCard no need to handle the M20 command answer @@ -512,12 +513,11 @@ void COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) web_interface->fileslist.clear(); //block any new output to serial from ESP to avoid pollution if (handlelockserial)(web_interface->blockserial) = true; - return; + return is_temp; } #endif -#ifdef TEMP_MONITORING_FEATURE int Tpos = buffer.indexOf("T:"); -#endif + if (Tpos > -1 ) is_temp = true; #ifdef POS_MONITORING_FEATURE int Xpos = buffer.indexOf("X:"); int Ypos = buffer.indexOf("Y:"); @@ -673,6 +673,7 @@ void COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) } } #endif + return is_temp; } //read a buffer in an array diff --git a/esp3d/command.h b/esp3d/command.h index 64e56aec..2967993d 100644 --- a/esp3d/command.h +++ b/esp3d/command.h @@ -31,7 +31,7 @@ public: static void read_buffer_serial(uint8_t *b, size_t len); static void read_buffer_serial(uint8_t b); static void read_buffer_tcp(uint8_t b); - static void check_command(String buffer, tpipe output, bool handlelockserial = true); + static bool check_command(String buffer, tpipe output, bool handlelockserial = true); static void execute_command(int cmd,String cmd_params, tpipe output); static String get_param(String & cmd_params, const char * id, bool withspace = false); static bool isadmin(String & cmd_params); diff --git a/esp3d/webinterface.cpp b/esp3d/webinterface.cpp index d91079d3..e5c5221a 100644 --- a/esp3d/webinterface.cpp +++ b/esp3d/webinterface.cpp @@ -3803,10 +3803,11 @@ void handle_web_command(){ String current_buffer; String current_line; int pos; + int temp_counter = 0; String tmp; bool datasent = false; - //pickup the list - while (count < MAX_TRY){ + //pickup the list + while (count < MAX_TRY){ //give some time between each buffer if (Serial.available()){ count = 0; @@ -3836,7 +3837,7 @@ void handle_web_command(){ LOG(current_line) LOG("\r\n") //check command - COMMAND::check_command(current_line, NO_PIPE, false); + if (COMMAND::check_command(current_line, NO_PIPE, false)) temp_counter ++ ; #if ((FIRMWARE_TARGET == REPETIER) || (FIRMWARE_TARGET == REPETIER4DV)) if (!current_line.startsWith( "ok ")) #endif @@ -3853,11 +3854,14 @@ void handle_web_command(){ tmp = current_buffer.substring(current_buffer.indexOf("\n")+1,current_buffer.length()); current_buffer = tmp; } + delay (0); } else delay(1); + //it is sending too many temp status should be heating so let's exit the loop + if (temp_counter > 5)count = MAX_TRY; count++; } - //to be sure connection close - if (buffer2send.length() > 0) { + //to be sure connection close + if (buffer2send.length() > 0) { web_interface->WebServer.sendContent(buffer2send); datasent = true; }