feat: Licht-Steuerung mit Fade-Regeln und Einschaltverhalten

This commit is contained in:
Michael Sauer
2026-09-11 13:20:49 +02:00
parent 472d2398ac
commit e0bde7bee3
8 changed files with 501 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
#ifndef NL_CONTROL_H
#define NL_CONTROL_H
#include <stdbool.h>
#include <stdint.h>
#include "board/nl_board.h"
#include "light/nl_light_types.h"
#define NL_MAX_TRANSITION_MS 60000u
#define NL_MAX_FADE_MS 10000u
#define NL_PERSIST_DELAY_MS 3000u
typedef struct {
bool has_on;
bool on;
bool has_brightness;
uint8_t brightness;
bool has_color;
uint8_t r, g, b;
bool has_ct;
uint16_t ct;
bool has_transition;
uint32_t transition_ms;
} nl_light_change_t;
typedef enum {
NL_CTRL_OK = 0,
NL_CTRL_ERR_NO_RGB,
NL_CTRL_ERR_COLOR_AND_CT,
NL_CTRL_ERR_BRIGHTNESS,
NL_CTRL_ERR_TRANSITION
} nl_ctrl_err_t;
/* The engine must be initialised before. Not thread safe: callers serialise access. */
void nl_ctrl_init(const nl_board_t *board, uint16_t fade_in_ms, uint16_t fade_out_ms);
void nl_ctrl_set_fades(uint16_t fade_in_ms, uint16_t fade_out_ms);
void nl_ctrl_boot(const nl_light_state_t *initial);
nl_ctrl_err_t nl_ctrl_apply(const nl_light_change_t *c, uint32_t now_ms);
void nl_ctrl_get(nl_light_state_t *out);
/* True once NL_PERSIST_DELAY_MS after the last change; out receives the state to store. */
bool nl_ctrl_persist_due(uint32_t now_ms, nl_light_state_t *out);
/* Clears the dirty flag only if nothing changed since `written` was taken. */
void nl_ctrl_persisted(const nl_light_state_t *written);
#endif