diff --git a/firmware/components/insa/include/common/Common.h b/firmware/components/insa/include/common/Common.h index 56b1090..cee9148 100644 --- a/firmware/components/insa/include/common/Common.h +++ b/firmware/components/insa/include/common/Common.h @@ -1,7 +1,7 @@ /** * @file Common.h * @brief Common definitions and types for the INSA component - * @details This header file contains shared enumerations, type definitions, and + * @details This header file contains shared enumerations, type definitions, and * callback function types used throughout the INSA component system. * It provides the foundation for button handling and event management. * @author System Control Team @@ -16,19 +16,19 @@ * @enum ButtonType * @brief Enumeration defining the different types of buttons available in the system * @details This enumeration represents all possible button types that can be handled - * by the system's input management. NONE represents no button pressed or + * by the system's input management. NONE represents no button pressed or * an invalid button state, while the other values correspond to specific * directional and action buttons. */ enum class ButtonType { - NONE, ///< No button pressed or invalid button state - UP, ///< Up directional button for navigation - DOWN, ///< Down directional button for navigation - LEFT, ///< Left directional button for navigation - RIGHT, ///< Right directional button for navigation + NONE, ///< No button pressed or invalid button state + UP, ///< Up directional button for navigation + DOWN, ///< Down directional button for navigation + LEFT, ///< Left directional button for navigation + RIGHT, ///< Right directional button for navigation SELECT, ///< Select/confirm button for accepting choices - BACK ///< Back/cancel button for returning to previous state + BACK ///< Back/cancel button for returning to previous state }; // Forward declaration of MenuItem to avoid circular dependency @@ -40,13 +40,13 @@ class MenuItem; * @details This function type is used to define callback functions that handle * button press events. The callback receives information about which * button was pressed and any additional context data. - * + * * @param MenuItem menu item for the specific action * @param ButtonType The type of button that was pressed - * + * * @note The first parameter can be used to distinguish between multiple instances * of the same button type or to pass additional event-specific data. - * + * * @example * @code * ButtonCallback myCallback = [](const MenuItem& item, ButtonType type) { @@ -59,5 +59,37 @@ class MenuItem; */ typedef std::function ButtonCallback; +/** + * @def IMPLEMENT_GET_NAME + * @brief Macro to implement getName() method using __FILE__ + * @details Extracts the class name from the source filename automatically. + * Use this macro in .cpp files to implement Widget::getName(). + * @param ClassName The class name for the method scope (e.g., MainMenu) + */ +#define IMPLEMENT_GET_NAME(ClassName) \ + const char *ClassName::getName() const \ + { \ + static const char *cachedName = nullptr; \ + if (!cachedName) \ + { \ + const char *file = __FILE__; \ + const char *lastSlash = file; \ + for (const char *p = file; *p; ++p) \ + { \ + if (*p == '/' || *p == '\\') \ + lastSlash = p + 1; \ + } \ + static char buffer[64]; \ + size_t i = 0; \ + for (; lastSlash[i] && lastSlash[i] != '.' && i < sizeof(buffer) - 1; ++i) \ + { \ + buffer[i] = lastSlash[i]; \ + } \ + buffer[i] = '\0'; \ + cachedName = buffer; \ + } \ + return cachedName; \ + } + // Include MenuItem.h after the typedef to avoid circular dependency #include "data/MenuItem.h" \ No newline at end of file diff --git a/firmware/components/insa/include/common/Widget.h b/firmware/components/insa/include/common/Widget.h index 6cca341..603c6b4 100644 --- a/firmware/components/insa/include/common/Widget.h +++ b/firmware/components/insa/include/common/Widget.h @@ -150,6 +150,19 @@ class Widget */ virtual void OnButtonClicked(ButtonType button); + /** + * @brief Returns the name of this widget for diagnostic purposes + * @return A string identifying the widget type + * + * @details This method returns a human-readable name for the widget which + * is used for logging and diagnostic events. Derived classes should + * override this method to return their specific screen/widget name. + * + * @note The base implementation returns "Widget". Override in derived classes + * to provide meaningful screen names for diagnostics. + */ + virtual const char *getName() const; + protected: /** * @brief Pointer to the u8g2 display context used for rendering operations diff --git a/firmware/components/insa/include/ui/ClockScreenSaver.h b/firmware/components/insa/include/ui/ClockScreenSaver.h index 1dbc0b1..09b2585 100644 --- a/firmware/components/insa/include/ui/ClockScreenSaver.h +++ b/firmware/components/insa/include/ui/ClockScreenSaver.h @@ -24,6 +24,7 @@ class ClockScreenSaver final : public Widget void Update(uint64_t dt) override; void Render() override; void OnButtonClicked(ButtonType button) override; + const char *getName() const override; private: static constexpr int MOVE_INTERVAL = 50; // milliseconds between movements diff --git a/firmware/components/insa/include/ui/ExternalDevices.h b/firmware/components/insa/include/ui/ExternalDevices.h index 372da4e..4f08d52 100644 --- a/firmware/components/insa/include/ui/ExternalDevices.h +++ b/firmware/components/insa/include/ui/ExternalDevices.h @@ -7,6 +7,8 @@ class ExternalDevices final : public Menu public: explicit ExternalDevices(menu_options_t *options); + const char *getName() const override; + private: void onButtonPressed(const MenuItem &menuItem, ButtonType button) override; menu_options_t *m_options; diff --git a/firmware/components/insa/include/ui/LightMenu.h b/firmware/components/insa/include/ui/LightMenu.h index d3af7b0..10a4d43 100644 --- a/firmware/components/insa/include/ui/LightMenu.h +++ b/firmware/components/insa/include/ui/LightMenu.h @@ -80,6 +80,8 @@ class LightMenu final : public Menu */ explicit LightMenu(menu_options_t *options); + const char *getName() const override; + private: /** * @brief Handles button press events specific to light control menu items diff --git a/firmware/components/insa/include/ui/MainMenu.h b/firmware/components/insa/include/ui/MainMenu.h index 862e86a..31d0ede 100644 --- a/firmware/components/insa/include/ui/MainMenu.h +++ b/firmware/components/insa/include/ui/MainMenu.h @@ -57,6 +57,8 @@ class MainMenu final : public Menu */ explicit MainMenu(menu_options_t *options); + const char *getName() const override; + private: /** * @brief Handles button press events specific to main menu items diff --git a/firmware/components/insa/include/ui/ScreenSaver.h b/firmware/components/insa/include/ui/ScreenSaver.h index 7386d5b..a8f2256 100644 --- a/firmware/components/insa/include/ui/ScreenSaver.h +++ b/firmware/components/insa/include/ui/ScreenSaver.h @@ -26,6 +26,7 @@ class ScreenSaver final : public Widget void Update(uint64_t dt) override; void Render() override; void OnButtonClicked(ButtonType button) override; + const char *getName() const override; private: /** diff --git a/firmware/components/insa/include/ui/SettingsMenu.h b/firmware/components/insa/include/ui/SettingsMenu.h index 1745b47..234da1f 100644 --- a/firmware/components/insa/include/ui/SettingsMenu.h +++ b/firmware/components/insa/include/ui/SettingsMenu.h @@ -20,40 +20,40 @@ * interface for the application. It allows users to configure various aspects * of the system including display preferences, system behavior, network * settings, and other configurable parameters. - * + * * The SettingsMenu class extends the base Menu functionality by: * - Providing settings-specific menu items (toggles, selections, number inputs) * - Managing configuration persistence and validation * - Organizing settings into logical categories and sections * - Implementing real-time preview of setting changes where applicable - * + * * Typical settings categories include: * - Display settings (brightness, contrast, theme) * - System preferences (timeouts, auto-save, etc.) * - Network configuration (if applicable) * - User interface preferences * - Hardware-specific parameters - * + * * @note This class is marked as final and cannot be inherited from. * @note Settings changes are typically applied immediately or after confirmation, * depending on the specific setting type and system requirements. - * + * * @see Menu for base menu functionality * @see menu_options_t for configuration structure * @see MainMenu for navigation back to main interface */ class SettingsMenu final : public Menu { -public: + public: /** * @brief Constructs the settings menu with the specified configuration * @param options Pointer to menu options configuration structure - * + * * @pre options must not be nullptr and must remain valid for the menu's lifetime * @pre options->u8g2 must be initialized and ready for graphics operations * @pre All callback functions in options must be properly configured * @post SettingsMenu is initialized with all available configuration options and ready for use - * + * * @details The constructor initializes the settings menu by creating all the * configuration menu items based on the current system state and * available options. This includes: @@ -61,17 +61,19 @@ public: * - Creating appropriate menu items (toggles, selections, number inputs) * - Setting up validation ranges and allowed values * - Organizing items in a logical, user-friendly order - * + * * The menu automatically detects which settings are available based on * hardware capabilities and system configuration, ensuring only relevant * options are presented to the user. - * + * * @note The menu does not take ownership of the options structure and assumes * it remains valid throughout the menu's lifetime. * @note Setting values are loaded from persistent storage during construction * and changes are typically saved automatically or on confirmation. - * + * * @see Menu::Menu for base class construction details */ explicit SettingsMenu(menu_options_t *options); + + const char *getName() const override; }; \ No newline at end of file diff --git a/firmware/components/insa/include/ui/SplashScreen.h b/firmware/components/insa/include/ui/SplashScreen.h index 5ffeb4e..86fb49f 100644 --- a/firmware/components/insa/include/ui/SplashScreen.h +++ b/firmware/components/insa/include/ui/SplashScreen.h @@ -151,6 +151,8 @@ class SplashScreen final : public Widget */ void Render() override; + const char *getName() const override; + private: /** * @brief Pointer to menu options configuration structure diff --git a/firmware/components/insa/src/common/Widget.cpp b/firmware/components/insa/src/common/Widget.cpp index 64750e6..16054b0 100644 --- a/firmware/components/insa/src/common/Widget.cpp +++ b/firmware/components/insa/src/common/Widget.cpp @@ -31,3 +31,8 @@ void Widget::Render() void Widget::OnButtonClicked(ButtonType button) { } + +const char *Widget::getName() const +{ + return "Widget"; +} diff --git a/firmware/components/insa/src/ui/ClockScreenSaver.cpp b/firmware/components/insa/src/ui/ClockScreenSaver.cpp index 7cc16e6..0b45171 100644 --- a/firmware/components/insa/src/ui/ClockScreenSaver.cpp +++ b/firmware/components/insa/src/ui/ClockScreenSaver.cpp @@ -132,3 +132,5 @@ void ClockScreenSaver::OnButtonClicked(ButtonType button) m_options->popScreen(); } } + +IMPLEMENT_GET_NAME(ClockScreenSaver) diff --git a/firmware/components/insa/src/ui/ExternalDevices.cpp b/firmware/components/insa/src/ui/ExternalDevices.cpp index 0e2cc02..7e421ba 100644 --- a/firmware/components/insa/src/ui/ExternalDevices.cpp +++ b/firmware/components/insa/src/ui/ExternalDevices.cpp @@ -23,3 +23,5 @@ void ExternalDevices::onButtonPressed(const MenuItem &menuItem, const ButtonType ble_connect_to_device(menuItem.getId()); } } + +IMPLEMENT_GET_NAME(ExternalDevices) diff --git a/firmware/components/insa/src/ui/LightMenu.cpp b/firmware/components/insa/src/ui/LightMenu.cpp index 91e45cc..05dfb71 100644 --- a/firmware/components/insa/src/ui/LightMenu.cpp +++ b/firmware/components/insa/src/ui/LightMenu.cpp @@ -123,3 +123,5 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto m_options->pushScreen(widget); } } + +IMPLEMENT_GET_NAME(LightMenu) diff --git a/firmware/components/insa/src/ui/MainMenu.cpp b/firmware/components/insa/src/ui/MainMenu.cpp index 351398b..70f1f6e 100644 --- a/firmware/components/insa/src/ui/MainMenu.cpp +++ b/firmware/components/insa/src/ui/MainMenu.cpp @@ -48,3 +48,5 @@ void MainMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button } } } + +IMPLEMENT_GET_NAME(MainMenu) diff --git a/firmware/components/insa/src/ui/ScreenSaver.cpp b/firmware/components/insa/src/ui/ScreenSaver.cpp index 16c384e..34509c3 100644 --- a/firmware/components/insa/src/ui/ScreenSaver.cpp +++ b/firmware/components/insa/src/ui/ScreenSaver.cpp @@ -326,4 +326,6 @@ void ScreenSaver::OnButtonClicked(ButtonType button) { m_options->popScreen(); } -} \ No newline at end of file +} + +IMPLEMENT_GET_NAME(ScreenSaver) diff --git a/firmware/components/insa/src/ui/SettingsMenu.cpp b/firmware/components/insa/src/ui/SettingsMenu.cpp index 6f874d8..864ff36 100644 --- a/firmware/components/insa/src/ui/SettingsMenu.cpp +++ b/firmware/components/insa/src/ui/SettingsMenu.cpp @@ -8,4 +8,6 @@ constexpr uint8_t OTA_UPLOAD = 0; SettingsMenu::SettingsMenu(menu_options_t *options) : Menu(options) { addText(SettingsMenuItem::OTA_UPLOAD, "OTA Einspielen"); -} \ No newline at end of file +} + +IMPLEMENT_GET_NAME(SettingsMenu) diff --git a/firmware/components/insa/src/ui/SplashScreen.cpp b/firmware/components/insa/src/ui/SplashScreen.cpp index b1e3392..2d6a038 100644 --- a/firmware/components/insa/src/ui/SplashScreen.cpp +++ b/firmware/components/insa/src/ui/SplashScreen.cpp @@ -28,3 +28,5 @@ void SplashScreen::Render() u8g2_SetFont(u8g2, u8g2_font_haxrcorp4089_tr); u8g2_DrawStr(u8g2, 35, 50, "Initialisierung..."); } + +IMPLEMENT_GET_NAME(SplashScreen) diff --git a/firmware/main/app_task.cpp b/firmware/main/app_task.cpp index 539832e..63996b1 100644 --- a/firmware/main/app_task.cpp +++ b/firmware/main/app_task.cpp @@ -14,6 +14,7 @@ #include "wifi_manager.h" #include #include +#include #include #include #include @@ -62,6 +63,7 @@ void setScreen(const std::shared_ptr &screen) { if (screen != nullptr) { + ESP_DIAG_EVENT(TAG, "Screen set: %s", screen->getName()); m_widget = screen; m_history.clear(); m_history.emplace_back(m_widget); @@ -77,6 +79,7 @@ void pushScreen(const std::shared_ptr &screen) { m_widget->onPause(); } + ESP_DIAG_EVENT(TAG, "Screen pushed: %s", screen->getName()); m_widget = screen; m_widget->onEnter(); m_history.emplace_back(m_widget); @@ -97,6 +100,7 @@ void popScreen() m_widget->onExit(); } m_widget = m_history.back(); + ESP_DIAG_EVENT(TAG, "Screen popped, now: %s", m_widget->getName()); m_widget->onResume(); } }