add autostart script support

This commit is contained in:
Luc 2019-10-03 20:07:36 +08:00
parent 027ab132ae
commit 5a7e555e87
8 changed files with 69 additions and 6 deletions

View File

@ -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 /////////////////////////////////////////////////////////////////////////
/************************************
*

View File

@ -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]<filname>
case 700:

View File

@ -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)

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;