Skip to content

Commit e86607b

Browse files
authored
PSRAM Status (#159)
Show PSRAM on status screen Use correct calculation for heap fragmentation Fix display of application error component
1 parent f045e4d commit e86607b

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

interface/src/components/ApplicationError.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ const ApplicationError: FC<ApplicationErrorProps> = ({ error }) => {
3333
<div className={classes.siteErrorPage}>
3434
<CssBaseline />
3535
<Paper className={classes.siteErrorPagePanel} elevation={10}>
36-
<Box display="flex" flexDirection="row" justifyContent="center">
36+
<Box display="flex" flexDirection="row" justifyContent="center" alignItems="center" mb={2}>
3737
<WarningIcon fontSize="large" color="error" />
38-
<Typography variant="h4" gutterBottom>
39-
&nbsp;Application error
40-
</Typography>
38+
<Box ml={2}>
39+
<Typography variant="h4">
40+
Application error
41+
</Typography>
42+
</Box>
4143
</Box>
4244
<Typography variant="subtitle1" gutterBottom>
4345
Failed to configure the application, please refresh to try again.

interface/src/system/SystemStatusForm.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ShowChartIcon from '@material-ui/icons/ShowChart';
99
import SdStorageIcon from '@material-ui/icons/SdStorage';
1010
import FolderIcon from '@material-ui/icons/Folder';
1111
import DataUsageIcon from '@material-ui/icons/DataUsage';
12+
import AppsIcon from '@material-ui/icons/Apps';
1213
import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew';
1314
import RefreshIcon from '@material-ui/icons/Refresh';
1415
import SettingsBackupRestoreIcon from '@material-ui/icons/SettingsBackupRestore';
@@ -17,7 +18,7 @@ import { redirectingAuthorizedFetch, AuthenticatedContextProps, withAuthenticate
1718
import { RestFormProps, FormButton, ErrorButton } from '../components';
1819
import { FACTORY_RESET_ENDPOINT, RESTART_ENDPOINT } from '../api';
1920

20-
import { SystemStatus } from './types';
21+
import { SystemStatus, EspPlatform } from './types';
2122

2223
interface SystemStatusFormState {
2324
confirmRestart: boolean;
@@ -31,7 +32,6 @@ function formatNumber(num: number) {
3132
return new Intl.NumberFormat().format(num);
3233
}
3334

34-
3535
class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusFormState> {
3636

3737
state: SystemStatusFormState = {
@@ -40,11 +40,6 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
4040
processing: false
4141
}
4242

43-
approxHeapFragmentation = (): number => {
44-
const { data: { max_alloc_heap, free_heap } } = this.props;
45-
return 100 - Math.round((max_alloc_heap / free_heap) * 100);
46-
}
47-
4843
createListItems() {
4944
const { data } = this.props
5045
return (
@@ -73,8 +68,22 @@ class SystemStatusForm extends Component<SystemStatusFormProps, SystemStatusForm
7368
<MemoryIcon />
7469
</Avatar>
7570
</ListItemAvatar>
76-
<ListItemText primary="Heap (Free / Max Alloc)" secondary={formatNumber(data.free_heap) + ' / ' + formatNumber(data.max_alloc_heap) + ' bytes (~' + this.approxHeapFragmentation() + '%\xa0fragmentation)'} />
71+
<ListItemText primary="Heap (Free / Max Alloc)" secondary={formatNumber(data.free_heap) + ' / ' + formatNumber(data.max_alloc_heap) + ' bytes ' + (data.esp_platform === EspPlatform.ESP8266 ? '(' + data.heap_fragmentation + '% fragmentation)' : '')} />
7772
</ListItem>
73+
{
74+
(data.esp_platform === EspPlatform.ESP32 && data.psram_size > 0) && (
75+
<Fragment>
76+
<Divider variant="inset" component="li" />
77+
<ListItem >
78+
<ListItemAvatar>
79+
<Avatar>
80+
<AppsIcon />
81+
</Avatar>
82+
</ListItemAvatar>
83+
<ListItemText primary="PSRAM (Size / Free)" secondary={formatNumber(data.psram_size) + ' / ' + formatNumber(data.free_psram) + ' bytes'} />
84+
</ListItem>
85+
</Fragment>)
86+
}
7887
<Divider variant="inset" component="li" />
7988
<ListItem >
8089
<ListItemAvatar>

interface/src/system/types.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
export interface SystemStatus {
2-
esp_platform: string;
1+
export enum EspPlatform {
2+
ESP8266 = "esp8266",
3+
ESP32 = "esp32"
4+
}
5+
6+
interface ESPSystemStatus {
7+
esp_platform: EspPlatform;
38
max_alloc_heap: number;
49
cpu_freq_mhz: number;
510
free_heap: number;
@@ -12,6 +17,19 @@ export interface SystemStatus {
1217
fs_total: number;
1318
}
1419

20+
export interface ESP32SystemStatus extends ESPSystemStatus {
21+
esp_platform: EspPlatform.ESP32;
22+
psram_size: number;
23+
free_psram: number;
24+
}
25+
26+
export interface ESP8266SystemStatus extends ESPSystemStatus {
27+
esp_platform: EspPlatform.ESP8266;
28+
heap_fragmentation: number;
29+
}
30+
31+
export type SystemStatus = ESP8266SystemStatus | ESP32SystemStatus;
32+
1533
export interface OTASettings {
1634
enabled: boolean;
1735
port: number;

lib/framework/SystemStatus.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
1313
#ifdef ESP32
1414
root["esp_platform"] = "esp32";
1515
root["max_alloc_heap"] = ESP.getMaxAllocHeap();
16+
root["psram_size"] = ESP.getPsramSize();
17+
root["free_psram"] = ESP.getFreePsram();
1618
#elif defined(ESP8266)
1719
root["esp_platform"] = "esp8266";
1820
root["max_alloc_heap"] = ESP.getMaxFreeBlockSize();
21+
root["heap_fragmentation"] = ESP.getHeapFragmentation();
1922
#endif
2023
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
2124
root["free_heap"] = ESP.getFreeHeap();

0 commit comments

Comments
 (0)