8#include "roo_logging.h"
9#include "roo_scheduler.h"
10#include "roo_threads.h"
20 friend constexpr Step FadeOn(roo_time::Duration duration);
21 friend constexpr Step FadeOff(roo_time::Duration duration);
23 friend constexpr Step SetTo(uint16_t level);
24 friend constexpr Step FadeTo(uint16_t level, roo_time::Duration duration);
25 friend constexpr Step Hold(roo_time::Duration duration);
30 enum Type { kSet, kHold, kFade };
32 constexpr Step(Type type, uint16_t target_level, uint16_t duration_millis);
35 uint16_t target_level_;
36 uint16_t duration_millis_;
42 void add(
Step step) { sequence_.push_back(std::move(step)); }
45 std::vector<Step> sequence_;
60constexpr Step FadeTo(uint16_t level, roo_time::Duration duration);
63constexpr Step FadeOn(roo_time::Duration duration);
69constexpr Step Hold(roo_time::Duration duration);
78 Blinker(
Led& led, roo_scheduler::Scheduler& scheduler);
85 uint16_t terminal_level = 0);
91 void set(uint16_t intensity);
101 uint16_t terminal_level);
105 roo_scheduler::SingletonTask stepper_;
106 std::vector<Step> sequence_;
107 uint16_t current_level_;
108 uint16_t terminal_level_;
112 mutable roo::mutex mutex_;
115 bool fade_in_progress_;
116 uint16_t fade_start_level_;
117 uint16_t fade_target_level_;
118 roo_time::Uptime fade_start_time_;
119 roo_time::Uptime fade_end_time_;
124 int rampup_percent_on = 0,
int rampup_percent_off = 0);
128constexpr Step::Step(Type type, uint16_t target_level, uint16_t duration_millis)
130 target_level_(target_level),
131 duration_millis_(duration_millis) {}
138constexpr Step FadeTo(uint16_t level, roo_time::Duration duration) {
139 return Step(Step::kFade, level, (uint16_t)duration.inMillis());
143 return FadeTo(65535, duration);
147 return FadeTo(0, duration);
151 return Step(Step::kHold, 0, (uint16_t)duration.inMillis());
Sequence of steps for monochrome blinking.
Runs blink sequences on a monochrome LED.
void loop(BlinkSequence sequence)
Repeats the sequence indefinitely.
void execute(BlinkSequence sequence, uint16_t terminal_level=0)
Executes the sequence once.
void turnOff()
Disables the LED.
void turnOn()
Enables the LED at the maximum intensity.
void repeat(BlinkSequence sequence, int repetitions, uint16_t terminal_level=0)
Repeats the sequence the specified number of times.
void set(uint16_t intensity)
Enables the LED at the specified intensity.
Abstract interface representing a monochrome LED.
Single step of a monochrome blink sequence.
friend constexpr Step FadeOff(roo_time::Duration duration)
Creates a step that fades linearly down to off over the duration.
friend constexpr Step Hold(roo_time::Duration duration)
Creates a step that maintains the current brightness for the duration.
friend constexpr Step FadeTo(uint16_t level, roo_time::Duration duration)
Creates a step that fades linearly to the target level over the duration.
friend constexpr Step TurnOff()
Creates a step that sets the LED to completely off instantly.
friend constexpr Step TurnOn()
Creates a step that sets the LED to the maximum brightness instantly.
friend constexpr Step FadeOn(roo_time::Duration duration)
Creates a step that fades linearly to the maximum brightness over duration.
friend constexpr Step SetTo(uint16_t level)
Creates a step that sets the LED to the specified brightness instantly.
constexpr Step FadeOn(roo_time::Duration duration)
Creates a step that fades linearly to the maximum brightness over duration.
constexpr Step SetTo(uint16_t level)
Creates a step that sets the LED to the specified brightness instantly.
constexpr Step TurnOff()
Creates a step that sets the LED to completely off instantly.
constexpr Step FadeOff(roo_time::Duration duration)
Creates a step that fades linearly down to off over the duration.
constexpr Step FadeTo(uint16_t level, roo_time::Duration duration)
Creates a step that fades linearly to the target level over the duration.
constexpr Step Hold(roo_time::Duration duration)
Creates a step that maintains the current brightness for the duration.
constexpr Step TurnOn()
Creates a step that sets the LED to the maximum brightness instantly.
BlinkSequence Blink(roo_time::Duration period, int duty_percent, int rampup_percent_on, int rampup_percent_off)
Creates a symmetric blink sequence with optional ramp-up/down segments.