diff --git a/Grbl_Esp32/commands.cpp b/Grbl_Esp32/commands.cpp index 1c7dff63..e1e69964 100644 --- a/Grbl_Esp32/commands.cpp +++ b/Grbl_Esp32/commands.cpp @@ -875,12 +875,64 @@ 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"); } 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/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index de56ae2f..ab1f8fed 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_MISO -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..5666c284 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_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 } void IRAM_ATTR isr_control_inputs() 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) { 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=