add simulation to UI

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2025-09-30 21:53:40 +02:00
parent 9ae568c2f4
commit 0f7686d5a5
13 changed files with 113 additions and 131 deletions

View File

@@ -1,8 +1,9 @@
idf_component_register(SRCS
"src/simulator.c"
"src/storage.c"
"src/simulator.cpp"
"src/storage.cpp"
INCLUDE_DIRS "include"
PRIV_REQUIRES
led-manager
persistence-manager
spiffs
)

View File

@@ -9,13 +9,12 @@ typedef struct
int cycle_duration_minutes;
} simulation_config_t;
__BEGIN_DECLS
char *get_time(void);
esp_err_t add_light_item(const char time[5], uint8_t red, uint8_t green, uint8_t blue, uint8_t white,
uint8_t brightness, uint8_t saturation);
void cleanup_light_items(void);
void start_simulate_day(void);
void start_simulate_night(void);
void start_simulation_task(void);
__END_DECLS
void stop_simulation_task(void);
void start_simulation(void);

View File

@@ -1,5 +1,4 @@
#pragma once
void initialize_storage();
void load_file(const char *filename);

View File

@@ -1,6 +1,7 @@
#include "simulator.h"
#include "color.h"
#include "hal_esp32/PersistenceManager.h"
#include "led_strip_ws2812.h"
#include "storage.h"
#include <esp_heap_caps.h>
@@ -332,11 +333,7 @@ void simulate_cycle(void *args)
void start_simulation_task(void)
{
if (simulation_task_handle != NULL)
{
vTaskDelete(simulation_task_handle);
simulation_task_handle = NULL;
}
stop_simulation_task();
simulation_config_t *config =
(simulation_config_t *)heap_caps_malloc(sizeof(simulation_config_t), MALLOC_CAP_SPIRAM);
@@ -355,3 +352,46 @@ void start_simulation_task(void)
heap_caps_free(config);
}
}
void stop_simulation_task(void)
{
if (simulation_task_handle != NULL)
{
vTaskDelete(simulation_task_handle);
simulation_task_handle = NULL;
}
};
void start_simulation(void)
{
stop_simulation_task();
auto persistence = PersistenceManager();
if (persistence.GetValue("light_active", false))
{
int mode = persistence.GetValue("light_mode", 0);
switch (mode)
{
case 0: // Simulation mode
start_simulation_task();
break;
case 1: // Day mode
start_simulate_day();
break;
case 2: // Night mode
start_simulate_night();
break;
default:
ESP_LOGW(TAG, "Unknown light mode: %d", mode);
break;
}
}
else
{
led_strip_update(LED_STATE_OFF, rgb_t{});
}
}