apply PR comments

This commit is contained in:
Raomin 2020-05-25 01:41:45 +02:00
parent 681b9f67cf
commit 6510a72789
2 changed files with 8 additions and 16 deletions

View File

@ -27,8 +27,8 @@ interface SystemStatusFormState {
type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps<SystemStatus>;
function asNum(num: number){
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
function formatNumber(num: number){
return new Intl.NumberFormat().format(num);
}
@ -73,7 +73,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<MemoryIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Heap (Free / Max Alloc)" secondary={asNum(data.free_heap) + ' / ' + asNum(data.max_alloc_heap) + ' bytes (~' + this.approxHeapFragmentation() + '% fragmentation)'} />
<ListItemText primary="Heap (Free / Max Alloc)" secondary={formatNumber(data.free_heap) + ' / ' + formatNumber(data.max_alloc_heap) + ' bytes (~' + this.approxHeapFragmentation() + '% fragmentation)'} />
</ListItem>
<Divider variant="inset" component="li" />
<ListItem >
@ -82,7 +82,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<DataUsageIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Sketch Size (used/max)" secondary={asNum(data.sketch_size) + ' / ' + asNum(data.free_sketch_space) + ' bytes'} />
<ListItemText primary="Sketch (Size / Free)" secondary={formatNumber(data.sketch_size) + ' / ' + formatNumber(data.free_sketch_space) + ' bytes'} />
</ListItem>
<Divider variant="inset" component="li" />
<ListItem >
@ -91,7 +91,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<SdStorageIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Flash Chip (Size / Speed)" secondary={asNum(data.flash_chip_size) + ' bytes / ' + (data.flash_chip_speed / 1000000).toFixed(0) + ' MHz'} />
<ListItemText primary="Flash Chip (Size / Speed)" secondary={formatNumber(data.flash_chip_size) + ' bytes / ' + (data.flash_chip_speed / 1000000).toFixed(0) + ' MHz'} />
</ListItem>
<ListItem >
<ListItemAvatar>
@ -99,7 +99,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<StorageIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary="SPIFFS (Used / Total | Free)" secondary={asNum(data.spiffs_used) + ' / ' + asNum(data.spiffs_size) + ' bytes | '+ asNum(data.spiffs_size-data.spiffs_used) + ' bytes free'} />
<ListItemText primary="SPIFFS (Used / Total | Free)" secondary={formatNumber(data.spiffs_used) + ' / ' + formatNumber(data.spiffs_size) + ' bytes | '+ formatNumber(data.spiffs_size-data.spiffs_used) + ' bytes free'} />
</ListItem>
<Divider variant="inset" component="li" />
</Fragment>

View File

@ -1,6 +1,5 @@
#include <SystemStatus.h>
#ifdef ESP32
#include <esp_spiffs.h>
#include <SPIFFS.h>
#elif defined(ESP8266)
#include <FS.h>
@ -30,15 +29,8 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
root["sdk_version"] = ESP.getSdkVersion();
root["flash_chip_size"] = ESP.getFlashChipSize();
root["flash_chip_speed"] = ESP.getFlashChipSpeed();
#ifdef ESP32
if (esp_spiffs_mounted(NULL)) {
root["spiffs_used"] = SPIFFS.usedBytes();
root["spiffs_size"] = SPIFFS.totalBytes();
}
#elif !defined(PROGMEM_WWW) //couldn't find an esp8266 alternative to esp_spiffs_mounted()
root["spiffs_used"] = SPIFFS.usedBytes();
root["spiffs_size"] = SPIFFS.totalBytes();
#endif
root["spiffs_used"] = SPIFFS.usedBytes();
root["spiffs_size"] = SPIFFS.totalBytes();
response->setLength();
request->send(response);
}