1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-30 01:30:05 +02:00

Display sd space in [ESP210]

Fix occupation always to 1%
This commit is contained in:
Luc
2019-08-29 21:02:43 +02:00
parent b8fcecfae3
commit 7f3fe30c39
2 changed files with 11 additions and 5 deletions

View File

@@ -875,7 +875,12 @@ bool COMMANDS::execute_internal_command (int cmd, String cmd_params, level_authe
int8_t state = get_sd_state(true); int8_t state = get_sd_state(true);
if (state == SDCARD_IDLE) { if (state == SDCARD_IDLE) {
listDir(SD, "/", 10, espresponse->client()); 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 ("");
espresponse->println (ssd.c_str());
} }
else espresponse->println ((state == SDCARD_NOT_PRESENT) ? "No SD card" : "Busy"); else espresponse->println ((state == SDCARD_NOT_PRESENT) ? "No SD card" : "Busy");
} }

View File

@@ -1366,19 +1366,20 @@ void Web_Server::handle_direct_SDFileList()
} }
jsonfile+="],\"path\":\""; jsonfile+="],\"path\":\"";
jsonfile+=path + "\","; jsonfile+=path + "\",";
static uint32_t volTotal = 1;
static uint32_t volFree = 0;
jsonfile+="\"total\":\""; jsonfile+="\"total\":\"";
String stotalspace,susedspace; String stotalspace,susedspace;
//SDCard are in GB or MB but no less //SDCard are in GB or MB but no less
totalspace = SD.totalBytes(); totalspace = SD.totalBytes();
usedspace = SD.usedBytes(); usedspace = SD.usedBytes();
stotalspace = ESPResponseStream::formatBytes(totalspace); 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% //minimum if even one byte is used is 1%
if ( (occupedspace <= 1) && (volTotal!=volFree)) { if ( occupedspace <= 1) {
occupedspace=1; occupedspace=1;
} }
if (totalspace) { if (totalspace) {