8#include "roo_logging.h"
9#include "roo_scheduler.h"
26 enum Type { kSet, kHold, kFade };
28 constexpr RgbStep(Type type,
Color color, uint16_t duration_millis);
32 uint16_t duration_millis_;
38 void add(
RgbStep step) { sequence_.push_back(std::move(step)); }
41 std::vector<RgbStep> sequence_;
88 Color terminal_color);
92 roo_scheduler::SingletonTask stepper_;
93 std::vector<RgbStep> sequence_;
95 Color terminal_color_;
99 mutable roo::mutex mutex_;
101 bool fade_in_progress_;
102 Color fade_start_color_;
103 Color fade_target_color_;
104 roo_time::Uptime fade_start_time_;
105 roo_time::Uptime fade_end_time_;
110 int duty_percent = 50,
int rampup_percent_on = 0,
111 int rampup_percent_off = 0);
115constexpr RgbStep::RgbStep(Type type,
Color color, uint16_t duration_millis)
116 : type_(type), target_color_(color), duration_millis_(duration_millis) {}
119 return RgbStep(RgbStep::kSet, color, 0);
125 return RgbStep(RgbStep::kHold,
Color(), (uint16_t)duration.inMillis());
129 return RgbStep(RgbStep::kFade, color, (uint16_t)duration.inMillis());
Simple 24-bit RGB color value.
Sequence of steps for RGB blinking.
Runs blink sequences on an RGB LED.
void repeat(RgbBlinkSequence sequence, int repetitions, Color terminal_color=Color())
Repeats the sequence the specified number of times.
void setColor(Color color)
Enables the LED, setting it to the specified color.
void loop(RgbBlinkSequence sequence)
Repeats the sequence indefinitely.
void execute(RgbBlinkSequence sequence, Color terminal_color=Color())
Executes the sequence once.
void turnOff()
Disables the LED.
Abstract interface representing an RGB LED.
Single step of an RGB blink sequence.
friend constexpr RgbStep RgbSetTo(Color color)
Creates a step that sets the LED to the specified color instantly.
friend constexpr RgbStep RgbFadeOff(roo_time::Duration duration)
Creates a step that fades the LED off over the duration.
friend constexpr RgbStep RgbFadeTo(Color color, roo_time::Duration duration)
Creates a step that fades to the target color over the duration.
friend constexpr RgbStep RgbTurnOff()
Creates a step that disables the LED. Equivalent to RgbSetTo(Color()).
friend constexpr RgbStep RgbHold(roo_time::Duration duration)
Creates a step that holds the current color for the duration.
constexpr RgbStep RgbTurnOff()
Creates a step that disables the LED. Equivalent to RgbSetTo(Color()).
constexpr RgbStep RgbSetTo(Color color)
Creates a step that sets the LED to the specified color instantly.
constexpr RgbStep RgbFadeTo(Color color, roo_time::Duration duration)
Creates a step that fades to the target color over the duration.
constexpr RgbStep RgbHold(roo_time::Duration duration)
Creates a step that holds the current color for the duration.
RgbBlinkSequence RgbBlink(roo_time::Duration period, Color color, int duty_percent, int rampup_percent_on, int rampup_percent_off)
Creates a symmetric blink sequence with optional ramp-up/down segments.
constexpr RgbStep RgbFadeOff(roo_time::Duration duration)
Creates a step that fades the LED off over the duration.