From 55165a7908a1a7f18c7630adad96962397644c23 Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 16:25:17 +0200 Subject: [PATCH 1/7] Add SPI pin customization support --- Grbl_Esp32/cpu_map.h | 8 ++++++++ Grbl_Esp32/grbl.h | 2 +- Grbl_Esp32/grbl_sd.cpp | 2 +- Grbl_Esp32/system.cpp | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index de56ae2f..001750f1 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -36,6 +36,14 @@ */ +//Set your pine definition +//let -1 to use default board pin +#define GRBL_SPI_SS -1 +#define GRBL_SPI_MOSI -1 +#define GRBL_SPI_MIS0 -1 +#define GRBL_SPI_SCK -1 +//Set you frequency +#define GRBL_SPI_FREQ 4000000 #ifdef CPU_MAP_ESP32 // This is the CPU Map for the ESP32 CNC Controller R2 diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h index b78a1e7e..586286b2 100644 --- a/Grbl_Esp32/grbl.h +++ b/Grbl_Esp32/grbl.h @@ -20,7 +20,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20190708" +#define GRBL_VERSION_BUILD "20190829" //#include #include diff --git a/Grbl_Esp32/grbl_sd.cpp b/Grbl_Esp32/grbl_sd.cpp index 550bb246..a843dc1b 100644 --- a/Grbl_Esp32/grbl_sd.cpp +++ b/Grbl_Esp32/grbl_sd.cpp @@ -200,7 +200,7 @@ uint8_t get_sd_state(bool refresh) sd_state = SDCARD_NOT_PRESENT; //using default value for speed ? should be parameter //refresh content if card was removed - if (SD.begin()) { + if (SD.begin((GRBL_SPI_SS == -1)?SS:GRBL_SPI_SS, SPI, GRBL_SPI_FREQ)) { if ( SD.cardSize() > 0 )sd_state = SDCARD_IDLE; } return sd_state; diff --git a/Grbl_Esp32/system.cpp b/Grbl_Esp32/system.cpp index f842f3f6..a2ce3245 100644 --- a/Grbl_Esp32/system.cpp +++ b/Grbl_Esp32/system.cpp @@ -44,6 +44,10 @@ void system_ini() // Renamed from system_init() due to conflict with esp32 files #endif #endif + //customize pin definition if needed +#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MIS0 != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) + SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MIS0, GRBL_SPI_MOSI, GRBL_SPI_SS); +#endif } void IRAM_ATTR isr_control_inputs() From 09f9fd2a4932400d387dd70f524569846a2e6d5e Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 17:29:17 +0200 Subject: [PATCH 2/7] Update cpu_map.h --- Grbl_Esp32/cpu_map.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index 001750f1..ab1f8fed 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -40,7 +40,7 @@ //let -1 to use default board pin #define GRBL_SPI_SS -1 #define GRBL_SPI_MOSI -1 -#define GRBL_SPI_MIS0 -1 +#define GRBL_SPI_MISO -1 #define GRBL_SPI_SCK -1 //Set you frequency #define GRBL_SPI_FREQ 4000000 From 8ae9261c1e16d2b19b6897dc23ca0d328437fd1d Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 18:11:38 +0200 Subject: [PATCH 3/7] fix typo --- Grbl_Esp32/commands.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ Grbl_Esp32/system.cpp | 4 ++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Grbl_Esp32/commands.cpp b/Grbl_Esp32/commands.cpp index 1c7dff63..774f5f10 100644 --- a/Grbl_Esp32/commands.cpp +++ b/Grbl_Esp32/commands.cpp @@ -881,6 +881,49 @@ bool COMMANDS::execute_internal_command (int cmd, String cmd_params, level_authe } break; + //Delete SD Card file / directory + //[ESP215] + case 215: + { + if (!espresponse) return false; +#ifdef ENABLE_AUTHENTICATION + if (auth_type == LEVEL_GUEST) { + espresponse->println ("Error: Wrong authentication!"); + return false; + + } +#endif + parameter = get_param (cmd_params, "", true); + if (parameter.length() != 0) { + int8_t state = get_sd_state(true); + if (state == SDCARD_IDLE) { + File file2del = SD.open(cmd_params.c_str()); + if (file2del) { + if (file2del.isDirectory()) { + if (!SD.rmdir((char *)cmd_params.c_str())) { + espresponse->println ("Error: Cannot delete directory! Is directory empty?"); + } else { + espresponse->println ("Directory deleted."); + } + } else { + if (!SD.remove((char *)cmd_params.c_str())) { + espresponse->println ("Error: Cannot delete file!"); + } else { + espresponse->println ("File deleted."); + } + } + } else { + espresponse->println ("Error: Cannot stat file!"); + } + file2del.close(); + } else { + espresponse->println ((state == SDCARD_NOT_PRESENT) ? "No SD card" : "Busy"); + } + } else { + espresponse->println ("Error: Missing file name!"); + } + } + break; //print SD file //[ESP220] case 220: diff --git a/Grbl_Esp32/system.cpp b/Grbl_Esp32/system.cpp index a2ce3245..5666c284 100644 --- a/Grbl_Esp32/system.cpp +++ b/Grbl_Esp32/system.cpp @@ -45,8 +45,8 @@ void system_ini() // Renamed from system_init() due to conflict with esp32 files #endif //customize pin definition if needed -#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MIS0 != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) - SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MIS0, GRBL_SPI_MOSI, GRBL_SPI_SS); +#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MISO != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) + SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MISO, GRBL_SPI_MOSI, GRBL_SPI_SS); #endif } From a9127acdedf47fbd9e4b217ce02f464aceb6a865 Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 18:23:28 +0200 Subject: [PATCH 4/7] Revert "fix typo" This reverts commit 8ae9261c1e16d2b19b6897dc23ca0d328437fd1d. --- Grbl_Esp32/commands.cpp | 43 ----------------------------------------- Grbl_Esp32/system.cpp | 4 ++-- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/Grbl_Esp32/commands.cpp b/Grbl_Esp32/commands.cpp index 774f5f10..1c7dff63 100644 --- a/Grbl_Esp32/commands.cpp +++ b/Grbl_Esp32/commands.cpp @@ -881,49 +881,6 @@ bool COMMANDS::execute_internal_command (int cmd, String cmd_params, level_authe } break; - //Delete SD Card file / directory - //[ESP215] - case 215: - { - if (!espresponse) return false; -#ifdef ENABLE_AUTHENTICATION - if (auth_type == LEVEL_GUEST) { - espresponse->println ("Error: Wrong authentication!"); - return false; - - } -#endif - parameter = get_param (cmd_params, "", true); - if (parameter.length() != 0) { - int8_t state = get_sd_state(true); - if (state == SDCARD_IDLE) { - File file2del = SD.open(cmd_params.c_str()); - if (file2del) { - if (file2del.isDirectory()) { - if (!SD.rmdir((char *)cmd_params.c_str())) { - espresponse->println ("Error: Cannot delete directory! Is directory empty?"); - } else { - espresponse->println ("Directory deleted."); - } - } else { - if (!SD.remove((char *)cmd_params.c_str())) { - espresponse->println ("Error: Cannot delete file!"); - } else { - espresponse->println ("File deleted."); - } - } - } else { - espresponse->println ("Error: Cannot stat file!"); - } - file2del.close(); - } else { - espresponse->println ((state == SDCARD_NOT_PRESENT) ? "No SD card" : "Busy"); - } - } else { - espresponse->println ("Error: Missing file name!"); - } - } - break; //print SD file //[ESP220] case 220: diff --git a/Grbl_Esp32/system.cpp b/Grbl_Esp32/system.cpp index 5666c284..a2ce3245 100644 --- a/Grbl_Esp32/system.cpp +++ b/Grbl_Esp32/system.cpp @@ -45,8 +45,8 @@ void system_ini() // Renamed from system_init() due to conflict with esp32 files #endif //customize pin definition if needed -#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MISO != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) - SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MISO, GRBL_SPI_MOSI, GRBL_SPI_SS); +#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MIS0 != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) + SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MIS0, GRBL_SPI_MOSI, GRBL_SPI_SS); #endif } From 30242b414a46657b53855ab2509408fa243dd7ab Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 18:23:53 +0200 Subject: [PATCH 5/7] fix typo --- Grbl_Esp32/system.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Grbl_Esp32/system.cpp b/Grbl_Esp32/system.cpp index a2ce3245..5666c284 100644 --- a/Grbl_Esp32/system.cpp +++ b/Grbl_Esp32/system.cpp @@ -45,8 +45,8 @@ void system_ini() // Renamed from system_init() due to conflict with esp32 files #endif //customize pin definition if needed -#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MIS0 != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) - SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MIS0, GRBL_SPI_MOSI, GRBL_SPI_SS); +#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MISO != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) + SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MISO, GRBL_SPI_MOSI, GRBL_SPI_SS); #endif } From b8fcecfae312b3e0589af1e082d893d419a14510 Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 18:33:02 +0200 Subject: [PATCH 6/7] add ESP command to delete SD card file / directory --- Grbl_Esp32/commands.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ doc/Commands.txt | 3 +++ 2 files changed, 50 insertions(+) diff --git a/Grbl_Esp32/commands.cpp b/Grbl_Esp32/commands.cpp index 1c7dff63..f1298477 100644 --- a/Grbl_Esp32/commands.cpp +++ b/Grbl_Esp32/commands.cpp @@ -881,6 +881,53 @@ bool COMMANDS::execute_internal_command (int cmd, String cmd_params, level_authe } break; + //Delete SD Card file / directory + //[ESP215]pwd= + case 215: + { + if (!espresponse) return false; +#ifdef ENABLE_AUTHENTICATION + if (auth_type == LEVEL_GUEST) { + espresponse->println ("Error: Wrong authentication!"); + return false; + + } +#endif + parameter = get_param (cmd_params, "", true); + if (parameter.length() != 0) { + int8_t state = get_sd_state(true); + parameter.trim(); + if (parameter[0] != '/'){ + parameter = "/" + parameter; + } + if (state == SDCARD_IDLE) { + File file2del = SD.open(parameter.c_str()); + if (file2del) { + if (file2del.isDirectory()) { + if (!SD.rmdir((char *)parameter.c_str())) { + espresponse->println ("Error: Cannot delete directory! Is directory empty?"); + } else { + espresponse->println ("Directory deleted."); + } + } else { + if (!SD.remove((char *)parameter.c_str())) { + espresponse->println ("Error: Cannot delete file!"); + } else { + espresponse->println ("File deleted."); + } + } + } else { + espresponse->println ("Error: Cannot stat file!"); + } + file2del.close(); + } else { + espresponse->println ((state == SDCARD_NOT_PRESENT) ? "No SD card" : "Busy"); + } + } else { + espresponse->println ("Error: Missing file name!"); + } + } + break; //print SD file //[ESP220] case 220: diff --git a/doc/Commands.txt b/doc/Commands.txt index c9705b30..2071a42b 100644 --- a/doc/Commands.txt +++ b/doc/Commands.txt @@ -85,6 +85,9 @@ Reply: 81 * Get SD Card Content [ESP210] pwd= +* Delete SD Card file / directory +[ESP215]pwd= + * Print SD file [ESP220] pwd= From 7f3fe30c3989f423edcfd7fd19956f2dc52ed434 Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 21:02:43 +0200 Subject: [PATCH 7/7] Display sd space in [ESP210] Fix occupation always to 1% --- Grbl_Esp32/commands.cpp | 5 +++++ Grbl_Esp32/web_server.cpp | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Grbl_Esp32/commands.cpp b/Grbl_Esp32/commands.cpp index f1298477..e1e69964 100644 --- a/Grbl_Esp32/commands.cpp +++ b/Grbl_Esp32/commands.cpp @@ -875,7 +875,12 @@ bool COMMANDS::execute_internal_command (int cmd, String cmd_params, level_authe int8_t state = get_sd_state(true); if (state == SDCARD_IDLE) { listDir(SD, "/", 10, espresponse->client()); + String ssd = "[SD Free:" + ESPResponseStream::formatBytes(SD.totalBytes() - SD.usedBytes()); + ssd +=" Used:" + ESPResponseStream::formatBytes(SD.usedBytes()); + ssd +=" Total:" + ESPResponseStream::formatBytes(SD.totalBytes()); + ssd +="]"; espresponse->println (""); + espresponse->println (ssd.c_str()); } else espresponse->println ((state == SDCARD_NOT_PRESENT) ? "No SD card" : "Busy"); } diff --git a/Grbl_Esp32/web_server.cpp b/Grbl_Esp32/web_server.cpp index 1e09d9b3..a4d4933a 100644 --- a/Grbl_Esp32/web_server.cpp +++ b/Grbl_Esp32/web_server.cpp @@ -1366,19 +1366,20 @@ void Web_Server::handle_direct_SDFileList() } jsonfile+="],\"path\":\""; jsonfile+=path + "\","; - static uint32_t volTotal = 1; - static uint32_t volFree = 0; jsonfile+="\"total\":\""; String stotalspace,susedspace; //SDCard are in GB or MB but no less totalspace = SD.totalBytes(); usedspace = SD.usedBytes(); stotalspace = ESPResponseStream::formatBytes(totalspace); - susedspace = ESPResponseStream::formatBytes(usedspace); + susedspace = ESPResponseStream::formatBytes(usedspace+1); - uint32_t occupedspace = (volFree/volTotal)*100; + uint32_t occupedspace = 1; + uint32_t usedspace2 = usedspace/(1024*1024); + uint32_t totalspace2 = totalspace/(1024*1024); + occupedspace = (usedspace2 * 100)/totalspace2; //minimum if even one byte is used is 1% - if ( (occupedspace <= 1) && (volTotal!=volFree)) { + if ( occupedspace <= 1) { occupedspace=1; } if (totalspace) {