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:
2025-09-29 23:15:06 +02:00
parent dc66484f5e
commit 08b0e04584
50 changed files with 14880 additions and 8787 deletions

View File

@@ -113,7 +113,7 @@ static void init_ui(void)
});
u8g2_ClearBuffer(&u8g2);
m_widget->render();
m_widget->Render();
u8g2_SendBuffer(&u8g2);
}
@@ -126,27 +126,27 @@ static void handle_button(uint8_t button)
switch (button)
{
case 1:
m_widget->onButtonClicked(ButtonType::UP);
m_widget->OnButtonClicked(ButtonType::UP);
break;
case 3:
m_widget->onButtonClicked(ButtonType::LEFT);
m_widget->OnButtonClicked(ButtonType::LEFT);
break;
case 5:
m_widget->onButtonClicked(ButtonType::RIGHT);
m_widget->OnButtonClicked(ButtonType::RIGHT);
break;
case 6:
m_widget->onButtonClicked(ButtonType::DOWN);
m_widget->OnButtonClicked(ButtonType::DOWN);
break;
case 16:
m_widget->onButtonClicked(ButtonType::BACK);
m_widget->OnButtonClicked(ButtonType::BACK);
break;
case 18:
m_widget->onButtonClicked(ButtonType::SELECT);
m_widget->OnButtonClicked(ButtonType::SELECT);
break;
default:
@@ -160,8 +160,10 @@ void app_task(void *args)
{
if (i2c_bus_scan_and_check() != ESP_OK)
{
led_behavior_t led0_behavior = {
.mode = LED_MODE_BLINK, .color = {.r = 50, .g = 0, .b = 0}, .on_time_ms = 1000, .off_time_ms = 500};
led_behavior_t led0_behavior = {.mode = LED_MODE_BLINK,
.color = {.red = 50, .green = 0, .blue = 0},
.on_time_ms = 1000,
.off_time_ms = 500};
led_status_set_behavior(0, led0_behavior);
ESP_LOGE(TAG, "Display not found on I2C bus");
@@ -192,8 +194,8 @@ void app_task(void *args)
uint64_t deltaMs = delta / 1000;
m_widget->update(deltaMs);
m_widget->render();
m_widget->Update(deltaMs);
m_widget->Render();
m_inactivityTracker->update(deltaMs);
}

View File

@@ -1,11 +1,8 @@
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
void setup_buttons(void);
void cleanup_buttons(void);
#ifdef __cplusplus
}
#endif
#include <sys/cdefs.h>
__BEGIN_DECLS
void setup_buttons(void);
void cleanup_buttons(void);
__END_DECLS

View File

@@ -70,23 +70,18 @@ typedef struct
.reset = U8G2_ESP32_HAL_UNDEFINED, \
.dc = U8G2_ESP32_HAL_UNDEFINED}
#ifdef __cplusplus
extern "C"
{
#endif
/**
* Initialize the HAL with the given configuration.
*
* @see u8g2_esp32_hal_t
* @see U8G2_ESP32_HAL_DEFAULT
*/
void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param);
uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
#ifdef __cplusplus
}
#endif
__BEGIN_DECLS
/**
* Initialize the HAL with the given configuration.
*
* @see u8g2_esp32_hal_t
* @see U8G2_ESP32_HAL_DEFAULT
*/
void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param);
uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
__END_DECLS
#endif /* U8G2_ESP32_HAL_H_ */
#endif
#endif

View File

@@ -8,11 +8,6 @@
#define I2C_MASTER_SDA_PIN ((gpio_num_t)CONFIG_DISPLAY_SDA_PIN)
#define I2C_MASTER_SCL_PIN ((gpio_num_t)CONFIG_DISPLAY_SCL_PIN)
#ifdef __cplusplus
extern "C"
{
#endif
esp_err_t i2c_bus_scan_and_check(void);
#ifdef __cplusplus
}
#endif
__BEGIN_DECLS
esp_err_t i2c_bus_scan_and_check(void);
__END_DECLS

View File

@@ -1,52 +1,45 @@
#include "app_task.h"
#include "ble_manager.h"
#include "esp_event.h"
#include "esp_insights.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "color.h"
#include "hal_esp32/PersistenceManager.h"
#include "led_manager.h"
#include "led_status.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
#include "led_strip_ws2812.h"
#include "simulator.h"
#include "wifi_manager.h"
#include <ble_manager.h>
#include <esp_event.h>
#include <esp_insights.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <nvs_flash.h>
#include <sdkconfig.h>
#ifdef __cplusplus
extern "C"
__BEGIN_DECLS
void app_main(void)
{
#endif
void app_main(void)
// Initialize NVS
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
// Initialize NVS
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ESP_ERROR_CHECK(nvs_flash_erase());
ESP_ERROR_CHECK(nvs_flash_init());
}
led_status_init(CONFIG_STATUS_WLED_PIN);
wled_init();
register_handler();
xTaskCreatePinnedToCore(app_task, "app_task", 4096, NULL, tskIDLE_PRIORITY + 1, NULL, portNUM_PROCESSORS - 1);
xTaskCreatePinnedToCore(simulate, "simulate", 4096, NULL, tskIDLE_PRIORITY + 1, NULL, portNUM_PROCESSORS - 1);
// xTaskCreatePinnedToCore(ble_manager_task, "ble_manager", 4096, NULL, tskIDLE_PRIORITY + 1, NULL,
// portNUM_PROCESSORS - 1);
auto persistence = PersistenceManager();
persistence.Load();
if (persistence.GetValue("light_active", false))
{
led_event_data_t payload = {.value = 42};
send_event(EVENT_LED_ON, &payload);
}
ESP_ERROR_CHECK(nvs_flash_erase());
ESP_ERROR_CHECK(nvs_flash_init());
}
auto persistence = PersistenceManager();
persistence.Load();
led_status_init(CONFIG_STATUS_WLED_PIN);
led_strip_init();
start_simulation_task();
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);
if (persistence.GetValue("light_active", false))
{
led_strip_update(LED_STATE_DAY, rgb_t{});
}
#ifdef __cplusplus
}
#endif
__END_DECLS