Added flashing status mode to status led

This commit is contained in:
Christoffer Martinsson 2023-08-30 07:26:29 +02:00
parent d44e16d7fa
commit 3c2ab2c5e8

View File

@ -25,11 +25,14 @@ use ws2812_pio::Ws2812Direct;
pub enum StatusMode { pub enum StatusMode {
Off = 0, Off = 0,
Normal = 1, Normal = 1,
Activity = 2, NormalFlash = 2,
Other = 3, Activity = 3,
Warning = 4, ActivityFlash = 4,
Error = 5, Other = 5,
Bootloader = 6, OtherFlash = 6,
Warning = 7,
Error = 8,
Bootloader = 9,
} }
#[warn(dead_code)] #[warn(dead_code)]
@ -108,24 +111,46 @@ where
/// ///
/// Make sure to call this function regularly to keep the LED flashing /// Make sure to call this function regularly to keep the LED flashing
pub fn update(&mut self, mode: StatusMode) { pub fn update(&mut self, mode: StatusMode) {
let colors: [RGB8; 7] = [ let colors: [RGB8; 10] = [
(0, 0, 0).into(), // Off (0, 0, 0).into(), // Off
(10, 7, 0).into(), // Green (10, 7, 0).into(), // Green
(10, 7, 0).into(), // Green
(10, 4, 10).into(), // Blue (10, 4, 10).into(), // Blue
(10, 4, 10).into(), // Blue
(5, 10, 0).into(), // Orange
(5, 10, 0).into(), // Orange (5, 10, 0).into(), // Orange
(2, 20, 0).into(), // Red (2, 20, 0).into(), // Red
(2, 20, 0).into(), // Red (2, 20, 0).into(), // Red
(0, 10, 10).into(), // Purple (0, 10, 10).into(), // Purple
]; ];
self.mode = mode; if mode == StatusMode::Warning
|| mode == StatusMode::NormalFlash
|| mode == StatusMode::ActivityFlash
|| mode == StatusMode::OtherFlash
|| mode != self.mode
{
self.mode = mode;
} else {
return;
}
if mode == StatusMode::Warning && !self.state { if (mode == StatusMode::Warning
|| mode == StatusMode::NormalFlash
|| mode == StatusMode::ActivityFlash
|| mode == StatusMode::OtherFlash)
&& !self.state
{
self.ws2812_direct self.ws2812_direct
.write([colors[mode as usize]].iter().copied()) .write([colors[mode as usize]].iter().copied())
.unwrap(); .unwrap();
self.state = true; self.state = true;
} else if mode == StatusMode::Warning || mode == StatusMode::Off { } else if mode == StatusMode::Warning
|| mode == StatusMode::NormalFlash
|| mode == StatusMode::ActivityFlash
|| mode == StatusMode::OtherFlash
|| mode == StatusMode::Off
{
self.ws2812_direct self.ws2812_direct
.write([colors[0]].iter().copied()) .write([colors[0]].iter().copied())
.unwrap(); .unwrap();