starting with led-manager as esp32 and native component
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -98,6 +98,7 @@ else ()
|
|||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
ImGui
|
ImGui
|
||||||
insa
|
insa
|
||||||
|
led-manager
|
||||||
SDL3::SDL3
|
SDL3::SDL3
|
||||||
SDL3_image::SDL3_image
|
SDL3_image::SDL3_image
|
||||||
SDL3_ttf::SDL3_ttf
|
SDL3_ttf::SDL3_ttf
|
||||||
|
@@ -19,6 +19,7 @@ if (DEFINED ENV{IDF_PATH})
|
|||||||
INCLUDE_DIRS "include"
|
INCLUDE_DIRS "include"
|
||||||
PRIV_REQUIRES
|
PRIV_REQUIRES
|
||||||
u8g2
|
u8g2
|
||||||
|
led-manager
|
||||||
)
|
)
|
||||||
return()
|
return()
|
||||||
endif ()
|
endif ()
|
||||||
@@ -36,4 +37,5 @@ target_include_directories(${PROJECT_NAME} PUBLIC include)
|
|||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
u8g2
|
u8g2
|
||||||
|
led-manager
|
||||||
)
|
)
|
@@ -1,5 +1,6 @@
|
|||||||
#include "ui/LightMenu.h"
|
#include "ui/LightMenu.h"
|
||||||
|
|
||||||
|
#include "led_manager.h"
|
||||||
#include "ui/LightSettingsMenu.h"
|
#include "ui/LightSettingsMenu.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +18,7 @@ namespace LightMenuOptions
|
|||||||
{
|
{
|
||||||
constexpr std::string LIGHT_ACTIVE = "light_active";
|
constexpr std::string LIGHT_ACTIVE = "light_active";
|
||||||
constexpr std::string LIGHT_MODE = "light_mode";
|
constexpr std::string LIGHT_MODE = "light_mode";
|
||||||
}
|
} // namespace LightMenuOptions
|
||||||
|
|
||||||
LightMenu::LightMenu(menu_options_t *options) : Menu(options), m_options(options)
|
LightMenu::LightMenu(menu_options_t *options) : Menu(options), m_options(options)
|
||||||
{
|
{
|
||||||
@@ -56,6 +57,16 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
|||||||
if (button == ButtonType::SELECT)
|
if (button == ButtonType::SELECT)
|
||||||
{
|
{
|
||||||
toggle(menuItem);
|
toggle(menuItem);
|
||||||
|
if (getItem(menuItem.getId()).getValue() == "1")
|
||||||
|
{
|
||||||
|
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)
|
if (m_options && m_options->persistenceManager)
|
||||||
{
|
{
|
||||||
const auto value = getItem(menuItem.getId()).getValue() == "1";
|
const auto value = getItem(menuItem.getId()).getValue() == "1";
|
||||||
|
21
components/led-manager/CMakeLists.txt
Normal file
21
components/led-manager/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
if (DEFINED ENV{IDF_PATH})
|
||||||
|
idf_component_register(SRCS
|
||||||
|
src/hal_esp32/led_manager.cpp
|
||||||
|
INCLUDE_DIRS "include"
|
||||||
|
PRIV_REQUIRES
|
||||||
|
u8g2
|
||||||
|
esp_event
|
||||||
|
)
|
||||||
|
return()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.30)
|
||||||
|
project(led-manager)
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} STATIC
|
||||||
|
src/hal_native/led_manager.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(include)
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
2
components/led-manager/idf_component.yml
Executable file
2
components/led-manager/idf_component.yml
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
dependencies:
|
||||||
|
espressif/led_strip: '~3.0.1'
|
22
components/led-manager/include/led_manager.h
Normal file
22
components/led-manager/include/led_manager.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
EVENT_LED_ON,
|
||||||
|
EVENT_LED_OFF,
|
||||||
|
EVENT_LED_DAY,
|
||||||
|
EVENT_LED_NIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
} led_event_data_t;
|
||||||
|
|
||||||
|
uint64_t wled_init(void);
|
||||||
|
|
||||||
|
uint64_t register_handler(void);
|
||||||
|
|
||||||
|
uint64_t send_event(uint32_t event, led_event_data_t *payload);
|
92
components/led-manager/src/hal_esp32/led_manager.cpp
Normal file
92
components/led-manager/src/hal_esp32/led_manager.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#include "led_manager.h"
|
||||||
|
|
||||||
|
#include "esp_event.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "led_strip.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
led_strip_handle_t led_strip;
|
||||||
|
|
||||||
|
static const uint32_t value = 5;
|
||||||
|
|
||||||
|
ESP_EVENT_DECLARE_BASE(LED_EVENTS_BASE);
|
||||||
|
ESP_EVENT_DEFINE_BASE(LED_EVENTS_BASE);
|
||||||
|
|
||||||
|
esp_event_loop_handle_t loop_handle;
|
||||||
|
|
||||||
|
const char *TAG = "LED";
|
||||||
|
|
||||||
|
uint64_t wled_init(void)
|
||||||
|
{
|
||||||
|
led_strip_config_t strip_config = {.strip_gpio_num = CONFIG_WLED_DIN_PIN,
|
||||||
|
.max_leds = 64,
|
||||||
|
.led_model = LED_MODEL_WS2812,
|
||||||
|
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_RGB,
|
||||||
|
.flags = {
|
||||||
|
.invert_out = false,
|
||||||
|
}};
|
||||||
|
|
||||||
|
led_strip_rmt_config_t rmt_config = {.clk_src = RMT_CLK_SRC_DEFAULT,
|
||||||
|
.resolution_hz = 0,
|
||||||
|
.mem_block_symbols = 0,
|
||||||
|
.flags = {
|
||||||
|
.with_dma = true,
|
||||||
|
}};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < 64; i++)
|
||||||
|
{
|
||||||
|
led_strip_set_pixel(led_strip, i, 0, 0, 0);
|
||||||
|
}
|
||||||
|
led_strip_refresh(led_strip);
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void event_handler(void *arg, esp_event_base_t base, int32_t id, void *event_data)
|
||||||
|
{
|
||||||
|
if (id == EVENT_LED_ON || id == EVENT_LED_OFF)
|
||||||
|
{
|
||||||
|
auto brightness = (id == EVENT_LED_ON) ? value : 0;
|
||||||
|
for (uint32_t i = 0; i < 64; i++)
|
||||||
|
{
|
||||||
|
led_strip_set_pixel(led_strip, i, brightness, brightness, brightness);
|
||||||
|
}
|
||||||
|
led_strip_refresh(led_strip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t register_handler(void)
|
||||||
|
{
|
||||||
|
esp_event_loop_args_t loop_args = {
|
||||||
|
.queue_size = 2, .task_name = "led_manager", .task_priority = 5, .task_stack_size = 4096, .task_core_id = 1};
|
||||||
|
esp_event_loop_create(&loop_args, &loop_handle);
|
||||||
|
|
||||||
|
esp_event_handler_register_with(loop_handle, LED_EVENTS_BASE, ESP_EVENT_ANY_ID, event_handler, NULL);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t send_event(uint32_t event, led_event_data_t *payload)
|
||||||
|
{
|
||||||
|
if (payload == nullptr)
|
||||||
|
{
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = esp_event_post_to(loop_handle, // Event-Loop Handle
|
||||||
|
LED_EVENTS_BASE, // Event Base
|
||||||
|
event, // Event ID (EVENT_LED_ON, EVENT_LED_OFF, etc.)
|
||||||
|
payload, // Daten-Pointer
|
||||||
|
sizeof(led_event_data_t), // Datengröße
|
||||||
|
portMAX_DELAY // Wartezeit
|
||||||
|
);
|
||||||
|
|
||||||
|
if (err != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE("LED", "Failed to post event: %s", esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
16
components/led-manager/src/hal_native/led_manager.cpp
Normal file
16
components/led-manager/src/hal_native/led_manager.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "led_manager.h"
|
||||||
|
|
||||||
|
uint64_t wled_init(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t register_handler(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t send_event(uint32_t event, led_event_data_t *payload)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -1,14 +1,16 @@
|
|||||||
idf_component_register(SRCS
|
idf_component_register(SRCS
|
||||||
"main.cpp"
|
main.cpp
|
||||||
"app_task.cpp"
|
app_task.cpp
|
||||||
"PersistenceManager.cpp"
|
PersistenceManager.cpp
|
||||||
"button_handling.c"
|
button_handling.c
|
||||||
"hal/u8g2_esp32_hal.c"
|
hal/u8g2_esp32_hal.c
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES
|
PRIV_REQUIRES
|
||||||
insa
|
insa
|
||||||
|
led-manager
|
||||||
u8g2
|
u8g2
|
||||||
driver
|
driver
|
||||||
esp_timer
|
esp_timer
|
||||||
|
esp_event
|
||||||
nvs_flash
|
nvs_flash
|
||||||
)
|
)
|
||||||
|
7
main/Kconfig.projbuild
Normal file
7
main/Kconfig.projbuild
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
menu "Warnemuende Lighthouse"
|
||||||
|
config WLED_DIN_PIN
|
||||||
|
int "WLED Data In Pin"
|
||||||
|
default 14
|
||||||
|
help
|
||||||
|
The number of the WLED data in pin.
|
||||||
|
endmenu
|
@@ -1,5 +1,7 @@
|
|||||||
#include "app_task.h"
|
#include "app_task.h"
|
||||||
|
#include "esp_event.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "led_manager.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -9,6 +11,9 @@ extern "C"
|
|||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
|
||||||
|
wled_init();
|
||||||
|
register_handler();
|
||||||
}
|
}
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user