16#include <zephyr/types.h>
17#include <zephyr/sys/util.h>
23#define _CAF_LED_COLOR_CHANNEL_COUNT 3
29 uint8_t
c[_CAF_LED_COLOR_CHANNEL_COUNT];
68#define COLOR_BRIGHTNESS_TO_PCT(_val) ((_val * 100) / UINT8_MAX)
83#define LED_COLOR_ARG_PASS(...) __VA_ARGS__
96#define LED_COLOR(_r, _g, _b) { \
98 COLOR_BRIGHTNESS_TO_PCT(_r), \
99 COLOR_BRIGHTNESS_TO_PCT(_g), \
100 COLOR_BRIGHTNESS_TO_PCT(_b) \
106#define LED_NOCOLOR() { \
116#define LED_EFFECT_LED_ON(_color) \
118 .steps = ((const struct led_effect_step[]) { \
121 .substep_count = 1, \
126 .loop_forever = false, \
132#define LED_EFFECT_LED_OFF() LED_EFFECT_LED_ON(LED_NOCOLOR())
143#define LED_EFFECT_LED_ON_GO_OFF(_color, _on_time, _off_delay) \
145 .steps = ((const struct led_effect_step[]) { \
148 .substep_count = 1, \
153 .substep_count = 1, \
154 .substep_time = (_on_time), \
157 .color = LED_NOCOLOR(), \
158 .substep_count = (_off_delay)/10, \
159 .substep_time = 10, \
163 .loop_forever = false, \
178#define LED_EFFECT_LED_BLINK2(_period_on, _period_off, _color) \
180 .steps = ((const struct led_effect_step[]) { \
183 .substep_count = 1, \
184 .substep_time = (_period_off), \
187 .color = LED_NOCOLOR(), \
188 .substep_count = 1, \
189 .substep_time = (_period_on), \
193 .loop_forever = true, \
207#define LED_EFFECT_LED_BLINK(_period, _color) \
208 LED_EFFECT_LED_BLINK2(_period, _period, LED_COLOR_ARG_PASS(_color))
214#define _BREATH_SUBSTEPS 15
224#define LED_EFFECT_LED_BREATH(_period, _color) \
226 .steps = ((const struct led_effect_step[]) { \
229 .substep_count = _BREATH_SUBSTEPS, \
230 .substep_time = ((_period + (_BREATH_SUBSTEPS - 1)) \
231 / _BREATH_SUBSTEPS), \
235 .substep_count = 1, \
236 .substep_time = _period, \
239 .color = LED_NOCOLOR(), \
240 .substep_count = _BREATH_SUBSTEPS, \
241 .substep_time = ((_period + (_BREATH_SUBSTEPS - 1)) \
242 / _BREATH_SUBSTEPS), \
245 .color = LED_NOCOLOR(), \
246 .substep_count = 1, \
247 .substep_time = _period, \
251 .loop_forever = true, \
259#define LED_CLOCK_BLINK_PERIOD 200
265#define LED_CLOCK_SLEEP_PERIOD 1000
275#define _LED_CLOCK_TIK(i, ...) \
277 .color = __VA_ARGS__, \
278 .substep_count = 1, \
279 .substep_time = LED_CLOCK_BLINK_PERIOD, \
282 .color = LED_NOCOLOR(), \
283 .substep_count = 1, \
284 .substep_time = LED_CLOCK_BLINK_PERIOD, \
298#define LED_EFFECT_LED_CLOCK(_ticks, _color) \
300 .steps = ((const struct led_effect_step[]) { \
302 .color = LED_NOCOLOR(), \
303 .substep_count = 1, \
304 .substep_time = LED_CLOCK_SLEEP_PERIOD, \
306 LISTIFY(_ticks, _LED_CLOCK_TIK, (,), _color) \
308 .step_count = (2 * _ticks + 1), \
309 .loop_forever = true, \
uint8_t c[3]
Definition: led_effect.h:29
Color of LED.
Definition: led_effect.h:27
struct led_color color
Definition: led_effect.h:40
uint16_t substep_count
Definition: led_effect.h:43
uint16_t substep_time
Definition: led_effect.h:46
Single step of a LED effect.
Definition: led_effect.h:38
uint16_t step_count
Definition: led_effect.h:56
const struct led_effect_step * steps
Definition: led_effect.h:53
bool loop_forever
Definition: led_effect.h:59
Single LED effect.
Definition: led_effect.h:51