Better Serial Management

Thanks @me-no-dev big guru
This commit is contained in:
Luc 2018-07-05 12:32:59 +02:00
parent 222a95ecfc
commit 7994b0fa44
4 changed files with 17 additions and 2 deletions

View File

@ -57,6 +57,7 @@
//embedded response file if no files on SPIFFS //embedded response file if no files on SPIFFS
#include "nofile.h" #include "nofile.h"
bool can_process_serial = true;
extern bool deleteRecursive(String path); extern bool deleteRecursive(String path);
extern void CloseSerialUpload (bool iserror, String & filename); extern void CloseSerialUpload (bool iserror, String & filename);
@ -707,6 +708,8 @@ void handle_web_command (AsyncWebServerRequest *request)
LOG ("Start PurgeSerial\r\n") LOG ("Start PurgeSerial\r\n")
ESPCOM::processFromSerial (true); ESPCOM::processFromSerial (true);
LOG ("End PurgeSerial\r\n") LOG ("End PurgeSerial\r\n")
can_process_serial = false;
request->onDisconnect([request](){can_process_serial = true;});
//send command //send command
LOG ("Send Command\r\n") LOG ("Send Command\r\n")
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE); ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);

View File

@ -34,6 +34,7 @@ extern void handle_serial_SDFileList (AsyncWebServerRequest *request);
extern void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final); extern void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
extern void handle_Websocket_Event(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len); extern void handle_Websocket_Event(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);
extern void handle_onevent_connect(AsyncEventSourceClient *client); extern void handle_onevent_connect(AsyncEventSourceClient *client);
extern bool can_process_serial;
#ifdef SSDP_FEATURE #ifdef SSDP_FEATURE
extern void handle_SSDP (AsyncWebServerRequest *request); extern void handle_SSDP (AsyncWebServerRequest *request);

View File

@ -19,7 +19,7 @@
*/ */
//version and sources location //version and sources location
#define FW_VERSION "2.0.0.c14" #define FW_VERSION "2.0.0.c15"
#define REPOSITORY "https://github.com/luc-github/ESP3D" #define REPOSITORY "https://github.com/luc-github/ESP3D"
//Customize ESP3D //////////////////////////////////////////////////////////////////////// //Customize ESP3D ////////////////////////////////////////////////////////////////////////

View File

@ -44,6 +44,9 @@ bool ESPCOM::block_2_printer = false;
void ESPCOM::bridge(bool async) void ESPCOM::bridge(bool async)
{ {
#if defined (ASYNCWEBSERVER)
if(can_process_serial) {
#endif
//be sure wifi is on to proceed wifi function //be sure wifi is on to proceed wifi function
if ((WiFi.getMode() != WIFI_OFF) || wifi_config.WiFi_on) { if ((WiFi.getMode() != WIFI_OFF) || wifi_config.WiFi_on) {
//read tcp port input //read tcp port input
@ -53,7 +56,11 @@ void ESPCOM::bridge(bool async)
} }
//read serial input //read serial input
ESPCOM::processFromSerial(); ESPCOM::processFromSerial();
#if defined (ASYNCWEBSERVER)
}
#endif
} }
long ESPCOM::readBytes (tpipe output, uint8_t * sbuf, size_t len) long ESPCOM::readBytes (tpipe output, uint8_t * sbuf, size_t len)
{ {
switch (output) { switch (output) {
@ -339,7 +346,10 @@ bool ESPCOM::processFromSerial (bool async)
//check UART for data //check UART for data
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) { if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE); size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
uint8_t sbuf[len+1]; uint8_t * sbuf = (uint8_t *)malloc(len+1);
if(!sbuf){
return false;
}
sbuf[len] = '\0'; sbuf[len] = '\0';
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len); ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
#ifdef TCP_IP_DATA_FEATURE #ifdef TCP_IP_DATA_FEATURE
@ -366,6 +376,7 @@ bool ESPCOM::processFromSerial (bool async)
#endif #endif
//process data if any //process data if any
COMMAND::read_buffer_serial (sbuf, len); COMMAND::read_buffer_serial (sbuf, len);
free(sbuf);
return true; return true;
} else { } else {
return false; return false;