some optimizations regarding LED color
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
idf_component_register(SRCS
|
||||
src/common/ColorSettingsMenu.cpp
|
||||
src/common/InactivityTracker.cpp
|
||||
src/common/Menu.cpp
|
||||
src/common/ScrollBar.cpp
|
||||
src/common/Widget.cpp
|
||||
src/data/MenuItem.cpp
|
||||
src/ui/DayColorSettingsMenu.cpp
|
||||
src/ui/LightMenu.cpp
|
||||
src/ui/LightSettingsMenu.cpp
|
||||
src/ui/MainMenu.cpp
|
||||
src/ui/NightColorSettingsMenu.cpp
|
||||
src/ui/ClockScreenSaver.cpp
|
||||
src/ui/ScreenSaver.cpp
|
||||
src/ui/SettingsMenu.cpp
|
||||
|
29
firmware/components/insa/include/common/ColorSettingsMenu.h
Normal file
29
firmware/components/insa/include/common/ColorSettingsMenu.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Menu.h"
|
||||
|
||||
namespace ColorSettingsMenuOptions
|
||||
{
|
||||
constexpr auto RED = "red_";
|
||||
constexpr auto GREEN = "green_";
|
||||
constexpr auto BLUE = "blue_";
|
||||
} // namespace ColorSettingsMenuOptions
|
||||
|
||||
class ColorSettingsMenu : public Menu
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a ColorSettingsMenu with the specified options
|
||||
* @param options Pointer to menu configuration options structure
|
||||
* @details Initializes the menu with color settings options
|
||||
*/
|
||||
explicit ColorSettingsMenu(menu_options_t *options, std::string prefix);
|
||||
|
||||
void onButtonPressed(const MenuItem &menuItem, const ButtonType button) override;
|
||||
|
||||
void onExit() override;
|
||||
|
||||
private:
|
||||
std::string m_suffix;
|
||||
menu_options_t *m_options;
|
||||
};
|
@@ -159,7 +159,7 @@ class Menu : public Widget
|
||||
* @note New items are created as selection items with auto-generated names
|
||||
* in the format "Section X" where X is the item number
|
||||
*/
|
||||
void setItemSize(size_t size);
|
||||
void setItemSize(size_t size, int8_t startIndex = 0);
|
||||
|
||||
/**
|
||||
* @brief Toggles the boolean state of a toggle menu item
|
||||
|
@@ -63,7 +63,7 @@ class Widget
|
||||
* @note This method is typically called by the UI management system during
|
||||
* screen transitions or focus changes.
|
||||
*/
|
||||
virtual void enter();
|
||||
virtual void onEnter();
|
||||
|
||||
/**
|
||||
* @brief Called when the widget is temporarily paused or loses focus
|
||||
@@ -76,7 +76,7 @@ class Widget
|
||||
* only if pause behavior is needed.
|
||||
* @note The widget should be prepared to resume from this state when resume() is called.
|
||||
*/
|
||||
virtual void pause();
|
||||
virtual void onPause();
|
||||
|
||||
/**
|
||||
* @brief Called when the widget resumes from a paused state
|
||||
@@ -89,7 +89,7 @@ class Widget
|
||||
* only if resume behavior is needed.
|
||||
* @note This method should restore the widget to the state it was in before pause() was called.
|
||||
*/
|
||||
virtual void resume();
|
||||
virtual void onResume();
|
||||
|
||||
/**
|
||||
* @brief Called when the widget is being destroyed or exits the system
|
||||
@@ -99,11 +99,11 @@ class Widget
|
||||
* save final state, or release resources that are not automatically freed.
|
||||
*
|
||||
* @note The base implementation is empty, allowing derived classes to override
|
||||
* only if exit behavior is needed.
|
||||
* only if onExit behavior is needed.
|
||||
* @note This method is called before the widget's destructor and provides
|
||||
* an opportunity for controlled shutdown of widget-specific resources.
|
||||
*/
|
||||
virtual void exit();
|
||||
virtual void onExit();
|
||||
|
||||
/**
|
||||
* @brief Updates the widget's internal state based on elapsed time
|
||||
|
14
firmware/components/insa/include/ui/DayColorSettingsMenu.h
Normal file
14
firmware/components/insa/include/ui/DayColorSettingsMenu.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/ColorSettingsMenu.h"
|
||||
|
||||
class DayColorSettingsMenu final : public ColorSettingsMenu
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a DayColorSettingsMenu with the specified options
|
||||
* @param options Pointer to menu configuration options structure
|
||||
* @details Initializes the menu with day color settings options
|
||||
*/
|
||||
explicit DayColorSettingsMenu(menu_options_t *options);
|
||||
};
|
@@ -19,84 +19,84 @@
|
||||
* @details This final class inherits from Menu and represents the main menu interface
|
||||
* of the application. It serves as the primary entry point for user interaction
|
||||
* and provides navigation to all major application features and sub-menus.
|
||||
*
|
||||
*
|
||||
* The MainMenu class customizes the base Menu functionality by:
|
||||
* - Defining application-specific menu items during construction
|
||||
* - Implementing custom button handling for main menu navigation
|
||||
* - Managing transitions to sub-menus and application features
|
||||
*
|
||||
*
|
||||
* This class is typically the first screen presented to users after the splash
|
||||
* screen and serves as the central hub for all application functionality.
|
||||
*
|
||||
*
|
||||
* @note This class is marked as final and cannot be inherited from.
|
||||
*
|
||||
*
|
||||
* @see Menu for base menu functionality
|
||||
* @see menu_options_t for configuration structure
|
||||
*/
|
||||
class MainMenu final : public Menu
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs the main 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 MainMenu is initialized with application-specific menu items and ready for use
|
||||
*
|
||||
*
|
||||
* @details The constructor initializes the main menu by setting up all the
|
||||
* primary application menu items such as:
|
||||
* - Settings access
|
||||
* - Feature-specific menus
|
||||
* - System controls
|
||||
* - Application exit options
|
||||
*
|
||||
* - Application onExit options
|
||||
*
|
||||
* @note The menu does not take ownership of the options structure and assumes
|
||||
* it remains valid throughout the menu's lifetime.
|
||||
*/
|
||||
explicit MainMenu(menu_options_t *options);
|
||||
|
||||
private:
|
||||
private:
|
||||
/**
|
||||
* @brief Handles button press events specific to main menu items
|
||||
* @param menuItem
|
||||
* @param button Type of button that was pressed
|
||||
*
|
||||
*
|
||||
* @details Overrides the base Menu class method to provide main menu-specific
|
||||
* button handling logic. This method processes user interactions with
|
||||
* main menu items and initiates appropriate actions such as:
|
||||
* - Navigation to sub-menus (Settings, Light Control, etc.)
|
||||
* - Direct feature activation
|
||||
* - System operations
|
||||
*
|
||||
*
|
||||
* The method uses the menu item ID to determine which action to take and
|
||||
* utilizes the callback functions provided in m_options to perform screen
|
||||
* transitions or other application-level operations.
|
||||
*
|
||||
*
|
||||
* @note This method is called by the base Menu class when a button press
|
||||
* occurs on a menu item, after the base class has handled standard
|
||||
* navigation operations.
|
||||
*
|
||||
*
|
||||
* @see Menu::onButtonPressed for the base implementation
|
||||
* @see ButtonType for available button types
|
||||
*/
|
||||
void onButtonPressed(const MenuItem& menuItem, ButtonType button) override;
|
||||
void onButtonPressed(const MenuItem &menuItem, ButtonType button) override;
|
||||
|
||||
/**
|
||||
* @brief Pointer to menu options configuration structure
|
||||
* @details Stores a reference to the menu configuration passed during construction.
|
||||
* This pointer provides access to the display context and callback functions
|
||||
* needed for menu operations, screen transitions, and user interaction handling.
|
||||
*
|
||||
*
|
||||
* The configuration includes:
|
||||
* - Display context for rendering operations
|
||||
* - Screen management callbacks for navigation
|
||||
* - Input handling callbacks for button events
|
||||
*
|
||||
*
|
||||
* @note This pointer is not owned by the MainMenu and must remain valid
|
||||
* throughout the menu's lifetime. It is managed by the application framework.
|
||||
*
|
||||
*
|
||||
* @warning Must not be modified after construction as it may be shared
|
||||
* with other components.
|
||||
*/
|
||||
|
15
firmware/components/insa/include/ui/NightColorSettingsMenu.h
Normal file
15
firmware/components/insa/include/ui/NightColorSettingsMenu.h
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/ColorSettingsMenu.h"
|
||||
|
||||
class NightColorSettingsMenu final : public ColorSettingsMenu
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a NightColorSettingsMenu with the specified options
|
||||
* @param options Pointer to menu configuration options structure
|
||||
* @details Initializes the menu with night color settings options
|
||||
*/
|
||||
explicit NightColorSettingsMenu(menu_options_t *options);
|
||||
};
|
101
firmware/components/insa/src/common/ColorSettingsMenu.cpp
Normal file
101
firmware/components/insa/src/common/ColorSettingsMenu.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "common/ColorSettingsMenu.h"
|
||||
|
||||
#include "led_manager.h"
|
||||
|
||||
namespace ColorSettingsMenuItem
|
||||
{
|
||||
constexpr auto RED = 0;
|
||||
constexpr auto GREEN = 1;
|
||||
constexpr auto BLUE = 2;
|
||||
} // namespace ColorSettingsMenuItem
|
||||
|
||||
ColorSettingsMenu::ColorSettingsMenu(menu_options_t *options, std::string suffix)
|
||||
: Menu(options), m_suffix(std::move(suffix)), m_options(options)
|
||||
{
|
||||
|
||||
std::vector<std::string> values;
|
||||
for (size_t i = 0; i <= 254; i++)
|
||||
{
|
||||
values.emplace_back(std::to_string(i));
|
||||
}
|
||||
|
||||
int red_value = 0;
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
std::string key = ColorSettingsMenuOptions::RED + m_suffix;
|
||||
red_value = m_options->persistenceManager->GetValue(key, red_value);
|
||||
}
|
||||
addSelection(ColorSettingsMenuItem::RED, "Rot", values, red_value);
|
||||
|
||||
int green_value = 0;
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
std::string key = ColorSettingsMenuOptions::GREEN + m_suffix;
|
||||
green_value = m_options->persistenceManager->GetValue(key, green_value);
|
||||
}
|
||||
addSelection(ColorSettingsMenuItem::GREEN, "Gruen", values, green_value);
|
||||
|
||||
int blue_value = 0;
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
std::string key = ColorSettingsMenuOptions::BLUE + m_suffix;
|
||||
blue_value = m_options->persistenceManager->GetValue(key, blue_value);
|
||||
}
|
||||
addSelection(ColorSettingsMenuItem::BLUE, "Blau", values, blue_value);
|
||||
}
|
||||
|
||||
void ColorSettingsMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button)
|
||||
{
|
||||
switch (menuItem.getId())
|
||||
{
|
||||
case ColorSettingsMenuItem::RED:
|
||||
if (button == ButtonType::LEFT || button == ButtonType::RIGHT)
|
||||
{
|
||||
const auto item = switchValue(menuItem, button);
|
||||
const auto value = getItem(item.getId()).getIndex();
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
std::string key = ColorSettingsMenuOptions::RED + m_suffix;
|
||||
m_options->persistenceManager->SetValue(key, value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ColorSettingsMenuItem::GREEN:
|
||||
if (button == ButtonType::LEFT || button == ButtonType::RIGHT)
|
||||
{
|
||||
const auto item = switchValue(menuItem, button);
|
||||
const auto value = getItem(item.getId()).getIndex();
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
std::string key = ColorSettingsMenuOptions::GREEN + m_suffix;
|
||||
m_options->persistenceManager->SetValue(key, value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ColorSettingsMenuItem::BLUE:
|
||||
if (button == ButtonType::LEFT || button == ButtonType::RIGHT)
|
||||
{
|
||||
const auto item = switchValue(menuItem, button);
|
||||
const auto value = getItem(item.getId()).getIndex();
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
std::string key = ColorSettingsMenuOptions::BLUE + m_suffix;
|
||||
m_options->persistenceManager->SetValue(key, value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ColorSettingsMenu::onExit()
|
||||
{
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
m_options->persistenceManager->Save();
|
||||
|
||||
led_event_data_t payload = {.value = 42};
|
||||
send_event(EVENT_LED_REFRESH, &payload);
|
||||
}
|
||||
}
|
@@ -51,19 +51,19 @@ size_t Menu::getItemCount() const
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
void Menu::setItemSize(const size_t size)
|
||||
void Menu::setItemSize(const size_t size, int8_t startIndex)
|
||||
{
|
||||
if ((m_items.size() - 1) < size)
|
||||
{
|
||||
for (size_t i = m_items.size() - 1; i < size; i++)
|
||||
{
|
||||
auto caption = std::string("Bereich ") + std::to_string(i + 1);
|
||||
auto caption = std::string("Bereich ") + std::to_string(i + 1 - startIndex);
|
||||
auto index = 0;
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
constexpr int key_length = 20;
|
||||
char key[key_length] = "";
|
||||
snprintf(key, key_length, "section_%zu", i + 1);
|
||||
snprintf(key, key_length, "section_%zu", i + 1 - startIndex);
|
||||
index = m_options->persistenceManager->GetValue(key, index);
|
||||
}
|
||||
addSelection(i + 1, caption, m_items.at(0).getValues(), index);
|
||||
|
@@ -4,19 +4,19 @@ Widget::Widget(u8g2_t *u8g2) : u8g2(u8g2)
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::enter()
|
||||
void Widget::onEnter()
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::pause()
|
||||
void Widget::onPause()
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::resume()
|
||||
void Widget::onResume()
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::exit()
|
||||
void Widget::onExit()
|
||||
{
|
||||
}
|
||||
|
||||
|
5
firmware/components/insa/src/ui/DayColorSettingsMenu.cpp
Normal file
5
firmware/components/insa/src/ui/DayColorSettingsMenu.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "ui/DayColorSettingsMenu.h"
|
||||
|
||||
DayColorSettingsMenu::DayColorSettingsMenu(menu_options_t *options) : ColorSettingsMenu(options, "day")
|
||||
{
|
||||
}
|
@@ -58,20 +58,19 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
||||
{
|
||||
toggle(menuItem);
|
||||
const auto value = getItem(menuItem.getId()).getValue() == "1";
|
||||
led_event_data_t payload = {.value = 42};
|
||||
if (value)
|
||||
{
|
||||
led_event_data_t payload = {.value = 42};
|
||||
send_event(EVENT_LED_ON, &payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
led_event_data_t payload = {.value = 0};
|
||||
send_event(EVENT_LED_OFF, &payload);
|
||||
}
|
||||
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
m_options->persistenceManager->SetValue(LightMenuOptions::LIGHT_ACTIVE, value);
|
||||
m_options->persistenceManager->Save();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -83,14 +82,14 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
||||
if (button == ButtonType::LEFT || button == ButtonType::RIGHT)
|
||||
{
|
||||
const auto value = getItem(item.getId()).getIndex();
|
||||
led_event_data_t payload = {.value = value};
|
||||
send_event(EVENT_LED_DAY + value, &payload);
|
||||
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
m_options->persistenceManager->SetValue(LightMenuOptions::LIGHT_MODE, value);
|
||||
m_options->persistenceManager->Save();
|
||||
}
|
||||
|
||||
led_event_data_t payload = {.value = value};
|
||||
send_event(EVENT_LED_DAY + value, &payload);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -1,13 +1,19 @@
|
||||
#include "ui/LightSettingsMenu.h"
|
||||
|
||||
#include "common/Common.h"
|
||||
#include "ui/DayColorSettingsMenu.h"
|
||||
#include "ui/NightColorSettingsMenu.h"
|
||||
|
||||
/**
|
||||
* @namespace LightSettingsMenuItem
|
||||
* @brief Constants for light settings menu item identifiers
|
||||
*/
|
||||
namespace LightSettingsMenuItem
|
||||
{
|
||||
constexpr uint8_t SECTION_COUNTER = 0; ///< ID for the section counter menu item
|
||||
}
|
||||
constexpr uint8_t RGB_SETTING_DAY = 0;
|
||||
constexpr uint8_t RGB_SETTING_NIGHT = 1;
|
||||
constexpr uint8_t SECTION_COUNTER = 2;
|
||||
} // namespace LightSettingsMenuItem
|
||||
|
||||
std::string LightSettingsMenu::CreateKey(const int index)
|
||||
{
|
||||
@@ -19,6 +25,10 @@ std::string LightSettingsMenu::CreateKey(const int index)
|
||||
|
||||
LightSettingsMenu::LightSettingsMenu(menu_options_t *options) : Menu(options), m_options(options)
|
||||
{
|
||||
addText(LightSettingsMenuItem::RGB_SETTING_DAY, "Tag (Farbe)");
|
||||
addText(LightSettingsMenuItem::RGB_SETTING_NIGHT, "Nacht (Farbe)");
|
||||
|
||||
/*
|
||||
// Create values vector for section counts (1-99)
|
||||
std::vector<std::string> values;
|
||||
for (size_t i = 1; i <= 99; i++)
|
||||
@@ -34,24 +44,59 @@ LightSettingsMenu::LightSettingsMenu(menu_options_t *options) : Menu(options), m
|
||||
}
|
||||
addSelection(LightSettingsMenuItem::SECTION_COUNTER, "Sektionen", values, value);
|
||||
|
||||
setItemSize(std::stoull(getItem(0).getValue()));
|
||||
setItemSize(std::stoull(getItem(LightSettingsMenuItem::SECTION_COUNTER).getValue()),
|
||||
LightSettingsMenuItem::SECTION_COUNTER);
|
||||
*/
|
||||
}
|
||||
|
||||
void LightSettingsMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button)
|
||||
{
|
||||
// Handle value switching for the current menu item
|
||||
switchValue(menuItem, button);
|
||||
std::shared_ptr<Widget> widget;
|
||||
|
||||
// Update the section list size based on the section counter value
|
||||
if (menuItem.getId() == 0)
|
||||
switch (button)
|
||||
{
|
||||
setItemSize(std::stoull(getItem(0).getValue()));
|
||||
}
|
||||
case ButtonType::SELECT:
|
||||
switch (menuItem.getId())
|
||||
{
|
||||
case LightSettingsMenuItem::RGB_SETTING_DAY:
|
||||
widget = std::make_shared<DayColorSettingsMenu>(m_options);
|
||||
break;
|
||||
|
||||
// Persist the changed section values if persistence is available
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
const auto value = getItem(menuItem.getId()).getIndex();
|
||||
m_options->persistenceManager->SetValue(CreateKey(menuItem.getId()), value);
|
||||
case LightSettingsMenuItem::RGB_SETTING_NIGHT:
|
||||
widget = std::make_shared<NightColorSettingsMenu>(m_options);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_options && m_options->pushScreen)
|
||||
{
|
||||
m_options->pushScreen(widget);
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonType::RIGHT:
|
||||
case ButtonType::LEFT:
|
||||
// Handle value switching for the current menu item
|
||||
switchValue(menuItem, button);
|
||||
|
||||
// Update the section list size based on the section counter value
|
||||
if (menuItem.getId() == LightSettingsMenuItem::SECTION_COUNTER)
|
||||
{
|
||||
setItemSize(std::stoull(getItem(LightSettingsMenuItem::SECTION_COUNTER).getValue()),
|
||||
LightSettingsMenuItem::SECTION_COUNTER);
|
||||
}
|
||||
|
||||
// Persist the changed section values if persistence is available
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
const auto value = getItem(menuItem.getId()).getIndex();
|
||||
m_options->persistenceManager->SetValue(CreateKey(menuItem.getId()), value);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,5 @@
|
||||
#include "ui/NightColorSettingsMenu.h"
|
||||
|
||||
NightColorSettingsMenu::NightColorSettingsMenu(menu_options_t *options) : ColorSettingsMenu(options, "night")
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user