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>; type SystemStatusFormProps = AuthenticatedContextProps & RestFormProps<SystemStatus>;
function asNum(num: number){ function formatNumber(num: number){
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); return new Intl.NumberFormat().format(num);
} }
@ -73,7 +73,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<MemoryIcon /> <MemoryIcon />
</Avatar> </Avatar>
</ListItemAvatar> </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> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
<ListItem > <ListItem >
@ -82,7 +82,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<DataUsageIcon /> <DataUsageIcon />
</Avatar> </Avatar>
</ListItemAvatar> </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> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
<ListItem > <ListItem >
@ -91,7 +91,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<SdStorageIcon /> <SdStorageIcon />
</Avatar> </Avatar>
</ListItemAvatar> </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>
<ListItem > <ListItem >
<ListItemAvatar> <ListItemAvatar>
@ -99,7 +99,7 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
<StorageIcon /> <StorageIcon />
</Avatar> </Avatar>
</ListItemAvatar> </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> </ListItem>
<Divider variant="inset" component="li" /> <Divider variant="inset" component="li" />
</Fragment> </Fragment>

View File

@ -1,6 +1,5 @@
#include <SystemStatus.h> #include <SystemStatus.h>
#ifdef ESP32 #ifdef ESP32
#include <esp_spiffs.h>
#include <SPIFFS.h> #include <SPIFFS.h>
#elif defined(ESP8266) #elif defined(ESP8266)
#include <FS.h> #include <FS.h>
@ -30,15 +29,8 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
root["sdk_version"] = ESP.getSdkVersion(); root["sdk_version"] = ESP.getSdkVersion();
root["flash_chip_size"] = ESP.getFlashChipSize(); root["flash_chip_size"] = ESP.getFlashChipSize();
root["flash_chip_speed"] = ESP.getFlashChipSpeed(); root["flash_chip_speed"] = ESP.getFlashChipSpeed();
#ifdef ESP32
if (esp_spiffs_mounted(NULL)) {
root["spiffs_used"] = SPIFFS.usedBytes(); root["spiffs_used"] = SPIFFS.usedBytes();
root["spiffs_size"] = SPIFFS.totalBytes(); 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
response->setLength(); response->setLength();
request->send(response); request->send(response);
} }