#ifndef NL_CONTROL_H #define NL_CONTROL_H #include #include #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. * * 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); /* 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