From 986b4de93133a88338ed0a1249bd6d98308ca128 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Tue, 6 Oct 2020 08:28:34 -1000 Subject: [PATCH] $sd/show and handle settings in SD files --- Grbl_Esp32/src/Protocol.cpp | 2 +- Grbl_Esp32/src/SDCard.cpp | 1 + Grbl_Esp32/src/SDCard.h | 1 + Grbl_Esp32/src/WebUI/WebSettings.cpp | 34 ++++++++++++++++++++++++---- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Grbl_Esp32/src/Protocol.cpp b/Grbl_Esp32/src/Protocol.cpp index d2d3d0cb..abf37c12 100644 --- a/Grbl_Esp32/src/Protocol.cpp +++ b/Grbl_Esp32/src/Protocol.cpp @@ -142,7 +142,7 @@ void protocol_main_loop() { char fileLine[255]; if (readFileLine(fileLine, 255)) { SD_ready_next = false; - report_status_message(gc_execute_line(fileLine, SD_client), SD_client); + report_status_message(execute_line(fileLine, SD_client, SD_auth_level), SD_client); } else { char temp[50]; sd_get_current_filename(temp); diff --git a/Grbl_Esp32/src/SDCard.cpp b/Grbl_Esp32/src/SDCard.cpp index 4178cc91..f675c870 100644 --- a/Grbl_Esp32/src/SDCard.cpp +++ b/Grbl_Esp32/src/SDCard.cpp @@ -23,6 +23,7 @@ File myFile; bool SD_ready_next = false; // Grbl has processed a line and is waiting for another uint8_t SD_client = CLIENT_SERIAL; +WebUI::AuthenticationLevel SD_auth_level = WebUI::AuthenticationLevel::LEVEL_GUEST; uint32_t sd_current_line_number; // stores the most recent line number read from the SD static char comment[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated. diff --git a/Grbl_Esp32/src/SDCard.h b/Grbl_Esp32/src/SDCard.h index 4f19f8aa..a64a4e7d 100644 --- a/Grbl_Esp32/src/SDCard.h +++ b/Grbl_Esp32/src/SDCard.h @@ -31,6 +31,7 @@ const int SDCARD_BUSY_PARSING = 8; extern bool SD_ready_next; // Grbl has processed a line and is waiting for another extern uint8_t SD_client; +extern WebUI::AuthenticationLevel SD_auth_level; //bool sd_mount(); uint8_t get_sd_state(bool refresh); diff --git a/Grbl_Esp32/src/WebUI/WebSettings.cpp b/Grbl_Esp32/src/WebUI/WebSettings.cpp index d795660a..01a27fca 100644 --- a/Grbl_Esp32/src/WebUI/WebSettings.cpp +++ b/Grbl_Esp32/src/WebUI/WebSettings.cpp @@ -642,7 +642,7 @@ namespace WebUI { } #ifdef ENABLE_SD_CARD - static Error runSDFile(char* parameter, AuthenticationLevel auth_level) { // ESP220 + static Error openSDFile(char* parameter) { parameter = trim(parameter); if (*parameter == '\0') { webPrintln("Missing file name!"); @@ -665,7 +665,29 @@ namespace WebUI { if (!openFile(SD, parameter)) { report_status_message(Error::SdFailedRead, (espresponse) ? espresponse->client() : CLIENT_ALL); webPrintln(""); - return Error::Ok; + return Error::SdFailedOpenFile; + } + return Error::Ok; + } + static Error showSDFile(char* parameter, AuthenticationLevel auth_level) { // ESP221 + Error err; + if ((err = openSDFile(parameter)) != Error::Ok) { + return err; + } + SD_client = (espresponse) ? espresponse->client() : CLIENT_ALL; + char fileLine[255]; + while (readFileLine(fileLine, 255)) { + webPrintln(fileLine); + } + webPrintln(""); + closeFile(); + return Error::Ok; + } + + static Error runSDFile(char* parameter, AuthenticationLevel auth_level) { // ESP220 + Error err; + if ((err = openSDFile(parameter)) != Error::Ok) { + return err; } char fileLine[255]; if (!readFileLine(fileLine, 255)) { @@ -675,9 +697,10 @@ namespace WebUI { return Error::Ok; } SD_client = (espresponse) ? espresponse->client() : CLIENT_ALL; - report_status_message(gc_execute_line(fileLine, (espresponse) ? espresponse->client() : CLIENT_ALL), - (espresponse) ? espresponse->client() : CLIENT_ALL); // execute the first line - report_realtime_status((espresponse) ? espresponse->client() : CLIENT_ALL); + SD_auth_level = auth_level; + // execute the first line now; Protocol.cpp handles later ones when SD_ready_next + report_status_message(execute_line(fileLine, SD_client, SD_auth_level), SD_client); + report_realtime_status(SD_client); webPrintln(""); return Error::Ok; } @@ -985,6 +1008,7 @@ namespace WebUI { new WebCommand(NULL, WEBCMD, WU, "ESP400", "WebUI/List", listSettings); #endif #ifdef ENABLE_SD_CARD + new WebCommand("path", WEBCMD, WU, "ESP221", "SD/Show", showSDFile); new WebCommand("path", WEBCMD, WU, "ESP220", "SD/Run", runSDFile); new WebCommand("file_or_directory_path", WEBCMD, WU, "ESP215", "SD/Delete", deleteSDObject); new WebCommand(NULL, WEBCMD, WU, "ESP210", "SD/List", listSDFiles);