mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-04 18:00:37 +08:00
Serial fixes
more baud rate remove unused functions
This commit is contained in:
parent
7994b0fa44
commit
004d99c991
@ -1138,7 +1138,14 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
//get size of buffer
|
||||
if (len > 0) {
|
||||
CONFIG::wdtFeed();
|
||||
uint8_t sbuf[len + 1];
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len+1);
|
||||
if(!sbuf){
|
||||
web_interface->_upload_status = UPLOAD_STATUS_CANCELLED;
|
||||
ESPCOM::println (F ("SD upload rejected"), PRINTER_PIPE);
|
||||
LOG ("SD upload rejected\r\n");
|
||||
request->client()->abort();
|
||||
return ;
|
||||
}
|
||||
//read buffer
|
||||
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
||||
//convert buffer to zero end array
|
||||
@ -1150,6 +1157,7 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
if (response.indexOf ("wait") > -1) {
|
||||
LOG ("Exit start writing\r\n");
|
||||
done = true;
|
||||
free(sbuf);
|
||||
break;
|
||||
}
|
||||
//it is first command if it is failed no need to continue
|
||||
@ -1159,8 +1167,10 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
LOG ("Error start writing\r\n");
|
||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||
request->client()->abort();
|
||||
free(sbuf);
|
||||
return;
|
||||
}
|
||||
free(sbuf);
|
||||
}
|
||||
if ( (millis() - timeout) > SERIAL_CHECK_TIMEOUT) {
|
||||
done = true;
|
||||
|
@ -615,7 +615,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
} else {
|
||||
ESPCOM::print ( (const char *) CONFIG::intTostr (ibuf), output, espresponse);
|
||||
}
|
||||
ESPCOM::print (F ("\",\"H\":\"Baud Rate\",\"O\":[{\"9600\":\"9600\"},{\"19200\":\"19200\"},{\"38400\":\"38400\"},{\"57600\":\"57600\"},{\"115200\":\"115200\"},{\"230400\":\"230400\"},{\"250000\":\"250000\"}]}"), output, espresponse);
|
||||
ESPCOM::print (F ("\",\"H\":\"Baud Rate\",\"O\":[{\"9600\":\"9600\"},{\"19200\":\"19200\"},{\"38400\":\"38400\"},{\"57600\":\"57600\"},{\"115200\":\"115200\"},{\"230400\":\"230400\"},{\"250000\":\"250000\"},{\"500000\":\"500000\"},{\"921600 \":\"921600 \"}]}"), output, espresponse);
|
||||
ESPCOM::println (F (","), output, espresponse);
|
||||
|
||||
//2-Sleep Mode
|
||||
@ -1213,7 +1213,6 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
if (pos == EP_TARGET_FW) {
|
||||
CONFIG::InitFirmwareTarget();
|
||||
}
|
||||
|
||||
#ifdef DHT_FEATURE
|
||||
if (pos == EP_DHT_TYPE) {
|
||||
CONFIG::DHT_type = bbuf;
|
||||
@ -1569,14 +1568,6 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
ESPCOM::print (cmd_params, output, espresponse);
|
||||
ESPCOM::println (CONFIG::GetFirmwareTargetShortName(), output, espresponse);
|
||||
break;
|
||||
//clear status/error/info list
|
||||
case 802:
|
||||
if (CONFIG::check_update_presence( ) ) {
|
||||
ESPCOM::println ("yes", output, espresponse);
|
||||
} else {
|
||||
ESPCOM::println ("no", output, espresponse);
|
||||
}
|
||||
break;
|
||||
case 810:
|
||||
web_interface->blockserial = false;
|
||||
break;
|
||||
|
103
src/config.cpp
103
src/config.cpp
@ -38,7 +38,6 @@ extern "C" {
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DHT_FEATURE
|
||||
#include "DHTesp.h"
|
||||
extern DHTesp dht;
|
||||
@ -153,12 +152,10 @@ bool CONFIG::is_locked(byte flag){
|
||||
|
||||
void CONFIG::InitDirectSD()
|
||||
{
|
||||
|
||||
CONFIG::is_direct_sd = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool CONFIG::InitBaudrate(long value)
|
||||
{
|
||||
long baud_rate = 0;
|
||||
@ -168,7 +165,7 @@ bool CONFIG::InitBaudrate(long value)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( ! (baud_rate == 9600 || baud_rate == 19200 || baud_rate == 38400 || baud_rate == 57600 || baud_rate == 115200 || baud_rate == 230400 || baud_rate == 250000) ) {
|
||||
if ( ! (baud_rate == 9600 || baud_rate == 19200 || baud_rate == 38400 || baud_rate == 57600 || baud_rate == 115200 || baud_rate == 230400 || baud_rate == 250000 || baud_rate == 500000 || baud_rate == 921600 ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -580,104 +577,6 @@ bool CONFIG::write_string (int pos, const __FlashStringHelper *str)
|
||||
return write_string (pos, stmp.c_str() );
|
||||
}
|
||||
|
||||
bool CONFIG::check_update_presence( )
|
||||
{
|
||||
bool result = false;
|
||||
if (CONFIG::is_direct_sd) {
|
||||
if (!CONFIG::InitBaudrate()) return false;
|
||||
CONFIG::InitFirmwareTarget();
|
||||
delay (500);
|
||||
String cmd = "M20";
|
||||
//By default M20 should be applied
|
||||
//if (CONFIG::FirmwareTarget == UNKNOWN_FW) return false;
|
||||
if (CONFIG::FirmwareTarget == SMOOTHIEWARE) {
|
||||
byte sd_dir = 0;
|
||||
if (!CONFIG::read_byte (EP_PRIMARY_SD, &sd_dir ) ) {
|
||||
sd_dir = DEFAULT_PRIMARY_SD;
|
||||
}
|
||||
if (sd_dir == SD_DIRECTORY) {
|
||||
cmd = "ls /sd";
|
||||
} else if (sd_dir == EXT_DIRECTORY) {
|
||||
cmd = "ls /ext";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String tmp;
|
||||
|
||||
int count ;
|
||||
//send command to serial as no need to transfer ESP command
|
||||
//to avoid any pollution if Uploading file to SDCard
|
||||
//block every query
|
||||
//empty the serial buffer and incoming data
|
||||
if (ESPCOM::processFromSerial() ) {
|
||||
delay (1);
|
||||
}
|
||||
//Send command
|
||||
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
||||
count = 0;
|
||||
String current_buffer;
|
||||
String current_line;
|
||||
//int pos;
|
||||
int temp_counter = 0;
|
||||
|
||||
//pickup the list
|
||||
while (count < MAX_TRY) {
|
||||
//give some time between each buffer
|
||||
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||
count = 0;
|
||||
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||
uint8_t sbuf[len + 1];
|
||||
//read buffer
|
||||
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
||||
//change buffer as string
|
||||
sbuf[len] = '\0';
|
||||
//add buffer to current one if any
|
||||
current_buffer += (char * ) sbuf;
|
||||
while (current_buffer.indexOf ("\n") != -1) {
|
||||
//remove the possible "\r"
|
||||
current_buffer.replace ("\r", "");
|
||||
//pos = current_buffer.indexOf("\n");
|
||||
//get line
|
||||
current_line = current_buffer.substring (0, current_buffer.indexOf ("\n") );
|
||||
//if line is command ack - just exit so save the time out period
|
||||
if ( (current_line == "ok") || (current_line == "wait") ) {
|
||||
count = MAX_TRY;
|
||||
break;
|
||||
}
|
||||
//check line
|
||||
//save time no need to continue
|
||||
if (current_line.indexOf ("busy:") > -1 || current_line.indexOf ("T:") > -1 || current_line.indexOf ("B:") > -1) {
|
||||
temp_counter++;
|
||||
} else {
|
||||
|
||||
}
|
||||
if (temp_counter > 5) {
|
||||
break;
|
||||
}
|
||||
//current remove line from buffer
|
||||
tmp = current_buffer.substring (current_buffer.indexOf ("\n") + 1, current_buffer.length() );
|
||||
current_buffer = tmp;
|
||||
delay (0);
|
||||
}
|
||||
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++;
|
||||
}
|
||||
if (ESPCOM::processFromSerial() ) {
|
||||
delay (1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//write a string (array of byte with a 0x00 at the end)
|
||||
bool CONFIG::write_string (int pos, const char * byte_buffer)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "2.0.0.c15"
|
||||
#define FW_VERSION "2.0.0.c17"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||
|
||||
//Customize ESP3D ////////////////////////////////////////////////////////////////////////
|
||||
@ -201,7 +201,6 @@ using fs::File;
|
||||
#define LOG(string) { FS_FILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUG_OUTPUT_SERIAL
|
||||
#define DEBUG_PIPE SERIAL_PIPE
|
||||
#define LOG(string) {Serial.print(string);}
|
||||
@ -369,10 +368,8 @@ const char DEFAULT_TIME_SERVER3 [] PROGMEM = "1.pool.ntp.org";
|
||||
#define DEFAULT_DHT_TYPE 255
|
||||
const int DEFAULT_DHT_INTERVAL = 30;
|
||||
|
||||
|
||||
#define DEFAULT_IS_DIRECT_SD 0
|
||||
|
||||
|
||||
//SD Card reader speed
|
||||
//possible values are :SPI_FULL_SPEED, SPI_DIV3_SPEED,
|
||||
//SPI_HALF_SPEED, SPI_DIV6_SPEED, SPI_QUARTER_SPEED,
|
||||
@ -502,7 +499,6 @@ public:
|
||||
static void InitPins();
|
||||
static bool InitBaudrate(long value = 0);
|
||||
static bool InitExternalPorts();
|
||||
static bool check_update_presence();
|
||||
static uint8_t GetFirmwareTarget();
|
||||
static const char* GetFirmwareTargetName();
|
||||
static const char* GetFirmwareTargetShortName();
|
||||
|
@ -346,7 +346,7 @@ bool ESPCOM::processFromSerial (bool async)
|
||||
//check UART for data
|
||||
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len+1);
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len+1);
|
||||
if(!sbuf){
|
||||
return false;
|
||||
}
|
||||
|
@ -1201,7 +1201,18 @@ void SDFile_serial_upload()
|
||||
//get size of buffer
|
||||
if (len > 0) {
|
||||
CONFIG::wait(0);
|
||||
uint8_t sbuf[len + 1];
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len+1);
|
||||
if(!sbuf){
|
||||
ESPCOM::println (F ("SD upload rejected"), PRINTER_PIPE);
|
||||
LOG("SD upload rejected\r\n");
|
||||
LOG("Need to stop");
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
//read buffer
|
||||
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
||||
//convert buffer to zero end array
|
||||
@ -1213,6 +1224,7 @@ void SDFile_serial_upload()
|
||||
if (response.indexOf ("wait") > -1) {
|
||||
LOG ("Exit start writing\r\n");
|
||||
done = true;
|
||||
free(sbuf);
|
||||
break;
|
||||
}
|
||||
//it is first command if it is failed no need to continue
|
||||
@ -1226,8 +1238,10 @@ void SDFile_serial_upload()
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
free(sbuf);
|
||||
return;
|
||||
}
|
||||
free(sbuf);
|
||||
}
|
||||
if ( (millis() - timeout) > SERIAL_CHECK_TIMEOUT) {
|
||||
done = true;
|
||||
|
@ -95,7 +95,10 @@ bool sendLine2Serial (String & line)
|
||||
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||
//get size of buffer
|
||||
if (len > 0) {
|
||||
uint8_t sbuf[len + 1];
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len+1);
|
||||
if(!sbuf){
|
||||
return false;
|
||||
}
|
||||
//read buffer
|
||||
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
||||
//convert buffer to zero end array
|
||||
@ -103,11 +106,13 @@ bool sendLine2Serial (String & line)
|
||||
//use string because easier to handle
|
||||
String response = (const char*) sbuf;
|
||||
if ( (response.indexOf ("ok") > -1) || (response.indexOf ("wait") > -1) ) {
|
||||
free(sbuf);
|
||||
return true;
|
||||
}
|
||||
if (response.indexOf ("Resend") > -1) {
|
||||
count++;
|
||||
if (count > 5) {
|
||||
free(sbuf);
|
||||
return false;
|
||||
}
|
||||
LOG ("resend\r\n")
|
||||
@ -116,6 +121,7 @@ bool sendLine2Serial (String & line)
|
||||
CONFIG::wait (5);
|
||||
timeout = millis();
|
||||
}
|
||||
free(sbuf);
|
||||
}
|
||||
//no answer so exit: no news = good news
|
||||
if ( millis() - timeout > 500) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user