add simulation to UI
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
@@ -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);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void initialize_storage();
|
||||
|
||||
void load_file(const char *filename);
|
||||
|
@@ -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{});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user