Instead of using a state machine, the LED module operates as follows:
-
When the module receives a message on the
led_chanchannel, it performs the following steps:- Cancels any existing blink pattern.
- Saves the new LED state, which is the colors and the timing.
- Turns the LED on with the specified color.
-
When the message specifies a blinking pattern, which means that
repetitionsis not0, the module performs the following steps:- Starts a timer with
duration_on_msec. - Toggles the LED between the on and off states when the timer expires.
- Alternates the timer between
duration_on_msecandduration_off_msec. - Continues until the LED has blinked the specified number of repetitions.
- Starts a timer with
When repetitions is -1, the blinking continues indefinitely, or until the module receives a new message.
The module handles error cases gracefully and reports issues through logging.