Added get_mode to status_led class

This commit is contained in:
Christoffer Martinsson 2023-08-09 18:07:05 +02:00
parent 86d2f8ea95
commit 2bb2c8c010

View File

@ -55,6 +55,7 @@ where
{ {
ws2812_direct: Ws2812Direct<P, SM, I>, ws2812_direct: Ws2812Direct<P, SM, I>,
state: bool, state: bool,
mode: StatusMode,
} }
impl<P, SM, I> Ws2812StatusLed<P, SM, I> impl<P, SM, I> Ws2812StatusLed<P, SM, I>
@ -81,12 +82,19 @@ where
// prepare the PIO program // prepare the PIO program
let ws2812_direct = Ws2812Direct::new(pin, pio, sm, clock_freq); let ws2812_direct = Ws2812Direct::new(pin, pio, sm, clock_freq);
let state = false; let state = false;
let mode = StatusMode::Off;
Self { Self {
ws2812_direct, ws2812_direct,
state, state,
mode,
} }
} }
/// Get current status mode
pub fn get_mode(&self) -> StatusMode {
self.mode
}
/// Update status LED /// Update status LED
/// Depending on the mode, the LED will be set to a different colour /// Depending on the mode, the LED will be set to a different colour
/// ///
@ -110,6 +118,8 @@ where
(0, 10, 10).into(), // Purple (0, 10, 10).into(), // Purple
]; ];
self.mode = mode;
if mode == StatusMode::Warning && !self.state { if mode == StatusMode::Warning && !self.state {
self.ws2812_direct self.ws2812_direct
.write([colors[mode as usize]].iter().copied()) .write([colors[mode as usize]].iter().copied())