@@ -97,7 +97,6 @@ else ()
|
|||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
ImGui
|
ImGui
|
||||||
insa
|
insa
|
||||||
ruth
|
|
||||||
SDL3::SDL3
|
SDL3::SDL3
|
||||||
SDL3_image::SDL3_image
|
SDL3_image::SDL3_image
|
||||||
SDL3_ttf::SDL3_ttf
|
SDL3_ttf::SDL3_ttf
|
||||||
|
@@ -3,7 +3,6 @@ if (NOT DEFINED ENV{IDF_PATH})
|
|||||||
|
|
||||||
add_subdirectory(imgui)
|
add_subdirectory(imgui)
|
||||||
add_subdirectory(insa)
|
add_subdirectory(insa)
|
||||||
add_subdirectory(ruth)
|
|
||||||
|
|
||||||
target_link_libraries(components INTERFACE ImGui)
|
target_link_libraries(components INTERFACE ImGui)
|
||||||
endif ()
|
endif ()
|
@@ -1,10 +0,0 @@
|
|||||||
if (DEFINED ENV{IDF_PATH})
|
|
||||||
idf_component_register(SRCS
|
|
||||||
bob.c
|
|
||||||
INCLUDE_DIRS "include"
|
|
||||||
PRIV_REQUIRES
|
|
||||||
bt
|
|
||||||
ruth
|
|
||||||
)
|
|
||||||
return()
|
|
||||||
endif ()
|
|
@@ -1,8 +0,0 @@
|
|||||||
#include "bob.h"
|
|
||||||
|
|
||||||
#include "persistence.h"
|
|
||||||
|
|
||||||
void bob_init(void)
|
|
||||||
{
|
|
||||||
persistence_init("system_control");
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
void bob_init(void);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
@@ -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})
|
if (DEFINED ENV{IDF_PATH})
|
||||||
idf_component_register(SRCS
|
idf_component_register(SRCS
|
||||||
src/common/InactivityTracker.cpp
|
${SOURCE_FILES}
|
||||||
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
|
|
||||||
INCLUDE_DIRS "include"
|
INCLUDE_DIRS "include"
|
||||||
PRIV_REQUIRES
|
PRIV_REQUIRES
|
||||||
ruth
|
|
||||||
u8g2
|
u8g2
|
||||||
)
|
)
|
||||||
return()
|
return()
|
||||||
@@ -23,17 +27,7 @@ cmake_minimum_required(VERSION 3.30)
|
|||||||
project(insa)
|
project(insa)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC
|
add_library(${PROJECT_NAME} STATIC
|
||||||
src/common/InactivityTracker.cpp
|
${SOURCE_FILES}
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
@@ -42,5 +36,4 @@ target_include_directories(${PROJECT_NAME} PUBLIC include)
|
|||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
u8g2
|
u8g2
|
||||||
ruth
|
)
|
||||||
)
|
|
@@ -16,7 +16,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// Project-specific headers
|
// Project-specific headers
|
||||||
#include "persistence.h"
|
|
||||||
#include "common/Widget.h"
|
#include "common/Widget.h"
|
||||||
#include "u8g2.h"
|
#include "u8g2.h"
|
||||||
|
|
||||||
@@ -124,6 +123,4 @@ typedef struct
|
|||||||
* @see Widget::onButtonClicked for widget-specific button handling
|
* @see Widget::onButtonClicked for widget-specific button handling
|
||||||
*/
|
*/
|
||||||
std::function<void(ButtonType button)> onButtonClicked;
|
std::function<void(ButtonType button)> onButtonClicked;
|
||||||
|
|
||||||
persistence_t *persistence;
|
|
||||||
} menu_options_t;
|
} menu_options_t;
|
@@ -12,6 +12,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class InactivityTracker
|
* @class InactivityTracker
|
||||||
@@ -21,21 +22,21 @@
|
|||||||
* configured timeout period. It is commonly used for implementing power
|
* configured timeout period. It is commonly used for implementing power
|
||||||
* saving features, automatic screen savers, session timeouts, and other
|
* saving features, automatic screen savers, session timeouts, and other
|
||||||
* time-based system behaviors.
|
* time-based system behaviors.
|
||||||
*
|
*
|
||||||
* The InactivityTracker operates by:
|
* The InactivityTracker operates by:
|
||||||
* - Continuously tracking elapsed time since the last user activity
|
* - Continuously tracking elapsed time since the last user activity
|
||||||
* - Comparing elapsed time against a configurable timeout threshold
|
* - Comparing elapsed time against a configurable timeout threshold
|
||||||
* - Executing a callback function when the timeout is reached
|
* - Executing a callback function when the timeout is reached
|
||||||
* - Providing methods to reset the timer when activity is detected
|
* - Providing methods to reset the timer when activity is detected
|
||||||
* - Supporting enable/disable functionality for dynamic control
|
* - Supporting enable/disable functionality for dynamic control
|
||||||
*
|
*
|
||||||
* Key features include:
|
* Key features include:
|
||||||
* - Configurable timeout duration in milliseconds
|
* - Configurable timeout duration in milliseconds
|
||||||
* - Custom callback function execution on timeout
|
* - Custom callback function execution on timeout
|
||||||
* - Activity reset capability for responsive user interaction
|
* - Activity reset capability for responsive user interaction
|
||||||
* - Enable/disable control for conditional monitoring
|
* - Enable/disable control for conditional monitoring
|
||||||
* - High-resolution timing support using 64-bit millisecond precision
|
* - High-resolution timing support using 64-bit millisecond precision
|
||||||
*
|
*
|
||||||
* Common use cases:
|
* Common use cases:
|
||||||
* - Screen saver activation after idle periods
|
* - Screen saver activation after idle periods
|
||||||
* - Automatic screen dimming or shutdown
|
* - Automatic screen dimming or shutdown
|
||||||
@@ -43,14 +44,14 @@
|
|||||||
* - Power management and battery conservation
|
* - Power management and battery conservation
|
||||||
* - User interface state transitions
|
* - User interface state transitions
|
||||||
* - Security lockout after inactivity
|
* - Security lockout after inactivity
|
||||||
*
|
*
|
||||||
* The class is designed to be lightweight and efficient, suitable for
|
* The class is designed to be lightweight and efficient, suitable for
|
||||||
* real-time applications where precise timing and minimal overhead are important.
|
* real-time applications where precise timing and minimal overhead are important.
|
||||||
*
|
*
|
||||||
* @note This class requires regular update calls to function properly.
|
* @note This class requires regular update calls to function properly.
|
||||||
* @note The timeout callback is executed once per timeout period and will
|
* @note The timeout callback is executed once per timeout period and will
|
||||||
* not repeat until the tracker is reset and times out again.
|
* not repeat until the tracker is reset and times out again.
|
||||||
*
|
*
|
||||||
* @see Widget for integration with UI components
|
* @see Widget for integration with UI components
|
||||||
* @see Menu for menu timeout implementations
|
* @see Menu for menu timeout implementations
|
||||||
*/
|
*/
|
||||||
@@ -61,15 +62,15 @@ class InactivityTracker
|
|||||||
* @brief Constructs an InactivityTracker with specified timeout and callback
|
* @brief Constructs an InactivityTracker with specified timeout and callback
|
||||||
* @param timeoutMs Timeout duration in milliseconds before triggering callback
|
* @param timeoutMs Timeout duration in milliseconds before triggering callback
|
||||||
* @param onTimeout Callback function to execute when timeout is reached
|
* @param onTimeout Callback function to execute when timeout is reached
|
||||||
*
|
*
|
||||||
* @pre timeoutMs must be greater than 0 for meaningful timeout behavior
|
* @pre timeoutMs must be greater than 0 for meaningful timeout behavior
|
||||||
* @pre onTimeout must be a valid callable function object
|
* @pre onTimeout must be a valid callable function object
|
||||||
* @post InactivityTracker is initialized, enabled, and ready for activity monitoring
|
* @post InactivityTracker is initialized, enabled, and ready for activity monitoring
|
||||||
*
|
*
|
||||||
* @details The constructor initializes the inactivity tracker with the specified
|
* @details The constructor initializes the inactivity tracker with the specified
|
||||||
* timeout duration and callback function. The tracker starts in an enabled
|
* timeout duration and callback function. The tracker starts in an enabled
|
||||||
* state with zero elapsed time, ready to begin monitoring user activity.
|
* state with zero elapsed time, ready to begin monitoring user activity.
|
||||||
*
|
*
|
||||||
* The timeout callback function can perform any necessary actions when inactivity
|
* The timeout callback function can perform any necessary actions when inactivity
|
||||||
* is detected, such as:
|
* is detected, such as:
|
||||||
* - Activating screen savers or power saving modes
|
* - Activating screen savers or power saving modes
|
||||||
@@ -77,11 +78,11 @@ class InactivityTracker
|
|||||||
* - Logging inactivity events
|
* - Logging inactivity events
|
||||||
* - Triggering security lockouts
|
* - Triggering security lockouts
|
||||||
* - Initiating automatic save operations
|
* - Initiating automatic save operations
|
||||||
*
|
*
|
||||||
* @note The tracker begins monitoring immediately upon construction.
|
* @note The tracker begins monitoring immediately upon construction.
|
||||||
* @note The callback function should be lightweight to avoid blocking
|
* @note The callback function should be lightweight to avoid blocking
|
||||||
* the main application thread during timeout processing.
|
* the main application thread during timeout processing.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
* @code
|
* @code
|
||||||
* auto tracker = InactivityTracker(30000, []() {
|
* auto tracker = InactivityTracker(30000, []() {
|
||||||
@@ -95,23 +96,23 @@ class InactivityTracker
|
|||||||
/**
|
/**
|
||||||
* @brief Updates the inactivity timer and checks for timeout conditions
|
* @brief Updates the inactivity timer and checks for timeout conditions
|
||||||
* @param dt Delta time in milliseconds since the last update call
|
* @param dt Delta time in milliseconds since the last update call
|
||||||
*
|
*
|
||||||
* @details This method must be called regularly (typically every frame) to
|
* @details This method must be called regularly (typically every frame) to
|
||||||
* maintain accurate timing and timeout detection. It increments the
|
* maintain accurate timing and timeout detection. It increments the
|
||||||
* elapsed time counter and triggers the timeout callback when the
|
* elapsed time counter and triggers the timeout callback when the
|
||||||
* configured timeout duration is reached.
|
* configured timeout duration is reached.
|
||||||
*
|
*
|
||||||
* The update process:
|
* The update process:
|
||||||
* - Adds the delta time to the elapsed time counter (if enabled)
|
* - Adds the delta time to the elapsed time counter (if enabled)
|
||||||
* - Compares elapsed time against the configured timeout threshold
|
* - Compares elapsed time against the configured timeout threshold
|
||||||
* - Executes the timeout callback if the threshold is exceeded
|
* - Executes the timeout callback if the threshold is exceeded
|
||||||
* - Continues monitoring until reset or disabled
|
* - Continues monitoring until reset or disabled
|
||||||
*
|
*
|
||||||
* @note This method should be called consistently from the main application
|
* @note This method should be called consistently from the main application
|
||||||
* loop to ensure accurate timing behavior.
|
* loop to ensure accurate timing behavior.
|
||||||
* @note The timeout callback is executed only once per timeout period.
|
* @note The timeout callback is executed only once per timeout period.
|
||||||
* @note If the tracker is disabled, elapsed time is not updated.
|
* @note If the tracker is disabled, elapsed time is not updated.
|
||||||
*
|
*
|
||||||
* @see reset() to restart the inactivity timer
|
* @see reset() to restart the inactivity timer
|
||||||
* @see setEnabled() to control monitoring state
|
* @see setEnabled() to control monitoring state
|
||||||
*/
|
*/
|
||||||
@@ -119,27 +120,27 @@ class InactivityTracker
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resets the inactivity timer to indicate recent user activity
|
* @brief Resets the inactivity timer to indicate recent user activity
|
||||||
*
|
*
|
||||||
* @details This method should be called whenever user activity is detected
|
* @details This method should be called whenever user activity is detected
|
||||||
* to restart the inactivity timeout period. It resets the elapsed
|
* to restart the inactivity timeout period. It resets the elapsed
|
||||||
* time counter to zero, effectively extending the timeout deadline
|
* time counter to zero, effectively extending the timeout deadline
|
||||||
* and preventing timeout callback execution until the full timeout
|
* and preventing timeout callback execution until the full timeout
|
||||||
* duration elapses again without further resets.
|
* duration elapses again without further resets.
|
||||||
*
|
*
|
||||||
* Common scenarios for calling reset():
|
* Common scenarios for calling reset():
|
||||||
* - Button presses or key events
|
* - Button presses or key events
|
||||||
* - Mouse movement or touch input
|
* - Mouse movement or touch input
|
||||||
* - Menu navigation or selection actions
|
* - Menu navigation or selection actions
|
||||||
* - Any user interface interaction
|
* - Any user interface interaction
|
||||||
* - System activity that should extend the timeout
|
* - System activity that should extend the timeout
|
||||||
*
|
*
|
||||||
* @post Elapsed time is reset to zero, restarting the timeout period
|
* @post Elapsed time is reset to zero, restarting the timeout period
|
||||||
*
|
*
|
||||||
* @note This method can be called at any time, even when the tracker
|
* @note This method can be called at any time, even when the tracker
|
||||||
* is disabled, to prepare for future monitoring.
|
* is disabled, to prepare for future monitoring.
|
||||||
* @note Frequent reset calls from active user interaction will prevent
|
* @note Frequent reset calls from active user interaction will prevent
|
||||||
* timeout callback execution, which is the intended behavior.
|
* timeout callback execution, which is the intended behavior.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
* @code
|
* @code
|
||||||
* void onButtonPress() {
|
* void onButtonPress() {
|
||||||
@@ -153,29 +154,29 @@ class InactivityTracker
|
|||||||
/**
|
/**
|
||||||
* @brief Enables or disables inactivity monitoring
|
* @brief Enables or disables inactivity monitoring
|
||||||
* @param enabled True to enable monitoring, false to disable
|
* @param enabled True to enable monitoring, false to disable
|
||||||
*
|
*
|
||||||
* @details This method controls whether the inactivity tracker actively
|
* @details This method controls whether the inactivity tracker actively
|
||||||
* monitors for timeouts. When disabled, the elapsed time counter
|
* monitors for timeouts. When disabled, the elapsed time counter
|
||||||
* is not updated during update() calls, effectively pausing the
|
* is not updated during update() calls, effectively pausing the
|
||||||
* timeout detection without losing the current elapsed time state.
|
* timeout detection without losing the current elapsed time state.
|
||||||
*
|
*
|
||||||
* Use cases for disabling:
|
* Use cases for disabling:
|
||||||
* - Temporary suspension during system operations
|
* - Temporary suspension during system operations
|
||||||
* - Context-sensitive monitoring (disable in certain application states)
|
* - Context-sensitive monitoring (disable in certain application states)
|
||||||
* - Power management control (disable during low-power modes)
|
* - Power management control (disable during low-power modes)
|
||||||
* - User preference settings (allow users to disable timeouts)
|
* - User preference settings (allow users to disable timeouts)
|
||||||
* - Development and debugging (disable for testing)
|
* - Development and debugging (disable for testing)
|
||||||
*
|
*
|
||||||
* When re-enabled, monitoring resumes from the current elapsed time state,
|
* When re-enabled, monitoring resumes from the current elapsed time state,
|
||||||
* allowing for seamless pause/resume functionality.
|
* allowing for seamless pause/resume functionality.
|
||||||
*
|
*
|
||||||
* @post Monitoring state is updated according to the enabled parameter
|
* @post Monitoring state is updated according to the enabled parameter
|
||||||
*
|
*
|
||||||
* @note Disabling the tracker does not reset the elapsed time counter.
|
* @note Disabling the tracker does not reset the elapsed time counter.
|
||||||
* @note The timeout callback will not be executed while disabled, even
|
* @note The timeout callback will not be executed while disabled, even
|
||||||
* if the timeout threshold would otherwise be exceeded.
|
* if the timeout threshold would otherwise be exceeded.
|
||||||
* @note Enabling/disabling can be done at any time during operation.
|
* @note Enabling/disabling can be done at any time during operation.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
* @code
|
* @code
|
||||||
* tracker.setEnabled(false); // Pause monitoring during critical operation
|
* tracker.setEnabled(false); // Pause monitoring during critical operation
|
||||||
@@ -186,8 +187,8 @@ class InactivityTracker
|
|||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t m_timeoutMs; ///< Timeout duration in milliseconds before callback execution
|
uint64_t m_timeoutMs; ///< Timeout duration in milliseconds before callback execution
|
||||||
uint64_t m_elapsedTime; ///< Current elapsed time since last reset in milliseconds
|
uint64_t m_elapsedTime; ///< Current elapsed time since last reset in milliseconds
|
||||||
bool m_enabled; ///< Flag indicating whether monitoring is currently active
|
bool m_enabled; ///< Flag indicating whether monitoring is currently active
|
||||||
std::function<void()> m_onTimeout; ///< Callback function executed when timeout threshold is reached
|
std::function<void()> m_onTimeout; ///< Callback function executed when timeout threshold is reached
|
||||||
};
|
};
|
@@ -30,7 +30,6 @@ LightMenu::LightMenu(menu_options_t *options) : Menu(options), m_options(options
|
|||||||
|
|
||||||
void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button)
|
void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button)
|
||||||
{
|
{
|
||||||
MenuItem item = menuItem;
|
|
||||||
std::shared_ptr<Widget> widget;
|
std::shared_ptr<Widget> widget;
|
||||||
|
|
||||||
// Handle different menu items based on their ID
|
// Handle different menu items based on their ID
|
||||||
@@ -42,25 +41,12 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
|||||||
{
|
{
|
||||||
toggle(menuItem);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LightMenuItem::MODE: {
|
case LightMenuItem::MODE: {
|
||||||
// Switch between day/night modes using left/right buttons
|
// Switch between day/night modes using left/right buttons
|
||||||
item = switchValue(menuItem, button);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,12 +31,4 @@ void LightSettingsMenu::onButtonPressed(const MenuItem &menuItem, const ButtonTy
|
|||||||
|
|
||||||
// Update the section list size based on the section counter value
|
// Update the section list size based on the section counter value
|
||||||
setItemSize(std::stoull(getItem(0).getValue()));
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -1,20 +0,0 @@
|
|||||||
if (DEFINED ENV{IDF_PATH})
|
|
||||||
idf_component_register(SRCS
|
|
||||||
espressif/persistence.c
|
|
||||||
INCLUDE_DIRS "include"
|
|
||||||
PRIV_REQUIRES
|
|
||||||
nvs_flash
|
|
||||||
)
|
|
||||||
return()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.30)
|
|
||||||
project(ruth)
|
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC
|
|
||||||
persistence.c
|
|
||||||
)
|
|
||||||
|
|
||||||
include_directories(include)
|
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
|
@@ -1,116 +0,0 @@
|
|||||||
#include "persistence.h"
|
|
||||||
|
|
||||||
#include "esp_err.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_mac.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
#include "nvs_flash.h"
|
|
||||||
|
|
||||||
static const char *TAG = "persistence";
|
|
||||||
|
|
||||||
static nvs_handle_t persistence_handle;
|
|
||||||
static SemaphoreHandle_t persistence_mutex;
|
|
||||||
|
|
||||||
void *persistence_init(const char *namespace_name)
|
|
||||||
{
|
|
||||||
esp_err_t ret = nvs_flash_init();
|
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
|
||||||
{
|
|
||||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
||||||
ret = nvs_flash_init();
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(ret);
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(nvs_open(namespace_name, NVS_READWRITE, &persistence_handle));
|
|
||||||
|
|
||||||
persistence_mutex = xSemaphoreCreateMutex();
|
|
||||||
if (persistence_mutex == NULL)
|
|
||||||
{
|
|
||||||
ESP_LOGE(TAG, "Failed to create mutex");
|
|
||||||
}
|
|
||||||
return &persistence_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void persistence_save(persistence_value_t value_type, const char *key, const void *value)
|
|
||||||
{
|
|
||||||
if (persistence_mutex != NULL)
|
|
||||||
{
|
|
||||||
if (xSemaphoreTake(persistence_mutex, portMAX_DELAY) == pdTRUE)
|
|
||||||
{
|
|
||||||
esp_err_t err = ESP_ERR_INVALID_ARG;
|
|
||||||
|
|
||||||
switch (value_type)
|
|
||||||
{
|
|
||||||
case VALUE_TYPE_STRING:
|
|
||||||
err = nvs_set_str(persistence_handle, key, (char *)value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VALUE_TYPE_INT32:
|
|
||||||
err = nvs_set_i32(persistence_handle, key, *(int32_t *)value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ESP_LOGE(TAG, "Unsupported value type");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err == ESP_OK)
|
|
||||||
{
|
|
||||||
ESP_ERROR_CHECK(nvs_commit(persistence_handle));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ESP_LOGE(TAG, "Error saving key %s: %s", key, esp_err_to_name(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
xSemaphoreGive(persistence_mutex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void *persistence_load(persistence_value_t value_type, const char *key, void *out)
|
|
||||||
{
|
|
||||||
if (persistence_mutex != NULL)
|
|
||||||
{
|
|
||||||
if (xSemaphoreTake(persistence_mutex, portMAX_DELAY) == pdTRUE)
|
|
||||||
{
|
|
||||||
esp_err_t err = ESP_ERR_INVALID_ARG;
|
|
||||||
|
|
||||||
switch (value_type)
|
|
||||||
{
|
|
||||||
case VALUE_TYPE_STRING:
|
|
||||||
err = nvs_get_str(persistence_handle, key, (char *)out, NULL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VALUE_TYPE_INT32:
|
|
||||||
err = nvs_get_i32(persistence_handle, key, (int32_t *)out);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ESP_LOGE(TAG, "Unsupported value type");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err != ESP_OK)
|
|
||||||
{
|
|
||||||
ESP_LOGE(TAG, "Error loading key %s: %s", key, esp_err_to_name(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
xSemaphoreGive(persistence_mutex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void persistence_deinit()
|
|
||||||
{
|
|
||||||
if (persistence_mutex != NULL)
|
|
||||||
{
|
|
||||||
vSemaphoreDelete(persistence_mutex);
|
|
||||||
persistence_mutex = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
nvs_close(persistence_handle);
|
|
||||||
}
|
|
@@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
VALUE_TYPE_STRING,
|
|
||||||
VALUE_TYPE_INT32,
|
|
||||||
} persistence_value_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
void *handle;
|
|
||||||
void (*save)(persistence_value_t value_type, const char *key, const void *value);
|
|
||||||
} persistence_t;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
void *persistence_init(const char *namespace_name);
|
|
||||||
void persistence_save(persistence_value_t value_type, const char *key, const void *value);
|
|
||||||
void *persistence_load(persistence_value_t value_type, const char *key, void *out);
|
|
||||||
void persistence_deinit();
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
@@ -1,32 +0,0 @@
|
|||||||
#include "persistence.h"
|
|
||||||
#include "stddef.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void *persistence_init(const char *namespace_name)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void persistence_save(const persistence_value_t value_type, const char *key, const void *value)
|
|
||||||
{
|
|
||||||
printf("Key: %s - ", key);
|
|
||||||
switch (value_type)
|
|
||||||
{
|
|
||||||
case VALUE_TYPE_STRING:
|
|
||||||
printf("Value (s): %s\n", (char *)value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VALUE_TYPE_INT32:
|
|
||||||
printf("Value (i): %d\n", *(int32_t *)value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void *persistence_load(persistence_value_t value_type, const char *key, void *out)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void persistence_deinit()
|
|
||||||
{
|
|
||||||
}
|
|
@@ -5,9 +5,7 @@ idf_component_register(SRCS
|
|||||||
"hal/u8g2_esp32_hal.c"
|
"hal/u8g2_esp32_hal.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES
|
PRIV_REQUIRES
|
||||||
bob
|
|
||||||
insa
|
insa
|
||||||
ruth
|
|
||||||
u8g2
|
u8g2
|
||||||
driver
|
driver
|
||||||
esp_timer
|
esp_timer
|
||||||
|
@@ -99,7 +99,6 @@ static void init_ui(void)
|
|||||||
.pushScreen = [](const std::shared_ptr<Widget> &screen) { pushScreen(screen); },
|
.pushScreen = [](const std::shared_ptr<Widget> &screen) { pushScreen(screen); },
|
||||||
.popScreen = []() { popScreen(); },
|
.popScreen = []() { popScreen(); },
|
||||||
.onButtonClicked = nullptr,
|
.onButtonClicked = nullptr,
|
||||||
.persistence = nullptr,
|
|
||||||
};
|
};
|
||||||
m_widget = std::make_shared<SplashScreen>(&options);
|
m_widget = std::make_shared<SplashScreen>(&options);
|
||||||
m_inactivityTracker = std::make_unique<InactivityTracker>(60000, []() {
|
m_inactivityTracker = std::make_unique<InactivityTracker>(60000, []() {
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
#include "app_task.h"
|
#include "app_task.h"
|
||||||
#include "bob.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
@@ -9,8 +8,6 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
bob_init();
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(app_task, "main_loop", 4096, NULL, tskIDLE_PRIORITY + 1, NULL, portNUM_PROCESSORS - 1);
|
xTaskCreatePinnedToCore(app_task, "main_loop", 4096, NULL, tskIDLE_PRIORITY + 1, NULL, portNUM_PROCESSORS - 1);
|
||||||
}
|
}
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
#include <hal/u8g2_hal_sdl.h>
|
#include <hal/u8g2_hal_sdl.h>
|
||||||
#include <u8g2.h>
|
#include <u8g2.h>
|
||||||
|
|
||||||
#include "persistence.h"
|
|
||||||
#include "MenuOptions.h"
|
#include "MenuOptions.h"
|
||||||
#include "common/InactivityTracker.h"
|
#include "common/InactivityTracker.h"
|
||||||
#include "ui/ScreenSaver.h"
|
#include "ui/ScreenSaver.h"
|
||||||
@@ -72,8 +71,6 @@ Device::Device(void *appstate) : UIWidget(appstate)
|
|||||||
u8g2_Setup_sh1106_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_sdl_hw_spi, u8x8_gpio_and_delay_sdl);
|
u8g2_Setup_sh1106_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_sdl_hw_spi, u8x8_gpio_and_delay_sdl);
|
||||||
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
|
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
|
||||||
|
|
||||||
m_persistence.save = persistence_save;
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
.u8g2 = &u8g2,
|
.u8g2 = &u8g2,
|
||||||
.setScreen = [this](const std::shared_ptr<Widget> &screen) {
|
.setScreen = [this](const std::shared_ptr<Widget> &screen) {
|
||||||
@@ -85,7 +82,6 @@ Device::Device(void *appstate) : UIWidget(appstate)
|
|||||||
.popScreen = [this]() {
|
.popScreen = [this]() {
|
||||||
this->PopScreen();
|
this->PopScreen();
|
||||||
},
|
},
|
||||||
.persistence = &m_persistence,
|
|
||||||
};
|
};
|
||||||
m_widget = std::make_shared<SplashScreen>(&options);
|
m_widget = std::make_shared<SplashScreen>(&options);
|
||||||
m_inactivityTracker = std::make_unique<InactivityTracker>(60000, []() {
|
m_inactivityTracker = std::make_unique<InactivityTracker>(60000, []() {
|
||||||
|
@@ -5,7 +5,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "UIWidget.h"
|
#include "UIWidget.h"
|
||||||
#include "persistence.h"
|
|
||||||
#include "common/Common.h"
|
#include "common/Common.h"
|
||||||
#include "common/Widget.h"
|
#include "common/Widget.h"
|
||||||
#include "model/AppContext.h"
|
#include "model/AppContext.h"
|
||||||
@@ -47,5 +46,4 @@ private:
|
|||||||
std::vector<std::shared_ptr<UIWidget>> m_children{};
|
std::vector<std::shared_ptr<UIWidget>> m_children{};
|
||||||
std::shared_ptr<Widget> m_widget;
|
std::shared_ptr<Widget> m_widget;
|
||||||
std::vector<std::shared_ptr<Widget>> m_history;
|
std::vector<std::shared_ptr<Widget>> m_history;
|
||||||
persistence_t m_persistence{};
|
|
||||||
};
|
};
|
Reference in New Issue
Block a user