From 7f288c0816de4ae93272e96050992a760aac7186 Mon Sep 17 00:00:00 2001 From: jude <45611619+geogod42@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:50:38 -0500 Subject: [PATCH] Add uptime to statistics menu Fixes #4392 Add uptime to the statistics menu. * Add a new function `RecordUptime` in `src/common/app_metrics.cpp` to record the uptime in hours. * Modify `RecordRuntimeStats` in `src/common/app_metrics.cpp` to call `RecordUptime`. * Update `src/common/appmain.cpp` to call `RecordUptime` in the `app_run` function. * Add a new line to display the uptime in hours in the statistics menu in `src/gui/screen_menu_statistics.cpp`. * Add a new member variable to store the uptime and a new method to update the uptime in `src/gui/screen_menu_statistics.hpp`. --- src/common/app_metrics.cpp | 7 +++++++ src/common/appmain.cpp | 1 + src/gui/screen_menu_statistics.cpp | 9 +++++++++ src/gui/screen_menu_statistics.hpp | 2 ++ 4 files changed, 19 insertions(+) diff --git a/src/common/app_metrics.cpp b/src/common/app_metrics.cpp index 9f25018e39..3d9329ffc3 100644 --- a/src/common/app_metrics.cpp +++ b/src/common/app_metrics.cpp @@ -133,6 +133,8 @@ void buddy::metrics::RecordRuntimeStats() { METRIC_DEF(heap, "heap", METRIC_VALUE_CUSTOM, 503, METRIC_HANDLER_ENABLE_ALL); metric_record_custom(&heap, " free=%zui,total=%zui", xPortGetFreeHeapSize(), static_cast(heap_total_size)); + + RecordUptime(); } void buddy::metrics::RecordMarlinVariables() { @@ -352,4 +354,9 @@ void buddy::metrics::record_dwarf_internal_temperatures() { } } } + +void buddy::metrics::RecordUptime() { + METRIC_DEF(uptime, "uptime", METRIC_VALUE_INTEGER, 1000, METRIC_HANDLER_ENABLE_ALL); + metric_record_integer(&uptime, ticks_s() / 3600); +} #endif diff --git a/src/common/appmain.cpp b/src/common/appmain.cpp index 08d535e996..e66260ab49 100644 --- a/src/common/appmain.cpp +++ b/src/common/appmain.cpp @@ -233,6 +233,7 @@ void app_run(void) { loop(); } marlin_server::loop(); + buddy::metrics::RecordUptime(); // Pa465 } } diff --git a/src/gui/screen_menu_statistics.cpp b/src/gui/screen_menu_statistics.cpp index 442f758bc9..ddee229580 100644 --- a/src/gui/screen_menu_statistics.cpp +++ b/src/gui/screen_menu_statistics.cpp @@ -4,11 +4,14 @@ #include "screen_menu_statistics.hpp" #include "DialogMoveZ.hpp" #include "img_resources.hpp" +#include "app_metrics.h" ScreenMenuStatistics::ScreenMenuStatistics() : ScreenMenuStatistics__(_(label)) { EnableLongHoldScreenAction(); header.SetIcon(&img::info_16x16); + AddItem(&uptime_label); + updateUptime(); } void ScreenMenuStatistics::windowEvent(window_t *sender, GUI_event_t event, void *param) { @@ -19,3 +22,9 @@ void ScreenMenuStatistics::windowEvent(window_t *sender, GUI_event_t event, void ScreenMenu::windowEvent(sender, event, param); } + +void ScreenMenuStatistics::updateUptime() { + char buffer[32]; + snprintf(buffer, sizeof(buffer), "Uptime: %lu hours", ticks_s() / 3600); + uptime_label.SetText(buffer); +} diff --git a/src/gui/screen_menu_statistics.hpp b/src/gui/screen_menu_statistics.hpp index 01d161ea53..a8e44668ad 100644 --- a/src/gui/screen_menu_statistics.hpp +++ b/src/gui/screen_menu_statistics.hpp @@ -23,4 +23,6 @@ class ScreenMenuStatistics : public ScreenMenuStatistics__ { private: virtual void windowEvent(window_t *sender, GUI_event_t event, void *param) override; + void updateUptime(); + IWindowMenuItem uptime_label; };