code cleanup

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2025-06-20 21:21:06 +02:00
parent 54080bfd9d
commit 26723db8d8
19 changed files with 50 additions and 316 deletions

View File

@@ -1,19 +1,23 @@
# Definiere die Quelldateien in einer Variable
set(SOURCE_FILES
src/common/InactivityTracker.cpp
src/common/Menu.cpp
src/common/ScrollBar.cpp
src/common/Widget.cpp
src/data/MenuItem.cpp
src/ui/LightMenu.cpp
src/ui/LightSettingsMenu.cpp
src/ui/MainMenu.cpp
src/ui/ScreenSaver.cpp
src/ui/SettingsMenu.cpp
src/ui/SplashScreen.cpp
)
if (DEFINED ENV{IDF_PATH})
idf_component_register(SRCS
src/common/InactivityTracker.cpp
src/common/Menu.cpp
src/common/ScrollBar.cpp
src/common/Widget.cpp
src/data/MenuItem.cpp
src/ui/LightMenu.cpp
src/ui/LightSettingsMenu.cpp
src/ui/MainMenu.cpp
src/ui/ScreenSaver.cpp
src/ui/SettingsMenu.cpp
src/ui/SplashScreen.cpp
${SOURCE_FILES}
INCLUDE_DIRS "include"
PRIV_REQUIRES
ruth
u8g2
)
return()
@@ -23,17 +27,7 @@ cmake_minimum_required(VERSION 3.30)
project(insa)
add_library(${PROJECT_NAME} STATIC
src/common/InactivityTracker.cpp
src/common/Menu.cpp
src/common/ScrollBar.cpp
src/common/Widget.cpp
src/data/MenuItem.cpp
src/ui/LightMenu.cpp
src/ui/LightSettingsMenu.cpp
src/ui/MainMenu.cpp
src/ui/ScreenSaver.cpp
src/ui/SettingsMenu.cpp
src/ui/SplashScreen.cpp
${SOURCE_FILES}
)
include_directories(include)
@@ -42,5 +36,4 @@ target_include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} PRIVATE
u8g2
ruth
)
)

View File

@@ -16,7 +16,6 @@
#include <memory>
// Project-specific headers
#include "persistence.h"
#include "common/Widget.h"
#include "u8g2.h"
@@ -124,6 +123,4 @@ typedef struct
* @see Widget::onButtonClicked for widget-specific button handling
*/
std::function<void(ButtonType button)> onButtonClicked;
persistence_t *persistence;
} menu_options_t;

View File

@@ -12,6 +12,7 @@
#pragma once
#include <functional>
#include <stdint.h>
/**
* @class InactivityTracker
@@ -21,21 +22,21 @@
* configured timeout period. It is commonly used for implementing power
* saving features, automatic screen savers, session timeouts, and other
* time-based system behaviors.
*
*
* The InactivityTracker operates by:
* - Continuously tracking elapsed time since the last user activity
* - Comparing elapsed time against a configurable timeout threshold
* - Executing a callback function when the timeout is reached
* - Providing methods to reset the timer when activity is detected
* - Supporting enable/disable functionality for dynamic control
*
*
* Key features include:
* - Configurable timeout duration in milliseconds
* - Custom callback function execution on timeout
* - Activity reset capability for responsive user interaction
* - Enable/disable control for conditional monitoring
* - High-resolution timing support using 64-bit millisecond precision
*
*
* Common use cases:
* - Screen saver activation after idle periods
* - Automatic screen dimming or shutdown
@@ -43,14 +44,14 @@
* - Power management and battery conservation
* - User interface state transitions
* - Security lockout after inactivity
*
*
* The class is designed to be lightweight and efficient, suitable for
* real-time applications where precise timing and minimal overhead are important.
*
*
* @note This class requires regular update calls to function properly.
* @note The timeout callback is executed once per timeout period and will
* not repeat until the tracker is reset and times out again.
*
*
* @see Widget for integration with UI components
* @see Menu for menu timeout implementations
*/
@@ -61,15 +62,15 @@ class InactivityTracker
* @brief Constructs an InactivityTracker with specified timeout and callback
* @param timeoutMs Timeout duration in milliseconds before triggering callback
* @param onTimeout Callback function to execute when timeout is reached
*
*
* @pre timeoutMs must be greater than 0 for meaningful timeout behavior
* @pre onTimeout must be a valid callable function object
* @post InactivityTracker is initialized, enabled, and ready for activity monitoring
*
*
* @details The constructor initializes the inactivity tracker with the specified
* timeout duration and callback function. The tracker starts in an enabled
* state with zero elapsed time, ready to begin monitoring user activity.
*
*
* The timeout callback function can perform any necessary actions when inactivity
* is detected, such as:
* - Activating screen savers or power saving modes
@@ -77,11 +78,11 @@ class InactivityTracker
* - Logging inactivity events
* - Triggering security lockouts
* - Initiating automatic save operations
*
*
* @note The tracker begins monitoring immediately upon construction.
* @note The callback function should be lightweight to avoid blocking
* the main application thread during timeout processing.
*
*
* Example usage:
* @code
* auto tracker = InactivityTracker(30000, []() {
@@ -95,23 +96,23 @@ class InactivityTracker
/**
* @brief Updates the inactivity timer and checks for timeout conditions
* @param dt Delta time in milliseconds since the last update call
*
*
* @details This method must be called regularly (typically every frame) to
* maintain accurate timing and timeout detection. It increments the
* elapsed time counter and triggers the timeout callback when the
* configured timeout duration is reached.
*
*
* The update process:
* - Adds the delta time to the elapsed time counter (if enabled)
* - Compares elapsed time against the configured timeout threshold
* - Executes the timeout callback if the threshold is exceeded
* - Continues monitoring until reset or disabled
*
*
* @note This method should be called consistently from the main application
* loop to ensure accurate timing behavior.
* @note The timeout callback is executed only once per timeout period.
* @note If the tracker is disabled, elapsed time is not updated.
*
*
* @see reset() to restart the inactivity timer
* @see setEnabled() to control monitoring state
*/
@@ -119,27 +120,27 @@ class InactivityTracker
/**
* @brief Resets the inactivity timer to indicate recent user activity
*
*
* @details This method should be called whenever user activity is detected
* to restart the inactivity timeout period. It resets the elapsed
* time counter to zero, effectively extending the timeout deadline
* and preventing timeout callback execution until the full timeout
* duration elapses again without further resets.
*
*
* Common scenarios for calling reset():
* - Button presses or key events
* - Mouse movement or touch input
* - Menu navigation or selection actions
* - Any user interface interaction
* - System activity that should extend the timeout
*
*
* @post Elapsed time is reset to zero, restarting the timeout period
*
*
* @note This method can be called at any time, even when the tracker
* is disabled, to prepare for future monitoring.
* @note Frequent reset calls from active user interaction will prevent
* timeout callback execution, which is the intended behavior.
*
*
* Example usage:
* @code
* void onButtonPress() {
@@ -153,29 +154,29 @@ class InactivityTracker
/**
* @brief Enables or disables inactivity monitoring
* @param enabled True to enable monitoring, false to disable
*
*
* @details This method controls whether the inactivity tracker actively
* monitors for timeouts. When disabled, the elapsed time counter
* is not updated during update() calls, effectively pausing the
* timeout detection without losing the current elapsed time state.
*
*
* Use cases for disabling:
* - Temporary suspension during system operations
* - Context-sensitive monitoring (disable in certain application states)
* - Power management control (disable during low-power modes)
* - User preference settings (allow users to disable timeouts)
* - Development and debugging (disable for testing)
*
*
* When re-enabled, monitoring resumes from the current elapsed time state,
* allowing for seamless pause/resume functionality.
*
*
* @post Monitoring state is updated according to the enabled parameter
*
*
* @note Disabling the tracker does not reset the elapsed time counter.
* @note The timeout callback will not be executed while disabled, even
* if the timeout threshold would otherwise be exceeded.
* @note Enabling/disabling can be done at any time during operation.
*
*
* Example usage:
* @code
* tracker.setEnabled(false); // Pause monitoring during critical operation
@@ -186,8 +187,8 @@ class InactivityTracker
void setEnabled(bool enabled);
private:
uint64_t m_timeoutMs; ///< Timeout duration in milliseconds before callback execution
uint64_t m_elapsedTime; ///< Current elapsed time since last reset in milliseconds
bool m_enabled; ///< Flag indicating whether monitoring is currently active
std::function<void()> m_onTimeout; ///< Callback function executed when timeout threshold is reached
uint64_t m_timeoutMs; ///< Timeout duration in milliseconds before callback execution
uint64_t m_elapsedTime; ///< Current elapsed time since last reset in milliseconds
bool m_enabled; ///< Flag indicating whether monitoring is currently active
std::function<void()> m_onTimeout; ///< Callback function executed when timeout threshold is reached
};

View File

@@ -30,7 +30,6 @@ LightMenu::LightMenu(menu_options_t *options) : Menu(options), m_options(options
void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button)
{
MenuItem item = menuItem;
std::shared_ptr<Widget> widget;
// Handle different menu items based on their ID
@@ -42,25 +41,12 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
{
toggle(menuItem);
}
if (m_options && m_options->persistence && m_options->persistence->save)
{
const auto value = getItem(item.getId()).getValue();
m_options->persistence->save(VALUE_TYPE_STRING, "light_activated", value.c_str());
}
break;
}
case LightMenuItem::MODE: {
// Switch between day/night modes using left/right buttons
item = switchValue(menuItem, button);
if (button == ButtonType::LEFT || button == ButtonType::RIGHT)
{
if (m_options && m_options->persistence && m_options->persistence->save)
{
const auto value = getItem(item.getId()).getIndex();
m_options->persistence->save(VALUE_TYPE_INT32, "light_mode", &value);
}
}
switchValue(menuItem, button);
break;
}

View File

@@ -31,12 +31,4 @@ void LightSettingsMenu::onButtonPressed(const MenuItem &menuItem, const ButtonTy
// Update the section list size based on the section counter value
setItemSize(std::stoull(getItem(0).getValue()));
// Persist the changed section values if persistence is available
if (m_options && m_options->persistence && m_options->persistence->save)
{
const auto key = "section_" + std::to_string(menuItem.getId());
const auto value = getItem(menuItem.getId()).getValue();
m_options->persistence->save(VALUE_TYPE_STRING, key.c_str(), value.c_str());
}
}