This commit is contained in:
jpirnay
2026-03-17 21:12:42 +01:00
parent 06f8bbfa36
commit ce0c429dae
3 changed files with 36 additions and 8 deletions
+7
View File
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include <HalStorage.h>
#include <WiFi.h> #include <WiFi.h>
// Snapshot of device system status, shared between the web server and the // Snapshot of device system status, shared between the web server and the
@@ -13,6 +14,9 @@ struct SystemStatus {
std::string macAddress; std::string macAddress;
uint32_t freeHeapBytes; uint32_t freeHeapBytes;
uint32_t uptimeSeconds; uint32_t uptimeSeconds;
uint64_t sdTotalBytes;
uint64_t sdUsedBytes;
uint64_t sdFreeBytes;
static SystemStatus collect() { static SystemStatus collect() {
SystemStatus s; SystemStatus s;
@@ -20,6 +24,9 @@ struct SystemStatus {
s.freeHeapBytes = ESP.getFreeHeap(); s.freeHeapBytes = ESP.getFreeHeap();
s.uptimeSeconds = millis() / 1000; s.uptimeSeconds = millis() / 1000;
s.macAddress = WiFi.macAddress().c_str(); s.macAddress = WiFi.macAddress().c_str();
s.sdTotalBytes = Storage.sdTotalBytes();
s.sdUsedBytes = Storage.sdUsedBytes();
s.sdFreeBytes = Storage.sdFreeBytes();
const wifi_mode_t mode = WiFi.getMode(); const wifi_mode_t mode = WiFi.getMode();
const bool isAP = (mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA); const bool isAP = (mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA);
@@ -8,6 +8,17 @@
#include "components/UITheme.h" #include "components/UITheme.h"
#include "fontIds.h" #include "fontIds.h"
static std::string formatBytes(uint64_t bytes) {
if (bytes >= 1024ULL * 1024 * 1024) {
char buf[16];
snprintf(buf, sizeof(buf), "%.1f GB", bytes / (1024.0 * 1024 * 1024));
return buf;
}
char buf[16];
snprintf(buf, sizeof(buf), "%u MB", static_cast<unsigned>(bytes / (1024 * 1024)));
return buf;
}
void SystemInformationActivity::onEnter() { void SystemInformationActivity::onEnter() {
Activity::onEnter(); Activity::onEnter();
requestUpdate(); requestUpdate();
@@ -28,12 +39,12 @@ void SystemInformationActivity::render(RenderLock&&) {
renderer.clearScreen(); renderer.clearScreen();
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_SYSTEM_INFO),
tr(STR_SYSTEM_INFO), CROSSPOINT_VERSION); CROSSPOINT_VERSION);
const auto status = SystemStatus::collect(); const auto status = SystemStatus::collect();
// Layout: label on the left, value on the right of the midpoint // Layout: label on the left, value right of the midpoint
const int leftX = metrics.verticalSpacing * 3; const int leftX = metrics.verticalSpacing * 3;
const int valueX = pageWidth / 2; const int valueX = pageWidth / 2;
const int lineH = renderer.getLineHeight(UI_10_FONT_ID); const int lineH = renderer.getLineHeight(UI_10_FONT_ID);
@@ -45,6 +56,7 @@ void SystemInformationActivity::render(RenderLock&&) {
renderer.drawText(UI_10_FONT_ID, valueX, y, value.c_str()); renderer.drawText(UI_10_FONT_ID, valueX, y, value.c_str());
}; };
// Device
drawRow(0, "Version", status.version); drawRow(0, "Version", status.version);
drawRow(1, "Free heap", std::to_string(status.freeHeapBytes / 1024) + " KB"); drawRow(1, "Free heap", std::to_string(status.freeHeapBytes / 1024) + " KB");
@@ -55,13 +67,22 @@ void SystemInformationActivity::render(RenderLock&&) {
snprintf(uptimeBuf, sizeof(uptimeBuf), "%uh %02um %02us", h, m, s); snprintf(uptimeBuf, sizeof(uptimeBuf), "%uh %02um %02us", h, m, s);
drawRow(2, "Uptime", uptimeBuf); drawRow(2, "Uptime", uptimeBuf);
// SD card
const std::string sdUsed = formatBytes(status.sdUsedBytes) + " / " + formatBytes(status.sdTotalBytes);
drawRow(3, "SD card", status.sdTotalBytes > 0 ? sdUsed : "N/A");
// WiFi (shown as-is; "Off" when not connected)
std::string wifiLabel = status.wifiMode; std::string wifiLabel = status.wifiMode;
if (status.rssi != 0) { if (status.rssi != 0) {
wifiLabel += " (" + std::to_string(status.rssi) + " dBm)"; wifiLabel += " (" + std::to_string(status.rssi) + " dBm)";
} }
drawRow(3, "WiFi", wifiLabel); drawRow(4, "WiFi", wifiLabel);
drawRow(4, "IP address", status.ip); if (status.wifiMode != "Off") {
drawRow(5, "MAC address", status.macAddress); drawRow(5, "IP address", status.ip);
drawRow(6, "MAC address", status.macAddress);
} else {
drawRow(5, "MAC address", status.macAddress);
}
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", ""); const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
+2 -2
View File
@@ -326,8 +326,8 @@ void CrossPointWebServer::handleStatus() const {
doc["rssi"] = status.rssi; doc["rssi"] = status.rssi;
doc["freeHeap"] = status.freeHeapBytes; doc["freeHeap"] = status.freeHeapBytes;
doc["uptime"] = status.uptimeSeconds; doc["uptime"] = status.uptimeSeconds;
doc["sdTotal"] = Storage.sdTotalBytes(); doc["sdTotal"] = status.sdTotalBytes;
doc["sdUsed"] = Storage.sdUsedBytes(); doc["sdUsed"] = status.sdUsedBytes;
String json; String json;
serializeJson(doc, json); serializeJson(doc, json);