Skip to main content

rmk_q1_pro_iso/backlight/
lock_indicator.rs

1use rmk::{
2    channel::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel},
3    event::LedIndicatorEvent,
4    macros::processor,
5};
6
7/// Channel used to send backlight indicator commands.
8pub static BACKLIGHT_CH: Channel<CriticalSectionRawMutex, BacklightCmd, 4> = Channel::new();
9
10#[derive(Copy, Clone)]
11/// Commands for lock indicator LEDs.
12pub enum BacklightCmd {
13    /// Update caps/num lock indicator states.
14    Indicators {
15        /// Whether Caps Lock is active.
16        caps: bool,
17    },
18}
19
20#[processor(subscribe = [LedIndicatorEvent])]
21/// Controller that reacts to indicator events for the LED driver.
22pub struct LedIndicatorProcessor;
23
24impl LedIndicatorProcessor {
25    /// Create a new indicator controller.
26    pub const fn new() -> Self { Self }
27
28    /// Handle incoming lock LED indicator events.
29    async fn on_led_indicator_event(&self, event: LedIndicatorEvent) {
30        let caps = event.indicator.caps_lock();
31
32        BACKLIGHT_CH.sender().send(BacklightCmd::Indicators { caps }).await;
33    }
34}