From e86607bff3624af823a2c68093b874d289a5810b Mon Sep 17 00:00:00 2001 From: rjwats Date: Sun, 21 Jun 2020 23:02:07 +0100 Subject: [PATCH] PSRAM Status (#159) Show PSRAM on status screen Use correct calculation for heap fragmentation Fix display of application error component --- interface/src/components/ApplicationError.tsx | 10 +++++--- interface/src/system/SystemStatusForm.tsx | 25 +++++++++++++------ interface/src/system/types.ts | 22 ++++++++++++++-- lib/framework/SystemStatus.cpp | 3 +++ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/interface/src/components/ApplicationError.tsx b/interface/src/components/ApplicationError.tsx index defca4f..7fbe0fc 100644 --- a/interface/src/components/ApplicationError.tsx +++ b/interface/src/components/ApplicationError.tsx @@ -33,11 +33,13 @@ const ApplicationError: FC = ({ error }) => {
- + - -  Application error - + + + Application error + + Failed to configure the application, please refresh to try again. diff --git a/interface/src/system/SystemStatusForm.tsx b/interface/src/system/SystemStatusForm.tsx index 3631863..751946e 100644 --- a/interface/src/system/SystemStatusForm.tsx +++ b/interface/src/system/SystemStatusForm.tsx @@ -9,6 +9,7 @@ import ShowChartIcon from '@material-ui/icons/ShowChart'; import SdStorageIcon from '@material-ui/icons/SdStorage'; import FolderIcon from '@material-ui/icons/Folder'; import DataUsageIcon from '@material-ui/icons/DataUsage'; +import AppsIcon from '@material-ui/icons/Apps'; import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew'; import RefreshIcon from '@material-ui/icons/Refresh'; import SettingsBackupRestoreIcon from '@material-ui/icons/SettingsBackupRestore'; @@ -17,7 +18,7 @@ import { redirectingAuthorizedFetch, AuthenticatedContextProps, withAuthenticate import { RestFormProps, FormButton, ErrorButton } from '../components'; import { FACTORY_RESET_ENDPOINT, RESTART_ENDPOINT } from '../api'; -import { SystemStatus } from './types'; +import { SystemStatus, EspPlatform } from './types'; interface SystemStatusFormState { confirmRestart: boolean; @@ -31,7 +32,6 @@ function formatNumber(num: number) { return new Intl.NumberFormat().format(num); } - class SystemStatusForm extends Component { state: SystemStatusFormState = { @@ -40,11 +40,6 @@ class SystemStatusForm extends Component { - const { data: { max_alloc_heap, free_heap } } = this.props; - return 100 - Math.round((max_alloc_heap / free_heap) * 100); - } - createListItems() { const { data } = this.props return ( @@ -73,8 +68,22 @@ class SystemStatusForm extends Component - + + { + (data.esp_platform === EspPlatform.ESP32 && data.psram_size > 0) && ( + + + + + + + + + + + ) + } diff --git a/interface/src/system/types.ts b/interface/src/system/types.ts index bbd9362..67b15e2 100644 --- a/interface/src/system/types.ts +++ b/interface/src/system/types.ts @@ -1,5 +1,10 @@ -export interface SystemStatus { - esp_platform: string; +export enum EspPlatform { + ESP8266 = "esp8266", + ESP32 = "esp32" +} + +interface ESPSystemStatus { + esp_platform: EspPlatform; max_alloc_heap: number; cpu_freq_mhz: number; free_heap: number; @@ -12,6 +17,19 @@ export interface SystemStatus { fs_total: number; } +export interface ESP32SystemStatus extends ESPSystemStatus { + esp_platform: EspPlatform.ESP32; + psram_size: number; + free_psram: number; +} + +export interface ESP8266SystemStatus extends ESPSystemStatus { + esp_platform: EspPlatform.ESP8266; + heap_fragmentation: number; +} + +export type SystemStatus = ESP8266SystemStatus | ESP32SystemStatus; + export interface OTASettings { enabled: boolean; port: number; diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index 28d987a..f879051 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -13,9 +13,12 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) { #ifdef ESP32 root["esp_platform"] = "esp32"; root["max_alloc_heap"] = ESP.getMaxAllocHeap(); + root["psram_size"] = ESP.getPsramSize(); + root["free_psram"] = ESP.getFreePsram(); #elif defined(ESP8266) root["esp_platform"] = "esp8266"; root["max_alloc_heap"] = ESP.getMaxFreeBlockSize(); + root["heap_fragmentation"] = ESP.getHeapFragmentation(); #endif root["cpu_freq_mhz"] = ESP.getCpuFreqMHz(); root["free_heap"] = ESP.getFreeHeap();