some optimizations regarding LED color

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2025-09-20 20:21:42 +02:00
parent 2f03713a4e
commit 273f9491f8
26 changed files with 357 additions and 91 deletions

View File

@@ -30,6 +30,7 @@ uint8_t received_signal;
std::shared_ptr<Widget> m_widget;
std::vector<std::shared_ptr<Widget>> m_history;
std::unique_ptr<InactivityTracker> m_inactivityTracker;
std::shared_ptr<PersistenceManager> m_persistenceManager;
extern QueueHandle_t buttonQueue;
@@ -58,7 +59,7 @@ void setScreen(const std::shared_ptr<Widget> &screen)
m_widget = screen;
m_history.clear();
m_history.emplace_back(m_widget);
m_widget->enter();
m_widget->onEnter();
}
}
@@ -68,10 +69,10 @@ void pushScreen(const std::shared_ptr<Widget> &screen)
{
if (m_widget)
{
m_widget->pause();
m_widget->onPause();
}
m_widget = screen;
m_widget->enter();
m_widget->onEnter();
m_history.emplace_back(m_widget);
}
}
@@ -83,22 +84,27 @@ void popScreen()
m_history.pop_back();
if (m_widget)
{
m_widget->exit();
if (m_persistenceManager != nullptr)
{
m_persistenceManager->Save();
}
m_widget->onExit();
}
m_widget = m_history.back();
m_widget->resume();
m_widget->onResume();
}
}
static void init_ui(void)
{
m_persistenceManager = std::make_shared<PersistenceManager>();
options = {
.u8g2 = &u8g2,
.setScreen = [](const std::shared_ptr<Widget> &screen) { setScreen(screen); },
.pushScreen = [](const std::shared_ptr<Widget> &screen) { pushScreen(screen); },
.popScreen = []() { popScreen(); },
.onButtonClicked = nullptr,
.persistenceManager = std::make_shared<PersistenceManager>(),
.persistenceManager = m_persistenceManager,
};
m_widget = std::make_shared<SplashScreen>(&options);
m_inactivityTracker = std::make_unique<InactivityTracker>(60000, []() {

View File

@@ -36,7 +36,7 @@ static void button_event_cb(void *arg, void *usr_data)
button_user_data_t *data = (button_user_data_t *)usr_data;
uint8_t gpio_num = data->gpio;
ESP_DIAG_EVENT(TAG, "Button pressed on GPIO %d", gpio_num);
ESP_LOGI(TAG, "Button pressed on GPIO %d", gpio_num);
if (xQueueSend(buttonQueue, &gpio_num, 0) != pdTRUE)
{

View File

@@ -5,6 +5,7 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "hal_esp32/PersistenceManager.h"
#include "led_manager.h"
#include "led_status.h"
#include "nvs_flash.h"
@@ -31,12 +32,18 @@ extern "C"
register_handler();
xTaskCreatePinnedToCore(app_task, "main_loop", 4096, NULL, tskIDLE_PRIORITY + 1, NULL, portNUM_PROCESSORS - 1);
xTaskCreatePinnedToCore(app_task, "app_task", 4096, NULL, tskIDLE_PRIORITY + 1, NULL, portNUM_PROCESSORS - 1);
// xTaskCreatePinnedToCore(ble_manager_task, "ble_manager", 4096, NULL, tskIDLE_PRIORITY + 1, NULL,
// portNUM_PROCESSORS - 1);
led_event_data_t payload = {.value = 42};
send_event(EVENT_LED_ON, &payload);
auto persistence = PersistenceManager();
persistence.Load();
if (persistence.GetValue("light_active", false))
{
led_event_data_t payload = {.value = 42};
send_event(EVENT_LED_ON, &payload);
}
}
#ifdef __cplusplus
}