Merge branch 'temp_info' of https://github.com/jpirnay/crosspoint-reader into feat-sdcard-info
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
// Snapshot of device system status, shared between the web server and the
|
||||
// System Information activity so both surfaces show consistent data.
|
||||
struct SystemStatus {
|
||||
const char* version;
|
||||
std::string ip;
|
||||
std::string wifiMode; // "STA", "AP", or "Off"
|
||||
int rssi; // dBm; 0 when not in STA mode
|
||||
std::string macAddress;
|
||||
uint32_t freeHeapBytes;
|
||||
uint32_t uptimeSeconds;
|
||||
|
||||
static SystemStatus collect() {
|
||||
SystemStatus s;
|
||||
s.version = CROSSPOINT_VERSION;
|
||||
s.freeHeapBytes = ESP.getFreeHeap();
|
||||
s.uptimeSeconds = millis() / 1000;
|
||||
s.macAddress = WiFi.macAddress().c_str();
|
||||
|
||||
const wifi_mode_t mode = WiFi.getMode();
|
||||
const bool isAP = (mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA);
|
||||
|
||||
if (isAP) {
|
||||
s.wifiMode = "AP";
|
||||
s.ip = WiFi.softAPIP().toString().c_str();
|
||||
s.rssi = 0;
|
||||
} else if (WiFi.status() == WL_CONNECTED) {
|
||||
s.wifiMode = "STA";
|
||||
s.ip = WiFi.localIP().toString().c_str();
|
||||
s.rssi = WiFi.RSSI();
|
||||
} else {
|
||||
s.wifiMode = "Off";
|
||||
s.ip = "-";
|
||||
s.rssi = 0;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "ButtonRemapActivity.h"
|
||||
#include "CalibreSettingsActivity.h"
|
||||
#include "ClearCacheActivity.h"
|
||||
#include "SystemInformationActivity.h"
|
||||
#include "CrossPointSettings.h"
|
||||
#include "KOReaderSettingsActivity.h"
|
||||
#include "LanguageSelectActivity.h"
|
||||
@@ -52,6 +53,7 @@ void SettingsActivity::onEnter() {
|
||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLEAR_READING_CACHE, SettingAction::ClearCache));
|
||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_CHECK_UPDATES, SettingAction::CheckForUpdates));
|
||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_LANGUAGE, SettingAction::Language));
|
||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_SYSTEM_INFO, SettingAction::SystemInfo));
|
||||
readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
|
||||
|
||||
// Reset selection to first category
|
||||
@@ -192,6 +194,9 @@ void SettingsActivity::toggleCurrentSetting() {
|
||||
case SettingAction::Language:
|
||||
startActivityForResult(std::make_unique<LanguageSelectActivity>(renderer, mappedInput), resultHandler);
|
||||
break;
|
||||
case SettingAction::SystemInfo:
|
||||
startActivityForResult(std::make_unique<SystemInformationActivity>(renderer, mappedInput), resultHandler);
|
||||
break;
|
||||
case SettingAction::None:
|
||||
// Do nothing
|
||||
break;
|
||||
|
||||
@@ -21,6 +21,7 @@ enum class SettingAction {
|
||||
ClearCache,
|
||||
CheckForUpdates,
|
||||
Language,
|
||||
SystemInfo,
|
||||
};
|
||||
|
||||
struct SettingInfo {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "SystemInformationActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <I18n.h>
|
||||
|
||||
#include "MappedInputManager.h"
|
||||
#include "SystemStatus.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
void SystemInformationActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
void SystemInformationActivity::onExit() { Activity::onExit(); }
|
||||
|
||||
void SystemInformationActivity::loop() {
|
||||
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
void SystemInformationActivity::render(RenderLock&&) {
|
||||
const auto& metrics = UITheme::getInstance().getMetrics();
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
const auto pageHeight = renderer.getScreenHeight();
|
||||
|
||||
renderer.clearScreen();
|
||||
|
||||
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight},
|
||||
tr(STR_SYSTEM_INFO), CROSSPOINT_VERSION);
|
||||
|
||||
const auto status = SystemStatus::collect();
|
||||
|
||||
// Layout: label on the left, value on the right of the midpoint
|
||||
const int leftX = metrics.verticalSpacing * 3;
|
||||
const int valueX = pageWidth / 2;
|
||||
const int lineH = renderer.getLineHeight(UI_10_FONT_ID);
|
||||
const int startY = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing * 3;
|
||||
|
||||
auto drawRow = [&](int row, const char* label, const std::string& value) {
|
||||
const int y = startY + row * (lineH + metrics.verticalSpacing);
|
||||
renderer.drawText(UI_10_FONT_ID, leftX, y, label, true, EpdFontFamily::BOLD);
|
||||
renderer.drawText(UI_10_FONT_ID, valueX, y, value.c_str());
|
||||
};
|
||||
|
||||
drawRow(0, "Version", status.version);
|
||||
drawRow(1, "Free heap", std::to_string(status.freeHeapBytes / 1024) + " KB");
|
||||
|
||||
const uint32_t h = status.uptimeSeconds / 3600;
|
||||
const uint32_t m = (status.uptimeSeconds % 3600) / 60;
|
||||
const uint32_t s = status.uptimeSeconds % 60;
|
||||
char uptimeBuf[16];
|
||||
snprintf(uptimeBuf, sizeof(uptimeBuf), "%uh %02um %02us", h, m, s);
|
||||
drawRow(2, "Uptime", uptimeBuf);
|
||||
|
||||
std::string wifiLabel = status.wifiMode;
|
||||
if (status.rssi != 0) {
|
||||
wifiLabel += " (" + std::to_string(status.rssi) + " dBm)";
|
||||
}
|
||||
drawRow(3, "WiFi", wifiLabel);
|
||||
drawRow(4, "IP address", status.ip);
|
||||
drawRow(5, "MAC address", status.macAddress);
|
||||
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
|
||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "activities/Activity.h"
|
||||
|
||||
class SystemInformationActivity final : public Activity {
|
||||
public:
|
||||
explicit SystemInformationActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
|
||||
: Activity("SystemInformation", renderer, mappedInput) {}
|
||||
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
void render(RenderLock&&) override;
|
||||
};
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "SettingsList.h"
|
||||
#include "SystemStatus.h"
|
||||
#include "WebDAVHandler.h"
|
||||
#include "html/FilesPageHtml.generated.h"
|
||||
#include "html/HomePageHtml.generated.h"
|
||||
@@ -316,16 +317,15 @@ void CrossPointWebServer::handleNotFound() const {
|
||||
}
|
||||
|
||||
void CrossPointWebServer::handleStatus() const {
|
||||
// Get correct IP based on AP vs STA mode
|
||||
const String ipAddr = apMode ? WiFi.softAPIP().toString() : WiFi.localIP().toString();
|
||||
const auto status = SystemStatus::collect();
|
||||
|
||||
JsonDocument doc;
|
||||
doc["version"] = CROSSPOINT_VERSION;
|
||||
doc["ip"] = ipAddr;
|
||||
doc["mode"] = apMode ? "AP" : "STA";
|
||||
doc["rssi"] = apMode ? 0 : WiFi.RSSI();
|
||||
doc["freeHeap"] = ESP.getFreeHeap();
|
||||
doc["uptime"] = millis() / 1000;
|
||||
doc["version"] = status.version;
|
||||
doc["ip"] = status.ip;
|
||||
doc["mode"] = status.wifiMode;
|
||||
doc["rssi"] = status.rssi;
|
||||
doc["freeHeap"] = status.freeHeapBytes;
|
||||
doc["uptime"] = status.uptimeSeconds;
|
||||
doc["sdTotal"] = Storage.sdTotalBytes();
|
||||
doc["sdUsed"] = Storage.sdUsedBytes();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user