implement new light mode (off/day/night/simulation)
missing: - fully connect it to the ui - setup duration in light settings Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
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
|
||||
@@ -19,4 +15,5 @@ idf_component_register(SRCS
|
||||
u8g2
|
||||
led-manager
|
||||
persistence-manager
|
||||
simulator
|
||||
)
|
||||
|
@@ -1,29 +0,0 @@
|
||||
#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;
|
||||
};
|
@@ -194,9 +194,9 @@ class Menu : public Widget
|
||||
private:
|
||||
MenuItem replaceItem(int index, const MenuItem &item);
|
||||
|
||||
void render() override;
|
||||
void Render() override;
|
||||
|
||||
void onButtonClicked(ButtonType button) override;
|
||||
void OnButtonClicked(ButtonType button) override;
|
||||
|
||||
void onPressedDown();
|
||||
|
||||
|
@@ -22,20 +22,20 @@
|
||||
* that indicates the current position within a scrollable range. The thumb
|
||||
* size is proportional to the visible area relative to the total content,
|
||||
* and its position reflects the current scroll offset.
|
||||
*
|
||||
*
|
||||
* The scrollbar automatically calculates thumb dimensions and position based on
|
||||
* the provided scroll values (current, minimum, maximum). It is designed to be
|
||||
* used alongside scrollable content like menus or lists to provide visual
|
||||
* feedback about scroll state.
|
||||
*
|
||||
*
|
||||
* @note This class is marked as final and cannot be inherited from.
|
||||
*
|
||||
*
|
||||
* @see Widget
|
||||
* @see menu_options_t
|
||||
*/
|
||||
class ScrollBar final : public Widget
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a ScrollBar with specified position and dimensions
|
||||
* @param options Pointer to menu options configuration structure
|
||||
@@ -43,12 +43,12 @@ public:
|
||||
* @param y Y coordinate position of the scrollbar on screen
|
||||
* @param width Width of the scrollbar in pixels
|
||||
* @param height Height of the scrollbar in pixels
|
||||
*
|
||||
*
|
||||
* @pre options must not be nullptr and must remain valid for the scrollbar's lifetime
|
||||
* @pre width and height must be greater than 0
|
||||
* @pre x and y must be valid screen coordinates
|
||||
* @post ScrollBar is initialized with the specified geometry and ready for use
|
||||
*
|
||||
*
|
||||
* @note The scrollbar does not take ownership of the options structure and
|
||||
* assumes it remains valid throughout the scrollbar's lifetime.
|
||||
*/
|
||||
@@ -59,48 +59,48 @@ public:
|
||||
* @details Overrides the base Widget render method to draw the scrollbar track
|
||||
* and thumb. The appearance is determined by the current scroll state
|
||||
* and the menu options configuration.
|
||||
*
|
||||
*
|
||||
* @pre u8g2 display context must be initialized and ready for drawing
|
||||
* @post Scrollbar's visual representation is drawn to the display buffer
|
||||
*
|
||||
*
|
||||
* @note This method is called during each frame's render cycle. The scrollbar
|
||||
* track and thumb are drawn based on the current scroll values set by refresh().
|
||||
*/
|
||||
void render() override;
|
||||
void Render() override;
|
||||
|
||||
/**
|
||||
* @brief Updates the scrollbar state with new scroll values
|
||||
* @param value Current scroll position value (must be between min and max)
|
||||
* @param max Maximum scroll value (total content size)
|
||||
* @param min Minimum scroll value (default: 0, typically the start of content)
|
||||
*
|
||||
*
|
||||
* @pre value must be between min and max (inclusive)
|
||||
* @pre max must be greater than or equal to min
|
||||
* @post Scrollbar thumb position and size are recalculated based on new values
|
||||
*
|
||||
*
|
||||
* @details This method recalculates the thumb's height and vertical position
|
||||
* based on the provided scroll range and current position. The thumb
|
||||
* height represents the proportion of visible content to total content,
|
||||
* while its position represents the current scroll offset within the range.
|
||||
*
|
||||
*
|
||||
* @note Call this method whenever the scroll state changes to keep the
|
||||
* scrollbar visualization synchronized with the actual content position.
|
||||
*/
|
||||
void refresh(size_t value, size_t max, size_t min = 0);
|
||||
|
||||
private:
|
||||
private:
|
||||
// Position and dimensions
|
||||
size_t m_x; ///< X coordinate of the scrollbar's left edge
|
||||
size_t m_y; ///< Y coordinate of the scrollbar's top edge
|
||||
size_t m_width; ///< Width of the scrollbar track in pixels
|
||||
size_t m_height; ///< Height of the scrollbar track in pixels
|
||||
size_t m_x; ///< X coordinate of the scrollbar's left edge
|
||||
size_t m_y; ///< Y coordinate of the scrollbar's top edge
|
||||
size_t m_width; ///< Width of the scrollbar track in pixels
|
||||
size_t m_height; ///< Height of the scrollbar track in pixels
|
||||
|
||||
// Scroll state values
|
||||
size_t m_value; ///< Current scroll position within the range [m_min, m_max]
|
||||
size_t m_max; ///< Maximum scroll value representing the end of content
|
||||
size_t m_min; ///< Minimum scroll value representing the start of content
|
||||
size_t m_value; ///< Current scroll position within the range [m_min, m_max]
|
||||
size_t m_max; ///< Maximum scroll value representing the end of content
|
||||
size_t m_min; ///< Minimum scroll value representing the start of content
|
||||
|
||||
// Calculated thumb properties (updated by refresh())
|
||||
size_t m_thumbHeight; ///< Calculated height of the scroll thumb in pixels
|
||||
size_t m_thumbY; ///< Calculated Y position of the scroll thumb relative to track
|
||||
size_t m_thumbHeight; ///< Calculated height of the scroll thumb in pixels
|
||||
size_t m_thumbY; ///< Calculated Y position of the scroll thumb relative to track
|
||||
};
|
@@ -117,7 +117,7 @@ class Widget
|
||||
* @note Override this method in derived classes to implement time-based behavior
|
||||
* such as animations, blinking effects, or timeout handling.
|
||||
*/
|
||||
virtual void update(uint64_t dt);
|
||||
virtual void Update(uint64_t dt);
|
||||
|
||||
/**
|
||||
* @brief Renders the widget to the display
|
||||
@@ -133,7 +133,7 @@ class Widget
|
||||
* Derived classes should use the u8g2 member variable to perform
|
||||
* drawing operations.
|
||||
*/
|
||||
virtual void render();
|
||||
virtual void Render();
|
||||
|
||||
/**
|
||||
* @brief Handles button press events
|
||||
@@ -148,7 +148,7 @@ class Widget
|
||||
*
|
||||
* @see ButtonType for available button types
|
||||
*/
|
||||
virtual void onButtonClicked(ButtonType button);
|
||||
virtual void OnButtonClicked(ButtonType button);
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@@ -21,9 +21,9 @@ class ClockScreenSaver final : public Widget
|
||||
{
|
||||
public:
|
||||
explicit ClockScreenSaver(menu_options_t *options);
|
||||
void update(uint64_t dt) override;
|
||||
void render() override;
|
||||
void onButtonClicked(ButtonType button) override;
|
||||
void Update(uint64_t dt) override;
|
||||
void Render() override;
|
||||
void OnButtonClicked(ButtonType button) override;
|
||||
|
||||
private:
|
||||
static constexpr int MOVE_INTERVAL = 50; // milliseconds between movements
|
||||
|
@@ -1,14 +0,0 @@
|
||||
#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);
|
||||
};
|
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Menu.h"
|
||||
|
||||
/**
|
||||
* @class LightSettingsMenu
|
||||
* @brief Menu for configuring light system settings including sections and LED parameters
|
||||
* @details This menu extends the base Menu class to provide specialized functionality
|
||||
* for managing light system configurations. It handles dynamic section management
|
||||
* and provides persistence for user settings.
|
||||
*/
|
||||
class LightSettingsMenu final : public Menu
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a LightSettingsMenu with the specified options
|
||||
* @param options Pointer to menu configuration options structure
|
||||
* @details Initializes the menu with section counter and default section settings
|
||||
*/
|
||||
explicit LightSettingsMenu(menu_options_t *options);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Handles button press events for light settings menu items
|
||||
* @param menuItem The menu item that received the button press
|
||||
* @param button The type of button that was pressed
|
||||
* @details Manages value switching, dynamic section list updates, and
|
||||
* persistence of section values when settings are modified
|
||||
*/
|
||||
void onButtonPressed(const MenuItem& menuItem, ButtonType button) override;
|
||||
|
||||
static std::string CreateKey(int index);
|
||||
|
||||
menu_options_t *m_options; ///< Pointer to menu configuration options
|
||||
};
|
@@ -1,15 +0,0 @@
|
||||
|
||||
#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);
|
||||
};
|
@@ -23,9 +23,9 @@ class ScreenSaver final : public Widget
|
||||
{
|
||||
public:
|
||||
explicit ScreenSaver(menu_options_t *options);
|
||||
void update(uint64_t dt) override;
|
||||
void render() override;
|
||||
void onButtonClicked(ButtonType button) override;
|
||||
void Update(uint64_t dt) override;
|
||||
void Render() override;
|
||||
void OnButtonClicked(ButtonType button) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@@ -21,71 +21,71 @@
|
||||
* displayed when the application starts. It serves multiple purposes including
|
||||
* brand presentation, system initialization feedback, and smooth transition
|
||||
* preparation to the main application interface.
|
||||
*
|
||||
*
|
||||
* The SplashScreen class provides:
|
||||
* - Brand identity display (logos, company information, product name)
|
||||
* - System initialization progress indication
|
||||
* - Smooth animations and visual effects for professional appearance
|
||||
* - Automatic transition timing to main menu after initialization
|
||||
* - Error indication if initialization fails
|
||||
*
|
||||
*
|
||||
* Key features include:
|
||||
* - Time-based automatic progression to main menu
|
||||
* - Animated elements (fade-in effects, progress indicators)
|
||||
* - Version information display
|
||||
* - Loading status messages
|
||||
* - Graceful handling of initialization delays
|
||||
*
|
||||
*
|
||||
* The splash screen typically displays for a minimum duration to ensure users
|
||||
* can read branding information, even if system initialization completes quickly.
|
||||
* It automatically transitions to the main menu once both the minimum display
|
||||
* time and system initialization are complete.
|
||||
*
|
||||
*
|
||||
* @note This class is marked as final and cannot be inherited from.
|
||||
* @note The splash screen does not handle user input - it operates on timing
|
||||
* and system state rather than user interaction.
|
||||
*
|
||||
*
|
||||
* @see Widget for base widget functionality
|
||||
* @see menu_options_t for configuration structure
|
||||
* @see MainMenu for the target transition screen
|
||||
*/
|
||||
class SplashScreen final : public Widget
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs the splash screen with specified configuration
|
||||
* @param options Pointer to menu options configuration structure
|
||||
*
|
||||
*
|
||||
* @pre options must not be nullptr and must remain valid for the splash screen's lifetime
|
||||
* @pre options->u8g2 must be initialized and ready for graphics operations
|
||||
* @pre Screen transition callbacks in options must be properly configured
|
||||
* @post SplashScreen is initialized and ready to display startup sequence
|
||||
*
|
||||
*
|
||||
* @details The constructor initializes the splash screen by:
|
||||
* - Setting up the initial display state and animations
|
||||
* - Preparing branding elements (logos, text, version info)
|
||||
* - Initializing timing controls for minimum display duration
|
||||
* - Configuring transition parameters for smooth progression
|
||||
* - Loading any required graphics resources or assets
|
||||
*
|
||||
*
|
||||
* The splash screen prepares all visual elements during construction to
|
||||
* ensure smooth rendering performance during the critical startup phase.
|
||||
* It also establishes the timing framework for controlling display duration
|
||||
* and transition timing.
|
||||
*
|
||||
*
|
||||
* @note The splash screen does not take ownership of the options structure
|
||||
* and assumes it remains valid throughout the screen's lifetime.
|
||||
* @note Graphics resources are loaded during construction, so any required
|
||||
* assets must be available at initialization time.
|
||||
*
|
||||
*
|
||||
* @see Widget::Widget for base class construction details
|
||||
*/
|
||||
explicit SplashScreen(menu_options_t *options);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Updates the splash screen state, animations, and timing logic
|
||||
* @param dt Delta time in milliseconds since the last update call
|
||||
*
|
||||
*
|
||||
* @details Overrides the base Widget update method to handle splash screen-specific
|
||||
* logic including:
|
||||
* - Animation progression (fade effects, transitions, progress indicators)
|
||||
@@ -93,31 +93,31 @@ public:
|
||||
* - System initialization status monitoring
|
||||
* - Automatic transition preparation to main menu
|
||||
* - Loading progress updates and status message changes
|
||||
*
|
||||
*
|
||||
* The update method manages the splash screen's lifecycle by tracking
|
||||
* elapsed time and system readiness state. It ensures the splash screen
|
||||
* remains visible for a minimum duration while also monitoring system
|
||||
* initialization completion. Once both conditions are met, it initiates
|
||||
* the transition to the main application interface.
|
||||
*
|
||||
*
|
||||
* Animation updates include:
|
||||
* - Fade-in effects for branding elements
|
||||
* - Progress bar or spinner animations
|
||||
* - Text transitions for status messages
|
||||
* - Smooth preparation for screen transition
|
||||
*
|
||||
*
|
||||
* @note This method is called every frame during the splash screen display
|
||||
* and must be efficient to maintain smooth visual presentation.
|
||||
* @note The method automatically handles transition to the main menu when
|
||||
* appropriate, using the callback functions provided in m_options.
|
||||
*
|
||||
*
|
||||
* @see Widget::update for the base update interface
|
||||
*/
|
||||
void update(uint64_t dt) override;
|
||||
|
||||
void Update(uint64_t dt) override;
|
||||
|
||||
/**
|
||||
* @brief Renders the splash screen visual elements to the display
|
||||
*
|
||||
*
|
||||
* @details Overrides the base Widget render method to draw all splash screen
|
||||
* elements including branding, status information, and visual effects.
|
||||
* The rendering includes:
|
||||
@@ -126,50 +126,50 @@ public:
|
||||
* - Loading progress indicators (progress bars, spinners, etc.)
|
||||
* - Status messages indicating initialization progress
|
||||
* - Background graphics and visual effects
|
||||
*
|
||||
*
|
||||
* The render method creates a professional, polished appearance that
|
||||
* reinforces brand identity while providing useful feedback about the
|
||||
* application startup process. All elements are positioned and styled
|
||||
* to create a cohesive, attractive presentation.
|
||||
*
|
||||
*
|
||||
* Rendering features include:
|
||||
* - Centered layout with balanced visual hierarchy
|
||||
* - Smooth animations and transitions
|
||||
* - Consistent typography and color scheme
|
||||
* - Progress feedback elements
|
||||
* - Error indication if initialization problems occur
|
||||
*
|
||||
*
|
||||
* @pre u8g2 display context must be initialized and ready for drawing
|
||||
* @post All splash screen visual elements are drawn to the display buffer
|
||||
*
|
||||
*
|
||||
* @note This method is called every frame and must be efficient to maintain
|
||||
* smooth visual presentation during the startup sequence.
|
||||
* @note The visual design should be consistent with the overall application
|
||||
* theme and branding guidelines.
|
||||
*
|
||||
*
|
||||
* @see Widget::render for the base render interface
|
||||
*/
|
||||
void render() override;
|
||||
void Render() override;
|
||||
|
||||
private:
|
||||
private:
|
||||
/**
|
||||
* @brief Pointer to menu options configuration structure
|
||||
* @details Stores a reference to the menu configuration passed during construction.
|
||||
* This provides access to the display context for rendering operations
|
||||
* and screen transition callbacks for automatic progression to the main menu.
|
||||
*
|
||||
*
|
||||
* The configuration enables:
|
||||
* - Display context (u8g2) for graphics rendering operations
|
||||
* - Screen transition callbacks for automatic progression to main menu
|
||||
* - System integration for initialization status monitoring
|
||||
*
|
||||
*
|
||||
* The splash screen uses the setScreen callback to automatically transition
|
||||
* to the main menu once the startup sequence is complete. This ensures a
|
||||
* seamless user experience from application launch to main interface.
|
||||
*
|
||||
*
|
||||
* @note This pointer is not owned by the SplashScreen and must remain valid
|
||||
* throughout the screen's lifetime. It is managed by the application framework.
|
||||
*
|
||||
*
|
||||
* @warning Must not be modified after construction as it contains critical
|
||||
* system callbacks required for proper application flow.
|
||||
*/
|
||||
|
@@ -1,101 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
}
|
@@ -29,7 +29,7 @@ constexpr int BOTTOM_OFFSET = 10;
|
||||
Menu::Menu(menu_options_t *options) : Widget(options->u8g2), m_options(options)
|
||||
{
|
||||
// Set up button callback using lambda to forward to member function
|
||||
m_options->onButtonClicked = [this](const ButtonType button) { onButtonClicked(button); };
|
||||
m_options->onButtonClicked = [this](const ButtonType button) { OnButtonClicked(button); };
|
||||
}
|
||||
|
||||
Menu::~Menu()
|
||||
@@ -126,7 +126,7 @@ MenuItem Menu::replaceItem(const int index, const MenuItem &item)
|
||||
return item;
|
||||
}
|
||||
|
||||
void Menu::render()
|
||||
void Menu::Render()
|
||||
{
|
||||
// Initialize selection if not set
|
||||
if (m_selected_item >= m_items.size() && !m_items.empty())
|
||||
@@ -232,7 +232,7 @@ void Menu::renderWidget(const MenuItem *item, const uint8_t *font, const int x,
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::onButtonClicked(const ButtonType button)
|
||||
void Menu::OnButtonClicked(const ButtonType button)
|
||||
{
|
||||
// Map button input to navigation functions
|
||||
switch (button)
|
||||
@@ -362,7 +362,7 @@ void Menu::drawScrollBar() const
|
||||
// Create scrollbar instance
|
||||
ScrollBar scrollBar(m_options, u8g2->width - UIConstants::SCROLLBAR_WIDTH, 3, 1, u8g2->height - 6);
|
||||
scrollBar.refresh(m_selected_item, m_items.size());
|
||||
scrollBar.render();
|
||||
scrollBar.Render();
|
||||
}
|
||||
|
||||
void Menu::drawSelectionBox() const
|
||||
|
@@ -7,7 +7,7 @@ ScrollBar::ScrollBar(const menu_options_t *options, const size_t x, const size_t
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollBar::render()
|
||||
void ScrollBar::Render()
|
||||
{
|
||||
if (m_max <= 1)
|
||||
{
|
||||
|
@@ -20,14 +20,14 @@ void Widget::onExit()
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::update(uint64_t dt)
|
||||
void Widget::Update(uint64_t dt)
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::render()
|
||||
void Widget::Render()
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::onButtonClicked(ButtonType button)
|
||||
void Widget::OnButtonClicked(ButtonType button)
|
||||
{
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "ui/ClockScreenSaver.h"
|
||||
#include "simulator.h"
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
@@ -36,17 +37,25 @@ void ClockScreenSaver::updateTextDimensions()
|
||||
|
||||
void ClockScreenSaver::getCurrentTimeString(char *buffer, size_t bufferSize) const
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
char *simulated_time = get_time();
|
||||
if (simulated_time != nullptr)
|
||||
{
|
||||
strncpy(buffer, simulated_time, bufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
// Format time as HH:MM:SS
|
||||
strftime(buffer, bufferSize, "%H:%M:%S", timeinfo);
|
||||
// Format time as HH:MM:SS
|
||||
strftime(buffer, bufferSize, "%H:%M:%S", timeinfo);
|
||||
}
|
||||
}
|
||||
|
||||
void ClockScreenSaver::update(const uint64_t dt)
|
||||
void ClockScreenSaver::Update(const uint64_t dt)
|
||||
{
|
||||
m_moveTimer += dt;
|
||||
|
||||
@@ -94,7 +103,7 @@ void ClockScreenSaver::checkBoundaryCollision()
|
||||
}
|
||||
}
|
||||
|
||||
void ClockScreenSaver::render()
|
||||
void ClockScreenSaver::Render()
|
||||
{
|
||||
// Clear screen with a black background
|
||||
u8g2_SetDrawColor(u8g2, 0);
|
||||
@@ -112,7 +121,7 @@ void ClockScreenSaver::render()
|
||||
u8g2_DrawStr(u8g2, m_posX, m_posY, timeBuffer);
|
||||
}
|
||||
|
||||
void ClockScreenSaver::onButtonClicked(ButtonType button)
|
||||
void ClockScreenSaver::OnButtonClicked(ButtonType button)
|
||||
{
|
||||
// Exit screensaver on any button press
|
||||
if (m_options && m_options->popScreen)
|
||||
|
@@ -1,5 +0,0 @@
|
||||
#include "ui/DayColorSettingsMenu.h"
|
||||
|
||||
DayColorSettingsMenu::DayColorSettingsMenu(menu_options_t *options) : ColorSettingsMenu(options, "day")
|
||||
{
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
#include "ui/LightMenu.h"
|
||||
|
||||
#include "led_manager.h"
|
||||
#include "ui/LightSettingsMenu.h"
|
||||
#include "led_strip_ws2812.h"
|
||||
|
||||
/**
|
||||
* @namespace LightMenuItem
|
||||
@@ -9,9 +8,8 @@
|
||||
*/
|
||||
namespace LightMenuItem
|
||||
{
|
||||
constexpr auto ACTIVATE = 0; ///< ID for the light activation toggle
|
||||
constexpr auto MODE = 1; ///< ID for the light mode selection
|
||||
constexpr auto LED_SETTINGS = 2; ///< ID for the LED settings menu item
|
||||
constexpr auto ACTIVATE = 0; ///< ID for the light activation toggle
|
||||
constexpr auto MODE = 1; ///< ID for the light mode selection
|
||||
} // namespace LightMenuItem
|
||||
|
||||
namespace LightMenuOptions
|
||||
@@ -30,19 +28,17 @@ LightMenu::LightMenu(menu_options_t *options) : Menu(options), m_options(options
|
||||
}
|
||||
addToggle(LightMenuItem::ACTIVATE, "Einschalten", active);
|
||||
|
||||
// Create mode selection options (Day/Night modes)
|
||||
std::vector<std::string> values;
|
||||
values.emplace_back("Tag"); // Day mode
|
||||
values.emplace_back("Nacht"); // Night mode
|
||||
// Create mode selection options (Simulation/Day/Night modes)
|
||||
std::vector<std::string> items;
|
||||
items.emplace_back("Simulation"); // Simulation mode
|
||||
items.emplace_back("Tag"); // Day mode
|
||||
items.emplace_back("Nacht"); // Night mode
|
||||
int mode_value = 0;
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
mode_value = m_options->persistenceManager->GetValue(LightMenuOptions::LIGHT_MODE, mode_value);
|
||||
}
|
||||
addSelection(LightMenuItem::MODE, "Modus", values, mode_value);
|
||||
|
||||
// Add menu item for accessing LED settings submenu
|
||||
addText(LightMenuItem::LED_SETTINGS, "Einstellungen");
|
||||
addSelection(LightMenuItem::MODE, "Modus", items, mode_value);
|
||||
}
|
||||
|
||||
void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button)
|
||||
@@ -58,14 +54,13 @@ 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)
|
||||
{
|
||||
send_event(EVENT_LED_ON, &payload);
|
||||
led_strip_update(LED_STATE_DAY, rgb_t{});
|
||||
}
|
||||
else
|
||||
{
|
||||
send_event(EVENT_LED_OFF, &payload);
|
||||
led_strip_update(LED_STATE_OFF, rgb_t{});
|
||||
}
|
||||
|
||||
if (m_options && m_options->persistenceManager)
|
||||
@@ -88,17 +83,7 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
||||
m_options->persistenceManager->Save();
|
||||
}
|
||||
|
||||
led_event_data_t payload = {.value = value};
|
||||
send_event(EVENT_LED_DAY + value, &payload);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case LightMenuItem::LED_SETTINGS: {
|
||||
// Open the LED settings submenu when SELECT is pressed
|
||||
if (button == ButtonType::SELECT)
|
||||
{
|
||||
widget = std::make_shared<LightSettingsMenu>(m_options);
|
||||
led_strip_update(value == 0 ? LED_STATE_DAY : LED_STATE_NIGHT, rgb_t{});
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -113,4 +98,4 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
||||
{
|
||||
m_options->pushScreen(widget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,102 +0,0 @@
|
||||
#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 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)
|
||||
{
|
||||
constexpr int key_length = 20;
|
||||
char key[key_length] = "";
|
||||
snprintf(key, key_length, "section_%d", index);
|
||||
return key;
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
values.emplace_back(std::to_string(i));
|
||||
}
|
||||
|
||||
// Add section counter selection (allows choosing number of sections)
|
||||
auto value = 7;
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
value = m_options->persistenceManager->GetValue(CreateKey(0), value);
|
||||
}
|
||||
addSelection(LightSettingsMenuItem::SECTION_COUNTER, "Sektionen", values, value);
|
||||
|
||||
setItemSize(std::stoull(getItem(LightSettingsMenuItem::SECTION_COUNTER).getValue()),
|
||||
LightSettingsMenuItem::SECTION_COUNTER);
|
||||
*/
|
||||
}
|
||||
|
||||
void LightSettingsMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button)
|
||||
{
|
||||
std::shared_ptr<Widget> widget;
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case ButtonType::SELECT:
|
||||
switch (menuItem.getId())
|
||||
{
|
||||
case LightSettingsMenuItem::RGB_SETTING_DAY:
|
||||
widget = std::make_shared<DayColorSettingsMenu>(m_options);
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
#include "ui/NightColorSettingsMenu.h"
|
||||
|
||||
NightColorSettingsMenu::NightColorSettingsMenu(menu_options_t *options) : ColorSettingsMenu(options, "night")
|
||||
{
|
||||
}
|
@@ -20,7 +20,7 @@ void ScreenSaver::initVehicles()
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSaver::update(const uint64_t dt)
|
||||
void ScreenSaver::Update(const uint64_t dt)
|
||||
{
|
||||
m_animationCounter += dt;
|
||||
m_lastSpawnTime += dt;
|
||||
@@ -214,7 +214,7 @@ ScreenSaver::Direction ScreenSaver::getRandomDirection()
|
||||
return (random() % 2 == 0) ? Direction::LEFT : Direction::RIGHT;
|
||||
}
|
||||
|
||||
void ScreenSaver::render()
|
||||
void ScreenSaver::Render()
|
||||
{
|
||||
// Clear screen with a black background
|
||||
u8g2_SetDrawColor(u8g2, 0);
|
||||
@@ -320,7 +320,7 @@ const unsigned char *ScreenSaver::getVehicleBitmap(const VehicleType type, const
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSaver::onButtonClicked(ButtonType button)
|
||||
void ScreenSaver::OnButtonClicked(ButtonType button)
|
||||
{
|
||||
if (m_options && m_options->popScreen)
|
||||
{
|
||||
|
@@ -8,7 +8,7 @@ SplashScreen::SplashScreen(menu_options_t *options) : Widget(options->u8g2), m_o
|
||||
{
|
||||
}
|
||||
|
||||
void SplashScreen::update(const uint64_t dt)
|
||||
void SplashScreen::Update(const uint64_t dt)
|
||||
{
|
||||
splashTime += dt;
|
||||
if (splashTime > 100)
|
||||
@@ -20,7 +20,7 @@ void SplashScreen::update(const uint64_t dt)
|
||||
}
|
||||
}
|
||||
|
||||
void SplashScreen::render()
|
||||
void SplashScreen::Render()
|
||||
{
|
||||
u8g2_SetFont(u8g2, u8g2_font_DigitalDisco_tr);
|
||||
u8g2_DrawStr(u8g2, 28, u8g2->height / 2 - 10, "HO Anlage");
|
||||
|
Reference in New Issue
Block a user