diff --git a/esp3d/configuration.h b/esp3d/configuration.h index 1513dce0..58bb0b7b 100644 --- a/esp3d/configuration.h +++ b/esp3d/configuration.h @@ -162,6 +162,11 @@ //ESP_GCODE_HOST_FEATURE : allow to send GCODE with ack #define ESP_GCODE_HOST_FEATURE +//ESP_AUTOSTART_SCRIPT : to do some actions / send GCODE at start, need ESP_GCODE_HOST_FEATURE enabled +//can be a line od several GCODES separated by `\n` e.g. "M21\nM117 SD mounted\n" +//can be a file name, if exists, commands inside will be processed, e.g "/FS:/autostart.esp" +#define ESP_AUTOSTART_SCRIPT "M117 Mouning SD\nM21\n" + //Extra features ///////////////////////////////////////////////////////////////////////// /************************************ * diff --git a/esp3d/src/core/commands.cpp b/esp3d/src/core/commands.cpp index b4c7acc4..9347fe4b 100644 --- a/esp3d/src/core/commands.cpp +++ b/esp3d/src/core/commands.cpp @@ -506,7 +506,7 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_ response = ESP710(cmd_params, auth_type, output); break; #endif //FILESYSTEM_FEATURE -#ifdef FILESYSTEM_FEATURE +#if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE) //Open local file //[ESP700] case 700: diff --git a/esp3d/src/core/commands.h b/esp3d/src/core/commands.h index 5170cfb4..ed588332 100644 --- a/esp3d/src/core/commands.h +++ b/esp3d/src/core/commands.h @@ -112,7 +112,7 @@ public: bool ESP600(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP610(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #endif //NOTIFICATION_FEATURE -#if defined(FILESYSTEM_FEATURE) +#if defined(FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE) bool ESP700(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); #endif //FILESYSTEM_FEATURE #if defined(FILESYSTEM_FEATURE) diff --git a/esp3d/src/core/esp3d.cpp b/esp3d/src/core/esp3d.cpp index af80fd97..21907d21 100644 --- a/esp3d/src/core/esp3d.cpp +++ b/esp3d/src/core/esp3d.cpp @@ -40,7 +40,9 @@ #ifdef DISPLAY_DEVICE #include "../modules/display/display.h" #endif //DISPLAY_DEVICE - +#ifdef ESP_GCODE_HOST_FEATURE +#include "../modules/gcode_host/gcode_host.h" +#endif //ESP_GCODE_HOST_FEATURE #include "esp3doutput.h" #include "../modules/boot_delay/boot_delay.h" @@ -107,6 +109,9 @@ bool Esp3D::begin() res = false; } #endif //WIFI_FEATURE +#if defined(ESP_AUTOSTART_SCRIPT) + esp3d_gcode_host.processscript(ESP_AUTOSTART_SCRIPT); +#endif //ESP_AUTOSTART_FEATURE return res; } diff --git a/esp3d/src/core/espcmd/ESP700.cpp b/esp3d/src/core/espcmd/ESP700.cpp index 5b19ffad..618c215e 100644 --- a/esp3d/src/core/espcmd/ESP700.cpp +++ b/esp3d/src/core/espcmd/ESP700.cpp @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "../../include/esp3d_config.h" -#if defined (FILESYSTEM_FEATURE) +#if defined (FILESYSTEM_FEATURE) && defined(ESP_GCODE_HOST_FEATURE) #include "../commands.h" #include "../esp3doutput.h" #include "../settings_esp3d.h" @@ -47,4 +47,4 @@ bool Commands::ESP700(const char* cmd_params, level_authenticate_type auth_type, return response; } -#endif //FILESYSTEM_FEATURE +#endif //FILESYSTEM_FEATURE && ESP_GCODE_HOST_FEATURE diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index 01b932a0..fd6dc1d9 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a20" +#define FW_VERSION "3.0.0.a21" #define REPOSITORY "https://github.com/luc-github/ESP3D" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/gcode_host/gcode_host.cpp b/esp3d/src/modules/gcode_host/gcode_host.cpp index 97668965..5c8ae251 100644 --- a/esp3d/src/modules/gcode_host/gcode_host.cpp +++ b/esp3d/src/modules/gcode_host/gcode_host.cpp @@ -23,6 +23,7 @@ #include "gcode_host.h" #include "../../core/settings_esp3d.h" #include "../../core/commands.h" +#include "../../core/esp3doutput.h" #include "../serial/serial_service.h" #include "../filesystem/esp_filesystem.h" @@ -321,6 +322,7 @@ bool GcodeHost::processFSFile(const char * filename, level_authenticate_type aut if (!sendCommand(cmd.c_str(),false, true)) { log_esp3d("Error sending command"); //To stop instead of continue may need some trigger + res = false; } } } @@ -335,6 +337,55 @@ bool GcodeHost::processFSFile(const char * filename, level_authenticate_type aut return res; } +bool GcodeHost::processscript(const char * line) +{ + bool res = true; + String s = line; + s.trim(); + ESP3DOutput output(ESP_ALL_CLIENTS); + if (s.startsWith(ESP_FLASH_FS_HEADER)) { + res = processFile(line, LEVEL_ADMIN, &output); + } else { + res = processLine(line, LEVEL_ADMIN, &output); + } + return res; +} + +//split line of command separated by '\n' +bool GcodeHost::processLine(const char * line, level_authenticate_type auth_type, ESP3DOutput * output) +{ + bool res = true; + String s = ""; + for (uint p = 0; p < strlen(line); p++) { + if ((line[p]==10) || (line[p]==13) || (p == (strlen(line)-1))) { + if (!((line[p]==10) || (line[p]==13)) && (p == (strlen(line)-1))) { + s+=line[p]; + } + s.trim(); + if (s.length()>0) { + //ignore comments + if (s[0]!=';') { + //it is internal or not ? + if(esp3d_commands.is_esp_command((uint8_t *)s.c_str(), s.length())) { + esp3d_commands.process((uint8_t *)s.c_str(), s.length(), output, auth_type); + } else { + //no check sum no ack + if (!sendCommand(s.c_str(),false, false)) { + log_esp3d("Error sending command"); + //To stop instead of continue may need some trigger + res = false; + } + } + } + } + s = ""; + } else { + s+=line[p]; + } + } + return res; +} + bool GcodeHost::processFile(const char * filename, level_authenticate_type auth_type, ESP3DOutput * output) { String FileName = filename; diff --git a/esp3d/src/modules/gcode_host/gcode_host.h b/esp3d/src/modules/gcode_host/gcode_host.h index 84d62bd2..78523fbf 100644 --- a/esp3d/src/modules/gcode_host/gcode_host.h +++ b/esp3d/src/modules/gcode_host/gcode_host.h @@ -73,6 +73,8 @@ public: } bool processFile(const char * filename, level_authenticate_type auth_type, ESP3DOutput * output); bool processFSFile(const char * filename, level_authenticate_type auth_type, ESP3DOutput * output); + bool processLine(const char * line, level_authenticate_type auth_type, ESP3DOutput * output); + bool processscript(const char * line); private: uint32_t _commandnumber; uint32_t _needcommandnumber;