feat: Default-Transition, Weckschalter und farbfreier Ausschaltfade
Zwei neue Einstellungen, beide wie fade_in/fade_out ueber POST /api/v1/device/state les- und schreibbar und sofort wirksam: - transition_default (Voreinstellung 300 ms) fuellt die Transition fuer Farb-, Weiss- und Helligkeitswechsel bei eingeschalteter Lampe, wenn der Aufruf kein eigenes "transition" mitbringt. Beim Ein- und Ausschalten behalten fade_in/fade_out weiterhin Vorrang. - wake_on_change (Voreinstellung aus) schaltet die Lampe bei einer Farb-, Weiss- oder Helligkeitsaenderung ein, wenn sie aus war. Ein ausdrueckliches "on": false im selben Aufruf gewinnt immer. Beide Felder haengen am Ende von nl_settings_t, damit bestehende Lampen ueber die Laengentoleranz von read_rec() ihre echten Voreinstellungen bekommen statt Nullen. nl_ctrl_set_fades() heisst jetzt nl_ctrl_set_options(). Dazu ein Treiberfehler, der erst an der migrierten GU10 RGB auffiel: der WY-Zweig von nl_sm2135eh_set() schrieb nur Header und WY-Daten, nie die RGB-Datenregister. Der Chip behielt also die zuletzt gesetzte Farbe, und bei einem direkten Wechsel Farbe -> Weiss (ohne Zwischenschritt ueber dunkel) schaelte sie sich beim Ausblenden wieder frei. Der Header sendet jetzt die - in Weiss immer nullwertigen - RGB-Daten mit. Die Bruno-Collection zeigt Transition jetzt zusammen mit einem Farb- und einem Weisswechsel im selben Aufruf und hat einen Request fuer die beiden neuen Einstellungen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
62a2b43175
commit
00d5a4c532
+17
-4
@@ -7,23 +7,29 @@ static const nl_board_t *s_board;
|
||||
static nl_light_state_t s_state;
|
||||
static uint16_t s_fade_in;
|
||||
static uint16_t s_fade_out;
|
||||
static uint16_t s_transition;
|
||||
static bool s_wake_on_change;
|
||||
static bool s_dirty;
|
||||
static uint32_t s_changed_at;
|
||||
|
||||
void nl_ctrl_init(const nl_board_t *board, uint16_t fade_in_ms, uint16_t fade_out_ms)
|
||||
void nl_ctrl_init(const nl_board_t *board, uint16_t fade_in_ms, uint16_t fade_out_ms,
|
||||
uint16_t transition_ms, bool wake_on_change)
|
||||
{
|
||||
s_board = board;
|
||||
s_state = nl_boot_default_state(board);
|
||||
s_state.on = false;
|
||||
s_dirty = false;
|
||||
s_changed_at = 0;
|
||||
nl_ctrl_set_fades(fade_in_ms, fade_out_ms);
|
||||
nl_ctrl_set_options(fade_in_ms, fade_out_ms, transition_ms, wake_on_change);
|
||||
}
|
||||
|
||||
void nl_ctrl_set_fades(uint16_t fade_in_ms, uint16_t fade_out_ms)
|
||||
void nl_ctrl_set_options(uint16_t fade_in_ms, uint16_t fade_out_ms, uint16_t transition_ms,
|
||||
bool wake_on_change)
|
||||
{
|
||||
s_fade_in = fade_in_ms > NL_MAX_FADE_MS ? NL_MAX_FADE_MS : fade_in_ms;
|
||||
s_fade_out = fade_out_ms > NL_MAX_FADE_MS ? NL_MAX_FADE_MS : fade_out_ms;
|
||||
s_transition = transition_ms > NL_MAX_TRANSITION_MS ? NL_MAX_TRANSITION_MS : transition_ms;
|
||||
s_wake_on_change = wake_on_change;
|
||||
}
|
||||
|
||||
void nl_ctrl_boot(const nl_light_state_t *initial)
|
||||
@@ -62,6 +68,13 @@ nl_ctrl_err_t nl_ctrl_apply(const nl_light_change_t *c, uint32_t now_ms)
|
||||
n.mode = NL_MODE_WHITE;
|
||||
}
|
||||
|
||||
/* Weckschalter: a color/CT/brightness change arriving while the lamp is off switches it
|
||||
* on, unless this same call also says "on": false explicitly - that always wins. Applied
|
||||
* before the duration below so an off->on transition here uses fade_in like any other. */
|
||||
if (s_wake_on_change && !s_state.on && !n.on && !(c->has_on && !c->on) &&
|
||||
(c->has_color || c->has_ct || c->has_brightness))
|
||||
n.on = true;
|
||||
|
||||
if (c->has_transition)
|
||||
dur = c->transition_ms;
|
||||
else if (!s_state.on && n.on)
|
||||
@@ -69,7 +82,7 @@ nl_ctrl_err_t nl_ctrl_apply(const nl_light_change_t *c, uint32_t now_ms)
|
||||
else if (s_state.on && !n.on)
|
||||
dur = s_fade_out;
|
||||
else
|
||||
dur = 0;
|
||||
dur = s_transition;
|
||||
|
||||
s_state = n;
|
||||
nl_engine_set(&s_state, dur);
|
||||
|
||||
+11
-3
@@ -32,9 +32,17 @@ typedef enum {
|
||||
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);
|
||||
/* The engine must be initialised before. Not thread safe: callers serialise access.
|
||||
*
|
||||
* transition_ms: default transition applied to a color/brightness/CT change while the lamp
|
||||
* stays on and the caller did not send its own "transition" (fade_in/fade_out still take
|
||||
* precedence when the lamp is switching on or off).
|
||||
* wake_on_change: if true, a color/CT/brightness change arriving while the lamp is off
|
||||
* switches it on (using fade_in), unless the same call also says "on": false. */
|
||||
void nl_ctrl_init(const nl_board_t *board, uint16_t fade_in_ms, uint16_t fade_out_ms,
|
||||
uint16_t transition_ms, bool wake_on_change);
|
||||
void nl_ctrl_set_options(uint16_t fade_in_ms, uint16_t fade_out_ms, uint16_t transition_ms,
|
||||
bool wake_on_change);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user