Compare commits
6 Commits
08b0e04584
...
main
Author | SHA1 | Date | |
---|---|---|---|
c586de76a2
|
|||
4a2d73c686
|
|||
f9010d5491
|
|||
0f7686d5a5
|
|||
9ae568c2f4
|
|||
99aa30c8e5
|
@@ -35,8 +35,11 @@ jobs:
|
||||
with:
|
||||
submodules: "recursive"
|
||||
|
||||
- name: Delete CMakeLists.txt in components (only used for simulator build)
|
||||
run: rm firmware/components/CMakeLists.txt
|
||||
- name: Extract API key
|
||||
env:
|
||||
INSIGHTS_API_KEY: ${{ secrets.INSIGHTS_API_KEY }}
|
||||
run: |
|
||||
echo $INSIGHTS_API_KEY > firmware/components/analytics/insights_api_key.txt
|
||||
|
||||
- name: ESP-IDF build
|
||||
uses: espressif/esp-idf-ci-action@v1
|
@@ -49,7 +49,7 @@
|
||||
*/
|
||||
class LightMenu final : public Menu
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs the light control menu with the specified configuration
|
||||
* @param options Pointer to menu options configuration structure
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
*/
|
||||
explicit LightMenu(menu_options_t *options);
|
||||
|
||||
private:
|
||||
private:
|
||||
/**
|
||||
* @brief Handles button press events specific to light control menu items
|
||||
* @param menuItem
|
||||
@@ -116,7 +116,7 @@ private:
|
||||
* @see Menu::onButtonPressed for the base implementation
|
||||
* @see ButtonType for available button types
|
||||
*/
|
||||
void onButtonPressed(const MenuItem& menuItem, ButtonType button) override;
|
||||
void onButtonPressed(const MenuItem &menuItem, ButtonType button) override;
|
||||
|
||||
/**
|
||||
* @brief Pointer to menu options configuration structure
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "ui/ClockScreenSaver.h"
|
||||
#include "hal_esp32/PersistenceManager.h"
|
||||
#include "simulator.h"
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
@@ -37,13 +38,15 @@ void ClockScreenSaver::updateTextDimensions()
|
||||
|
||||
void ClockScreenSaver::getCurrentTimeString(char *buffer, size_t bufferSize) const
|
||||
{
|
||||
if (m_options && m_options->persistenceManager->GetValue("light_active", false))
|
||||
{
|
||||
char *simulated_time = get_time();
|
||||
if (simulated_time != nullptr)
|
||||
{
|
||||
strncpy(buffer, simulated_time, bufferSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
|
||||
@@ -52,7 +55,6 @@ void ClockScreenSaver::getCurrentTimeString(char *buffer, size_t bufferSize) con
|
||||
|
||||
// Format time as HH:MM:SS
|
||||
strftime(buffer, bufferSize, "%H:%M:%S", timeinfo);
|
||||
}
|
||||
}
|
||||
|
||||
void ClockScreenSaver::Update(const uint64_t dt)
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "ui/LightMenu.h"
|
||||
|
||||
#include "led_strip_ws2812.h"
|
||||
#include "simulator.h"
|
||||
|
||||
/**
|
||||
* @namespace LightMenuItem
|
||||
@@ -54,19 +55,12 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
||||
{
|
||||
toggle(menuItem);
|
||||
const auto value = getItem(menuItem.getId()).getValue() == "1";
|
||||
if (value)
|
||||
{
|
||||
led_strip_update(LED_STATE_DAY, rgb_t{});
|
||||
}
|
||||
else
|
||||
{
|
||||
led_strip_update(LED_STATE_OFF, rgb_t{});
|
||||
}
|
||||
|
||||
if (m_options && m_options->persistenceManager)
|
||||
{
|
||||
m_options->persistenceManager->SetValue(LightMenuOptions::LIGHT_ACTIVE, value);
|
||||
}
|
||||
|
||||
start_simulation();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -83,7 +77,7 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
||||
m_options->persistenceManager->Save();
|
||||
}
|
||||
|
||||
led_strip_update(value == 0 ? LED_STATE_DAY : LED_STATE_NIGHT, rgb_t{});
|
||||
start_simulation();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
idf_component_register(SRCS
|
||||
src/color.c
|
||||
src/led_status.c
|
||||
src/led_strip_ws2812.c
|
||||
INCLUDE_DIRS "include"
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -9,4 +10,16 @@ typedef struct
|
||||
uint8_t blue;
|
||||
} rgb_t;
|
||||
|
||||
void interpolate_color(const rgb_t start_color, const rgb_t end_color, float fraction, rgb_t *out_color);
|
||||
typedef struct
|
||||
{
|
||||
uint8_t h;
|
||||
uint8_t s;
|
||||
uint8_t v;
|
||||
} hsv_t;
|
||||
|
||||
__BEGIN_DECLS
|
||||
rgb_t interpolate_color_rgb(rgb_t start, rgb_t end, float factor);
|
||||
rgb_t interpolate_color_hsv(rgb_t start, rgb_t end, float factor);
|
||||
hsv_t rgb_to_hsv(rgb_t rgb);
|
||||
rgb_t hsv_to_rgb(hsv_t hsv);
|
||||
__END_DECLS
|
||||
|
@@ -1,8 +1,183 @@
|
||||
#include "color.h"
|
||||
#include <math.h>
|
||||
|
||||
void interpolate_color(const rgb_t start_color, const rgb_t end_color, float fraction, rgb_t *out_color)
|
||||
rgb_t interpolate_color_rgb(rgb_t start, rgb_t end, float factor)
|
||||
{
|
||||
out_color->r = start_color.r + (end_color.r - start_color.r) * fraction;
|
||||
out_color->g = start_color.g + (end_color.g - start_color.g) * fraction;
|
||||
out_color->b = start_color.b + (end_color.b - start_color.b) * fraction;
|
||||
// Clamp factor to [0, 1]
|
||||
if (factor > 1.0f)
|
||||
factor = 1.0f;
|
||||
if (factor < 0.0f)
|
||||
factor = 0.0f;
|
||||
|
||||
rgb_t result;
|
||||
result.red = (uint8_t)(start.red + (end.red - start.red) * factor);
|
||||
result.green = (uint8_t)(start.green + (end.green - start.green) * factor);
|
||||
result.blue = (uint8_t)(start.blue + (end.blue - start.blue) * factor);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rgb_t interpolate_color_hsv(rgb_t start, rgb_t end, float factor)
|
||||
{
|
||||
// Clamp factor to [0, 1]
|
||||
if (factor > 1.0f)
|
||||
factor = 1.0f;
|
||||
if (factor < 0.0f)
|
||||
factor = 0.0f;
|
||||
|
||||
// Convert RGB to HSV
|
||||
hsv_t start_hsv = rgb_to_hsv(start);
|
||||
hsv_t end_hsv = rgb_to_hsv(end);
|
||||
|
||||
// Handle hue interpolation carefully (circular)
|
||||
double h1 = start_hsv.h;
|
||||
double h2 = end_hsv.h;
|
||||
double diff = h2 - h1;
|
||||
|
||||
if (diff > 180.0)
|
||||
{
|
||||
h1 += 360.0;
|
||||
}
|
||||
else if (diff < -180.0)
|
||||
{
|
||||
h2 += 360.0;
|
||||
}
|
||||
|
||||
// Interpolate HSV values
|
||||
hsv_t interpolated_hsv;
|
||||
interpolated_hsv.h = fmod(h1 + (h2 - h1) * factor, 360.0);
|
||||
if (interpolated_hsv.h < 0)
|
||||
{
|
||||
interpolated_hsv.h += 360.0;
|
||||
}
|
||||
interpolated_hsv.s = start_hsv.s + (end_hsv.s - start_hsv.s) * factor;
|
||||
interpolated_hsv.v = start_hsv.v + (end_hsv.v - start_hsv.v) * factor;
|
||||
|
||||
// Convert back to RGB
|
||||
return hsv_to_rgb(interpolated_hsv);
|
||||
}
|
||||
|
||||
hsv_t rgb_to_hsv(rgb_t rgb)
|
||||
{
|
||||
hsv_t hsv;
|
||||
uint8_t max = rgb.red;
|
||||
uint8_t min = rgb.red;
|
||||
|
||||
if (rgb.green > max)
|
||||
max = rgb.green;
|
||||
if (rgb.blue > max)
|
||||
max = rgb.blue;
|
||||
if (rgb.green < min)
|
||||
min = rgb.green;
|
||||
if (rgb.blue < min)
|
||||
min = rgb.blue;
|
||||
|
||||
uint8_t delta = max - min;
|
||||
|
||||
// Value berechnen
|
||||
hsv.v = max;
|
||||
|
||||
// Saturation berechnen
|
||||
if (max != 0)
|
||||
{
|
||||
hsv.s = (delta * 255) / max;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Schwarz (r = g = b = 0)
|
||||
hsv.s = 0;
|
||||
hsv.h = 0;
|
||||
return hsv;
|
||||
}
|
||||
|
||||
// Hue berechnen
|
||||
if (delta != 0)
|
||||
{
|
||||
int16_t hue;
|
||||
|
||||
if (rgb.red == max)
|
||||
{
|
||||
// Zwischen Gelb und Magenta
|
||||
hue = ((int16_t)(rgb.green - rgb.blue) * 30) / delta;
|
||||
if (hue < 0)
|
||||
hue += 180;
|
||||
}
|
||||
else if (rgb.green == max)
|
||||
{
|
||||
// Zwischen Cyan und Gelb
|
||||
hue = 60 + ((int16_t)(rgb.blue - rgb.red) * 30) / delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Zwischen Magenta und Cyan
|
||||
hue = 120 + ((int16_t)(rgb.red - rgb.green) * 30) / delta;
|
||||
}
|
||||
|
||||
hsv.h = (uint8_t)hue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Graustufe
|
||||
hsv.h = 0;
|
||||
}
|
||||
|
||||
return hsv;
|
||||
}
|
||||
|
||||
rgb_t hsv_to_rgb(hsv_t hsv)
|
||||
{
|
||||
rgb_t rgb;
|
||||
|
||||
if (hsv.s == 0)
|
||||
{
|
||||
// Graustufe
|
||||
rgb.red = hsv.v;
|
||||
rgb.green = hsv.v;
|
||||
rgb.blue = hsv.v;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t region = hsv.h / 30;
|
||||
uint16_t remainder = (hsv.h - (region * 30)) * 6;
|
||||
|
||||
uint8_t p = (hsv.v * (255 - hsv.s)) / 255;
|
||||
uint8_t q = (hsv.v * (255 - ((hsv.s * remainder) / 180))) / 255;
|
||||
uint8_t t = (hsv.v * (255 - ((hsv.s * (180 - remainder)) / 180))) / 255;
|
||||
|
||||
switch (region)
|
||||
{
|
||||
case 0:
|
||||
rgb.red = hsv.v;
|
||||
rgb.green = t;
|
||||
rgb.blue = p;
|
||||
break;
|
||||
case 1:
|
||||
rgb.red = q;
|
||||
rgb.green = hsv.v;
|
||||
rgb.blue = p;
|
||||
break;
|
||||
case 2:
|
||||
rgb.red = p;
|
||||
rgb.green = hsv.v;
|
||||
rgb.blue = t;
|
||||
break;
|
||||
case 3:
|
||||
rgb.red = p;
|
||||
rgb.green = q;
|
||||
rgb.blue = hsv.v;
|
||||
break;
|
||||
case 4:
|
||||
rgb.red = t;
|
||||
rgb.green = p;
|
||||
rgb.blue = hsv.v;
|
||||
break;
|
||||
default: // case 5:
|
||||
rgb.red = hsv.v;
|
||||
rgb.green = p;
|
||||
rgb.blue = q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return rgb;
|
||||
}
|
@@ -88,6 +88,8 @@ esp_err_t led_strip_init(void)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
set_all_pixels((rgb_t){.red = 0, .green = 0, .blue = 0});
|
||||
|
||||
xTaskCreate(led_strip_task, "led_strip_task", 4096, NULL, tskIDLE_PRIORITY + 1, NULL);
|
||||
|
||||
ESP_LOGI(TAG, "LED strip initialized");
|
||||
|
@@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../IPersistenceManager.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
|
||||
class PersistenceManager final : public IPersistenceManager {
|
||||
public:
|
||||
using ValueType = std::variant<
|
||||
bool,
|
||||
int,
|
||||
float,
|
||||
double,
|
||||
std::string
|
||||
>;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, ValueType> m_data;
|
||||
std::string m_filename;
|
||||
|
||||
public:
|
||||
explicit PersistenceManager(std::string filename = "settings.dat");
|
||||
~PersistenceManager() override;
|
||||
|
||||
[[nodiscard]] bool HasKey(const std::string& key) const override;
|
||||
void RemoveKey(const std::string& key) override;
|
||||
void Clear() override;
|
||||
[[nodiscard]] size_t GetKeyCount() const override { return m_data.size(); }
|
||||
|
||||
bool Save() override;
|
||||
bool Load() override;
|
||||
|
||||
bool SaveToFile(const std::string& filename);
|
||||
bool LoadFromFile(const std::string& filename);
|
||||
|
||||
protected:
|
||||
void SetValueImpl(const std::string& key, bool value) override;
|
||||
void SetValueImpl(const std::string& key, int value) override;
|
||||
void SetValueImpl(const std::string& key, float value) override;
|
||||
void SetValueImpl(const std::string& key, double value) override;
|
||||
void SetValueImpl(const std::string& key, const std::string& value) override;
|
||||
|
||||
[[nodiscard]] bool GetValueImpl(const std::string& key, bool defaultValue) const override;
|
||||
[[nodiscard]] int GetValueImpl(const std::string& key, int defaultValue) const override;
|
||||
[[nodiscard]] float GetValueImpl(const std::string& key, float defaultValue) const override;
|
||||
[[nodiscard]] double GetValueImpl(const std::string& key, double defaultValue) const override;
|
||||
[[nodiscard]] std::string GetValueImpl(const std::string& key, const std::string& defaultValue) const override;
|
||||
|
||||
private:
|
||||
static bool WriteValueToStream(SDL_IOStream* stream, const ValueType& value) ;
|
||||
static bool ReadValueFromStream(SDL_IOStream* stream, ValueType& value) ;
|
||||
|
||||
enum class TypeId : uint8_t {
|
||||
BOOL = 0,
|
||||
INT = 1,
|
||||
FLOAT = 2,
|
||||
DOUBLE = 3,
|
||||
STRING = 4
|
||||
};
|
||||
|
||||
static TypeId GetTypeId(const ValueType& value);
|
||||
};
|
@@ -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,12 +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);
|
||||
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,12 +1,14 @@
|
||||
#include "simulator.h"
|
||||
|
||||
#include "color.h"
|
||||
#include "hal_esp32/PersistenceManager.h"
|
||||
#include "led_strip_ws2812.h"
|
||||
#include "storage.h"
|
||||
#include <esp_heap_caps.h>
|
||||
#include <esp_log.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -37,12 +39,36 @@ typedef struct light_item_node_t
|
||||
static light_item_node_t *head = NULL;
|
||||
static light_item_node_t *tail = NULL;
|
||||
|
||||
// Interpolation mode selection
|
||||
typedef enum
|
||||
{
|
||||
INTERPOLATION_RGB,
|
||||
INTERPOLATION_HSV
|
||||
} interpolation_mode_t;
|
||||
|
||||
// You can change this to test different interpolation methods
|
||||
static const interpolation_mode_t interpolation_mode = INTERPOLATION_RGB;
|
||||
|
||||
char *get_time(void)
|
||||
{
|
||||
return time;
|
||||
}
|
||||
|
||||
esp_err_t add_light_item(const char time[5], uint8_t red, uint8_t green, uint8_t blue)
|
||||
// Main interpolation function that selects the appropriate method
|
||||
static rgb_t interpolate_color(rgb_t start, rgb_t end, float factor)
|
||||
{
|
||||
switch (interpolation_mode)
|
||||
{
|
||||
case INTERPOLATION_RGB:
|
||||
return interpolate_color_rgb(start, end, factor);
|
||||
case INTERPOLATION_HSV:
|
||||
default:
|
||||
return interpolate_color_hsv(start, end, factor);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Allocate memory for a new node in PSRAM.
|
||||
light_item_node_t *new_node = (light_item_node_t *)heap_caps_malloc(sizeof(light_item_node_t), MALLOC_CAP_SPIRAM);
|
||||
@@ -52,11 +78,21 @@ esp_err_t add_light_item(const char time[5], uint8_t red, uint8_t green, uint8_t
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
// Initialize the data of the new node.
|
||||
rgb_t color = {.red = red, .green = green, .blue = blue};
|
||||
|
||||
if (saturation < 255)
|
||||
{
|
||||
hsv_t hsv = rgb_to_hsv(color);
|
||||
hsv.s = hsv.s * (saturation / 255.0f);
|
||||
// color = hsv_to_rgb(hsv);
|
||||
}
|
||||
|
||||
float brightness_factor = brightness / 255.0f;
|
||||
|
||||
memcpy(new_node->time, time, sizeof(new_node->time));
|
||||
new_node->red = red;
|
||||
new_node->green = green;
|
||||
new_node->blue = blue;
|
||||
new_node->red = (uint8_t)(color.red * brightness_factor);
|
||||
new_node->green = (uint8_t)(color.green * brightness_factor);
|
||||
new_node->blue = (uint8_t)(color.blue * brightness_factor);
|
||||
new_node->next = NULL;
|
||||
|
||||
// Append the new node to the end of the list.
|
||||
@@ -102,7 +138,7 @@ static void initialize_light_items(void)
|
||||
}
|
||||
|
||||
initialize_storage();
|
||||
load_file("/spiffs/schema_02.csv");
|
||||
load_file("/spiffs/schema_03.csv");
|
||||
|
||||
if (head == NULL)
|
||||
{
|
||||
@@ -131,16 +167,62 @@ static light_item_node_t *find_best_light_item_for_time(int hhmm)
|
||||
|
||||
if (best_item == NULL)
|
||||
{
|
||||
ESP_LOGW(TAG, "No suitable light item found for time up to %04d", hhmm);
|
||||
}
|
||||
else
|
||||
// If no item is found for the given time (e.g., before the first item of the day),
|
||||
// find the last item of the previous day.
|
||||
best_time = -1;
|
||||
current = head;
|
||||
while (current != NULL)
|
||||
{
|
||||
ESP_LOGD(TAG, "Best light item for time %04d is %s", hhmm, best_item->time);
|
||||
int current_time = atoi(current->time);
|
||||
if (current_time > best_time)
|
||||
{
|
||||
best_time = current_time;
|
||||
best_item = current;
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
|
||||
return best_item;
|
||||
}
|
||||
|
||||
static light_item_node_t *find_next_light_item_for_time(int hhmm)
|
||||
{
|
||||
light_item_node_t *current = head;
|
||||
light_item_node_t *next_item = NULL;
|
||||
int next_time = 9999; // Initialize with a value larger than any possible time
|
||||
|
||||
// First pass: find the soonest time after hhmm
|
||||
while (current != NULL)
|
||||
{
|
||||
int current_time = atoi(current->time);
|
||||
if (current_time > hhmm && current_time < next_time)
|
||||
{
|
||||
next_time = current_time;
|
||||
next_item = current;
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
// If no item is found for the rest of the day, wrap around to the beginning of the next day
|
||||
if (next_item == NULL)
|
||||
{
|
||||
current = head;
|
||||
next_time = 9999;
|
||||
while (current != NULL)
|
||||
{
|
||||
int current_time = atoi(current->time);
|
||||
if (current_time < next_time)
|
||||
{
|
||||
next_time = current_time;
|
||||
next_item = current;
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
return next_item;
|
||||
}
|
||||
|
||||
void start_simulate_day(void)
|
||||
{
|
||||
initialize_light_items();
|
||||
@@ -186,7 +268,6 @@ void simulate_cycle(void *args)
|
||||
cycle_duration_minutes, delay_ms);
|
||||
|
||||
int current_minute_of_day = 0;
|
||||
light_item_node_t *last_item = NULL;
|
||||
|
||||
while (1)
|
||||
{
|
||||
@@ -196,15 +277,47 @@ void simulate_cycle(void *args)
|
||||
time = time_to_string(hhmm);
|
||||
|
||||
light_item_node_t *current_item = find_best_light_item_for_time(hhmm);
|
||||
light_item_node_t *next_item = find_next_light_item_for_time(hhmm);
|
||||
|
||||
if (current_item != NULL && current_item != last_item)
|
||||
if (current_item != NULL && next_item != NULL)
|
||||
{
|
||||
ESP_LOGI(TAG, "Simulating time: %02d:%02d -> Closest schedule is %s. R:%d, G:%d, B:%d", hours, minutes,
|
||||
current_item->time, current_item->red, current_item->green, current_item->blue);
|
||||
int current_item_time_min = (atoi(current_item->time) / 100) * 60 + (atoi(current_item->time) % 100);
|
||||
int next_item_time_min = (atoi(next_item->time) / 100) * 60 + (atoi(next_item->time) % 100);
|
||||
|
||||
if (next_item_time_min < current_item_time_min)
|
||||
{
|
||||
next_item_time_min += total_minutes_in_day;
|
||||
}
|
||||
|
||||
int minutes_since_current_item_start = current_minute_of_day - current_item_time_min;
|
||||
if (minutes_since_current_item_start < 0)
|
||||
{
|
||||
minutes_since_current_item_start += total_minutes_in_day;
|
||||
}
|
||||
|
||||
int interval_duration = next_item_time_min - current_item_time_min;
|
||||
if (interval_duration == 0)
|
||||
{
|
||||
interval_duration = 1;
|
||||
}
|
||||
|
||||
float interpolation_factor = (float)minutes_since_current_item_start / (float)interval_duration;
|
||||
|
||||
// Prepare colors for interpolation
|
||||
rgb_t start_rgb = {.red = current_item->red, .green = current_item->green, .blue = current_item->blue};
|
||||
rgb_t end_rgb = {.red = next_item->red, .green = next_item->green, .blue = next_item->blue};
|
||||
|
||||
// Use the interpolation function
|
||||
rgb_t final_rgb = interpolate_color(start_rgb, end_rgb, interpolation_factor);
|
||||
|
||||
led_strip_update(LED_STATE_SIMULATION, final_rgb);
|
||||
}
|
||||
else if (current_item != NULL)
|
||||
{
|
||||
// No next item, just use current
|
||||
led_strip_update(
|
||||
LED_STATE_SIMULATION,
|
||||
(rgb_t){.red = current_item->red, .green = current_item->green, .blue = current_item->blue});
|
||||
last_item = current_item;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(delay_ms));
|
||||
@@ -220,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);
|
||||
@@ -243,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{});
|
||||
}
|
||||
}
|
@@ -11,10 +11,10 @@ static const char *TAG = "storage";
|
||||
void initialize_storage()
|
||||
{
|
||||
esp_vfs_spiffs_conf_t conf = {
|
||||
.base_path = "/spiffs", // Der Basispfad, unter dem das Dateisystem gemountet wird
|
||||
.partition_label = NULL, // NULL, um die erste gefundene SPIFFS-Partition zu verwenden
|
||||
.max_files = 5, // Maximale Anzahl gleichzeitig geöffneter Dateien
|
||||
.format_if_mount_failed = false // Partition formatieren, wenn das Mounten fehlschlägt
|
||||
.base_path = "/spiffs",
|
||||
.partition_label = NULL,
|
||||
.max_files = 5,
|
||||
.format_if_mount_failed = false,
|
||||
};
|
||||
|
||||
esp_err_t ret = esp_vfs_spiffs_register(&conf);
|
||||
@@ -33,7 +33,7 @@ void initialize_storage()
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
|
||||
}
|
||||
return; // Oder entsprechende Fehlerbehandlung
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,24 +47,45 @@ void load_file(const char *filename)
|
||||
return;
|
||||
}
|
||||
|
||||
char line[128]; // Puffer für eine Zeile, vergrößert für mehr Sicherheit
|
||||
char line[128];
|
||||
uint8_t line_number = 0;
|
||||
while (fgets(line, sizeof(line), f))
|
||||
{
|
||||
// Entferne möglichen Zeilenumbruch am Ende
|
||||
char *pos = strchr(line, '\n');
|
||||
if (pos)
|
||||
{
|
||||
*pos = '\0';
|
||||
}
|
||||
|
||||
char time[5] = {0}; // 4 Zeichen + Nullterminator
|
||||
int red, green, blue;
|
||||
|
||||
// Parse die Zeile im Format "HHMM,R,G,B"
|
||||
int items_scanned = sscanf(line, "%4[^,],%d,%d,%d", time, &red, &green, &blue);
|
||||
if (items_scanned == 4)
|
||||
if (strlen(line) == 0)
|
||||
{
|
||||
add_light_item(time, (uint8_t)red, (uint8_t)green, (uint8_t)blue);
|
||||
continue;
|
||||
}
|
||||
|
||||
char *trimmed = line;
|
||||
while (*trimmed == ' ' || *trimmed == '\t')
|
||||
{
|
||||
trimmed++;
|
||||
}
|
||||
if (*trimmed == '#' || *trimmed == '\0')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
char time[10] = {0};
|
||||
int red, green, blue, white, brightness, saturation;
|
||||
|
||||
int items_scanned = sscanf(line, "%d,%d,%d,%d,%d,%d", &red, &green, &blue, &white, &brightness, &saturation);
|
||||
if (items_scanned == 6)
|
||||
{
|
||||
int total_minutes = line_number * 30;
|
||||
int hours = total_minutes / 60;
|
||||
int minutes = total_minutes % 60;
|
||||
|
||||
snprintf(time, sizeof(time), "%02d%02d", hours, minutes);
|
||||
|
||||
add_light_item(time, red, green, blue, white, brightness, saturation);
|
||||
line_number++;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -73,5 +94,5 @@ void load_file(const char *filename)
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
ESP_LOGI(TAG, "Finished loading file.");
|
||||
ESP_LOGI(TAG, "Finished loading file. Loaded %d entries.", line_number);
|
||||
}
|
@@ -21,4 +21,4 @@ idf_component_register(SRCS
|
||||
rmaker_common
|
||||
)
|
||||
|
||||
spiffs_create_partition_image(storage ../spiffs_image FLASH_IN_PROJECT)
|
||||
spiffs_create_partition_image(storage ../storage FLASH_IN_PROJECT)
|
||||
|
@@ -3,20 +3,22 @@
|
||||
#include "analytics.h"
|
||||
#include "button_handling.h"
|
||||
#include "common/InactivityTracker.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "esp_diagnostics.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "hal/u8g2_esp32_hal.h"
|
||||
#include "hal_esp32/PersistenceManager.h"
|
||||
#include "i2c_checker.h"
|
||||
#include "led_status.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "u8g2.h"
|
||||
#include "simulator.h"
|
||||
#include "ui/ClockScreenSaver.h"
|
||||
#include "ui/ScreenSaver.h"
|
||||
#include "ui/SplashScreen.h"
|
||||
#include "wifi_manager.h"
|
||||
#include <driver/i2c.h>
|
||||
#include <esp_diagnostics.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <esp_timer.h>
|
||||
#include <sdkconfig.h>
|
||||
#include <u8g2.h>
|
||||
|
||||
#define PIN_RST GPIO_NUM_NC
|
||||
|
||||
@@ -47,9 +49,13 @@ static void setup_screen(void)
|
||||
|
||||
ESP_DIAG_EVENT(TAG, "u8g2_InitDisplay");
|
||||
u8g2_InitDisplay(&u8g2);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
ESP_DIAG_EVENT(TAG, "u8g2_SetPowerSave");
|
||||
u8g2_SetPowerSave(&u8g2, 0);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
u8g2_ClearDisplay(&u8g2);
|
||||
}
|
||||
|
||||
void setScreen(const std::shared_ptr<Widget> &screen)
|
||||
@@ -158,6 +164,8 @@ static void handle_button(uint8_t button)
|
||||
|
||||
void app_task(void *args)
|
||||
{
|
||||
esp_task_wdt_add(NULL);
|
||||
|
||||
if (i2c_bus_scan_and_check() != ESP_OK)
|
||||
{
|
||||
led_behavior_t led0_behavior = {.mode = LED_MODE_BLINK,
|
||||
@@ -180,10 +188,14 @@ void app_task(void *args)
|
||||
analytics_init();
|
||||
#endif
|
||||
|
||||
start_simulation();
|
||||
|
||||
auto oldTime = esp_timer_get_time();
|
||||
|
||||
while (true)
|
||||
{
|
||||
esp_task_wdt_reset();
|
||||
|
||||
u8g2_ClearBuffer(&u8g2);
|
||||
|
||||
if (m_widget != nullptr)
|
||||
|
@@ -3,7 +3,6 @@
|
||||
#include "hal_esp32/PersistenceManager.h"
|
||||
#include "led_status.h"
|
||||
#include "led_strip_ws2812.h"
|
||||
#include "simulator.h"
|
||||
#include "wifi_manager.h"
|
||||
#include <ble_manager.h>
|
||||
#include <esp_event.h>
|
||||
@@ -31,15 +30,9 @@ void app_main(void)
|
||||
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(app_task, "app_task", 8192, 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{});
|
||||
}
|
||||
}
|
||||
__END_DECLS
|
||||
|
@@ -1,48 +0,0 @@
|
||||
0000,25,25,112
|
||||
0030,25,25,112
|
||||
0100,25,25,112
|
||||
0130,25,25,112
|
||||
0200,25,25,112
|
||||
0230,25,25,112
|
||||
0300,25,25,112
|
||||
0330,25,25,112
|
||||
0400,25,25,112
|
||||
0430,140,25,112
|
||||
0500,255,130,112
|
||||
0530,255,155,112
|
||||
0600,255,177,115
|
||||
0630,255,200,135
|
||||
0700,255,219,170
|
||||
0730,255,234,205
|
||||
0800,255,249,240
|
||||
0830,255,249,250
|
||||
0900,239,245,255
|
||||
0930,224,240,255
|
||||
1000,215,235,255
|
||||
1030,212,234,255
|
||||
1100,210,233,255
|
||||
1130,208,232,255
|
||||
1200,207,231,255
|
||||
1230,205,230,255
|
||||
1300,204,229,255
|
||||
1330,204,229,255
|
||||
1400,206,230,255
|
||||
1430,208,231,255
|
||||
1500,213,232,255
|
||||
1530,219,234,255
|
||||
1600,229,239,255
|
||||
1630,236,246,255
|
||||
1700,255,252,251
|
||||
1730,255,243,236
|
||||
1800,255,225,202
|
||||
1830,255,203,174
|
||||
1900,255,178,129
|
||||
1930,255,146,85
|
||||
2000,255,93,38
|
||||
2030,140,55,70
|
||||
2100,25,25,112
|
||||
2130,25,25,112
|
||||
2200,25,25,112
|
||||
2230,25,25,112
|
||||
2300,25,25,112
|
||||
2330,25,25,112
|
|
@@ -1,48 +0,0 @@
|
||||
0000,25,25,112
|
||||
0030,25,25,112
|
||||
0100,25,25,112
|
||||
0130,25,25,112
|
||||
0200,25,25,112
|
||||
0230,25,25,112
|
||||
0300,25,25,112
|
||||
0330,62,25,95
|
||||
0400,102,60,78
|
||||
0430,140,78,61
|
||||
0500,178,95,44
|
||||
0530,214,113,27
|
||||
0600,255,130,10
|
||||
0630,255,139,22
|
||||
0700,255,147,34
|
||||
0730,255,155,46
|
||||
0800,255,163,58
|
||||
0830,255,172,70
|
||||
0900,255,180,82
|
||||
0930,255,189,93
|
||||
1000,255,197,105
|
||||
1030,255,205,117
|
||||
1100,255,213,129
|
||||
1130,255,222,141
|
||||
1200,255,230,153
|
||||
1230,255,222,143
|
||||
1300,255,214,133
|
||||
1330,255,206,124
|
||||
1400,255,198,114
|
||||
1430,255,191,104
|
||||
1500,255,183,94
|
||||
1530,255,175,84
|
||||
1600,255,167,74
|
||||
1630,255,159,64
|
||||
1700,255,151,55
|
||||
1730,255,143,45
|
||||
1800,255,135,35
|
||||
1830,214,116,45
|
||||
1900,178,98,61
|
||||
1930,140,80,74
|
||||
2000,102,62,86
|
||||
2030,63,44,99
|
||||
2100,25,25,112
|
||||
2130,25,25,112
|
||||
2200,25,25,112
|
||||
2230,25,25,112
|
||||
2300,25,25,112
|
||||
2330,25,25,112
|
|
48
firmware/storage/schema_01.csv
Normal file
48
firmware/storage/schema_01.csv
Normal file
@@ -0,0 +1,48 @@
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
140,25,112,0,100,250
|
||||
255,130,112,0,130,250
|
||||
255,155,112,0,150,250
|
||||
255,177,115,0,170,250
|
||||
255,200,135,0,190,250
|
||||
255,219,170,0,210,250
|
||||
255,234,205,0,217,250
|
||||
255,249,240,0,223,250
|
||||
255,249,250,0,227,250
|
||||
239,245,255,0,234,250
|
||||
224,240,255,0,239,250
|
||||
215,235,255,0,244,250
|
||||
212,234,255,0,248,250
|
||||
210,233,255,0,250,250
|
||||
208,232,255,0,252,250
|
||||
207,231,255,0,255,250
|
||||
205,230,255,0,252,250
|
||||
204,229,255,0,250,250
|
||||
204,229,255,0,247,250
|
||||
206,230,255,0,245,250
|
||||
208,231,255,0,243,250
|
||||
213,232,255,0,240,250
|
||||
219,234,255,0,237,250
|
||||
229,239,255,0,235,250
|
||||
236,246,255,0,233,250
|
||||
255,252,251,0,230,250
|
||||
255,243,236,0,225,250
|
||||
255,225,202,0,220,250
|
||||
255,203,174,0,205,250
|
||||
255,178,129,0,190,250
|
||||
255,146,85,0,165,250
|
||||
255,93,38,0,140,250
|
||||
140,55,70,0,120,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
|
48
firmware/storage/schema_02.csv
Normal file
48
firmware/storage/schema_02.csv
Normal file
@@ -0,0 +1,48 @@
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
62,25,95,0,100,250
|
||||
102,60,78,0,100,250
|
||||
140,78,61,0,115,250
|
||||
178,95,44,0,130,250
|
||||
214,113,27,0,150,250
|
||||
255,130,10,0,170,250
|
||||
255,139,22,0,190,250
|
||||
255,147,34,0,210,250
|
||||
255,155,46,0,215,250
|
||||
255,163,58,0,220,250
|
||||
255,172,70,0,225,250
|
||||
255,180,82,0,230,250
|
||||
255,189,93,0,235,250
|
||||
255,197,105,0,240,250
|
||||
255,205,117,0,245,250
|
||||
255,213,129,0,250,250
|
||||
255,222,141,0,252,250
|
||||
255,230,153,0,255,250
|
||||
255,222,143,0,252,250
|
||||
255,214,133,0,250,250
|
||||
255,206,124,0,247,250
|
||||
255,198,114,0,245,250
|
||||
255,191,104,0,242,250
|
||||
255,183,94,0,240,250
|
||||
255,175,84,0,237,250
|
||||
255,167,74,0,235,250
|
||||
255,159,64,0,233,250
|
||||
255,151,55,0,230,250
|
||||
255,143,45,0,225,250
|
||||
255,135,35,0,220,250
|
||||
214,116,45,0,205,250
|
||||
178,98,61,0,190,250
|
||||
140,80,74,0,165,250
|
||||
102,62,86,0,140,250
|
||||
63,44,99,0,120,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
||||
25,25,112,0,100,250
|
|
71
firmware/storage/schema_03.csv
Normal file
71
firmware/storage/schema_03.csv
Normal file
@@ -0,0 +1,71 @@
|
||||
# Nacht (Tiefblau/Dunkelblau)
|
||||
15,20,40,0,80,250
|
||||
15,20,45,0,80,250
|
||||
15,20,50,0,85,250
|
||||
15,25,55,0,85,250
|
||||
20,25,60,0,90,250
|
||||
20,30,65,0,90,250
|
||||
25,35,70,0,95,250
|
||||
|
||||
# Frühe Morgendämmerung (Blau → Violett)
|
||||
35,40,80,0,100,250
|
||||
45,45,90,0,105,250
|
||||
55,50,100,0,110,250
|
||||
70,55,110,0,115,250
|
||||
85,60,115,0,120,250
|
||||
|
||||
# Morgendämmerung (Violett → Rosa → Orange)
|
||||
100,65,120,0,125,250
|
||||
120,75,125,0,130,250
|
||||
140,85,130,0,135,250
|
||||
160,95,135,0,140,250
|
||||
180,105,140,0,145,250
|
||||
|
||||
# Sonnenaufgang (Orange → Gelb-Orange)
|
||||
200,115,130,0,150,250
|
||||
220,130,120,0,160,250
|
||||
235,145,110,0,170,250
|
||||
245,160,100,0,180,250
|
||||
250,175,90,0,190,250
|
||||
|
||||
# Vormittag (Warm-Weiß)
|
||||
255,190,100,0,200,250
|
||||
255,205,120,0,210,250
|
||||
255,220,140,0,220,250
|
||||
|
||||
# Mittag (Helles Weiß mit leichtem Blaustich)
|
||||
255,245,200,0,230,250
|
||||
255,250,220,0,240,250
|
||||
255,255,240,0,250,250
|
||||
255,255,250,0,255,250
|
||||
255,250,240,0,250,250
|
||||
255,245,220,0,240,250
|
||||
255,240,200,0,230,250
|
||||
|
||||
# Nachmittag (Warm-Weiß)
|
||||
255,225,160,0,220,250
|
||||
255,210,140,0,210,250
|
||||
255,195,120,0,200,250
|
||||
|
||||
# Später Nachmittag → Abend (Gelb-Orange)
|
||||
250,180,100,0,190,250
|
||||
245,165,90,0,180,250
|
||||
235,150,80,0,170,250
|
||||
220,135,70,0,160,250
|
||||
200,120,60,0,150,250
|
||||
|
||||
# Sonnenuntergang (Orange → Rot → Violett)
|
||||
180,100,50,0,140,250
|
||||
160,85,60,0,135,250
|
||||
140,70,70,0,130,250
|
||||
120,60,80,0,125,250
|
||||
100,50,90,0,120,250
|
||||
|
||||
# Abenddämmerung (Violett → Blau)
|
||||
80,45,95,0,115,250
|
||||
60,40,100,0,110,250
|
||||
45,35,95,0,105,250
|
||||
30,30,85,0,100,250
|
||||
25,30,75,0,95,250
|
||||
20,25,65,0,90,250
|
||||
15,20,50,0,85,250
|
|
@@ -1 +1 @@
|
||||
0.1.0
|
||||
0.1.1
|
Reference in New Issue
Block a user