Skip to main content

Module animation

Module animation 

Source
Expand description

LED animation task.

Reads the current [hsm_firmware_logic::TokenState] off crate::channels::TOKEN_STATE and drives the green (GP16) and yellow (GP17) LEDs at the cadence dictated by the state’s [hsm_firmware_logic::LedPattern].

The task runs an infinite loop with two interleaved concerns:

  1. Apply the current pattern. Each pattern has a tick interval and a per-tick action (toggle green, toggle yellow, alternate, etc). The task sleeps for the tick interval, then performs the action.
  2. React to state changes promptly. Sleeping for a 500 ms tick would make a transition into Error invisible for half a second. To avoid that, the task races the tick timer against crate::channels::TOKEN_STATE using embassy_futures::select. Whichever fires first wins.

Β§Testability

The actual driving logic lives in apply_pattern, which is generic over the [Led] trait. The embassy task wrapper animation_task is a thin shell that supplies real Output<'static> values; host-side tests instantiate apply_pattern directly with mock LEDs to assert on transition counts.

ConstantsΒ§

ALTERNATE_INTERVAL πŸ”’
Tick interval for the alternate-both pattern (5 Hz).
FAST_BLINK_INTERVAL πŸ”’
Tick interval for the fast blink pattern (5 Hz).
SLOW_PULSE_INTERVAL πŸ”’
Tick interval for the slow pulse pattern (green, 1 Hz).
YELLOW_BLINK_INTERVAL πŸ”’
Tick interval for the yellow blink pattern (2 Hz).

FunctionsΒ§

animation_task πŸ”’
Drive the LEDs based on the current operating state. Spawn once at boot.
apply_pattern πŸ”’
Apply one tick of pattern to the LEDs and return the duration to wait before the next tick.