From f7c643d7063ac12998ce780485620a15d923ad04 Mon Sep 17 00:00:00 2001 From: Vitalii Popov Date: Tue, 10 Feb 2026 02:42:21 +0200 Subject: [PATCH] ? --- src/main.rs | 95 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 36 deletions(-) diff --git a/src/main.rs b/src/main.rs index 951c930..919ed8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,10 +56,17 @@ pub enum TouchAction { Hold, } +#[derive(Copy, Clone, Eq, PartialEq, Format)] +pub enum AnimationSignal { + NextAnimation, + SetMode(T), + SetColor(u16), +} + static TOUCH_SIGNAL: Signal = Signal::new(); static RADAR_SIGNAL: Signal = Signal::new(); -static TEXT_ANIMATION_SIGNAL: Signal = Signal::new(); -static HEART_ANIMATION_SIGNAL: Signal = Signal::new(); +static TEXT_ANIMATION_SIGNAL: Signal> = Signal::new(); +static HEART_ANIMATION_SIGNAL: Signal> = Signal::new(); static SYS_ACTION: Mutex = Mutex::new(SysAction::PresentenceOn); static TEXT_ANIMATION: Mutex = Mutex::new(TextLightType::Hue); static HEART_ANIMATION: Mutex = Mutex::new(HeartLightType::HeartBeat); @@ -188,13 +195,15 @@ async fn gatt_task(server: Server, sd: &'static Softdevice) { 2 => TextLightType::White, _ => TextLightType::Hue, }; - TEXT_ANIMATION_SIGNAL.signal(next); + TEXT_ANIMATION_SIGNAL.signal(AnimationSignal::SetMode(next)); } AnimationServiceEvent::TextColorWrite(val) => { + let val = val % 1536; info!("wrote text color: {}", val); if let Err(e) = server.light.text_color_notify(&conn, &(val)) { info!("send notification error: {:?}", e); } + TEXT_ANIMATION_SIGNAL.signal(AnimationSignal::SetColor(val)); } AnimationServiceEvent::HeartModeWrite(val) => { let val = val % 3; @@ -208,13 +217,15 @@ async fn gatt_task(server: Server, sd: &'static Softdevice) { 2 => HeartLightType::ConstantColor, _ => HeartLightType::HeartBeat, }; - HEART_ANIMATION_SIGNAL.signal(next); + HEART_ANIMATION_SIGNAL.signal(AnimationSignal::SetMode(next)); } AnimationServiceEvent::HeartColorWrite(val) => { + let val = val % 1536; info!("wrote heart color: {}", val); if let Err(e) = server.light.heart_color_notify(&conn, &(val)) { info!("send notification error: {:?}", e); } + HEART_ANIMATION_SIGNAL.signal(AnimationSignal::SetColor(val)); } AnimationServiceEvent::TextModeCccdWrite { indications, @@ -330,39 +341,11 @@ async fn actions_task() { } // change text animation TouchAction::DoubleTap => { - let mut current = TEXT_ANIMATION.lock().await; - let next = match *current { - TextLightType::ConstantColor => { - TextLightType::White - } - TextLightType::Hue => { - TextLightType::ConstantColor - } - TextLightType::White => { - TextLightType::Hue - } - }; - *current = next; - info!("Set text to {:?}", next); - TEXT_ANIMATION_SIGNAL.signal(next); + TEXT_ANIMATION_SIGNAL.signal(AnimationSignal::NextAnimation); } // change anchor animation TouchAction::TripleTap => { - let mut current = HEART_ANIMATION.lock().await; - let next = match *current { - HeartLightType::ConstantColor => { - HeartLightType::Hue - } - HeartLightType::Hue => { - HeartLightType::HeartBeat - } - HeartLightType::HeartBeat => { - HeartLightType::ConstantColor - } - }; - info!("Set heart to {:?}", next); - *current = next; - HEART_ANIMATION_SIGNAL.signal(next); + HEART_ANIMATION_SIGNAL.signal(AnimationSignal::NextAnimation); } // enter pairing mode TouchAction::Hold => { @@ -455,7 +438,27 @@ async fn light_task(mut pwm: SimplePwm<'static>) { } if let Ok(val) = with_timeout(Duration::from_millis(10), TEXT_ANIMATION_SIGNAL.wait()).await { - animation_type = val; + match val { + AnimationSignal::NextAnimation => { + animation_type = match animation_type { + TextLightType::Hue => { + TextLightType::ConstantColor + } + TextLightType::ConstantColor => { + TextLightType::White + } + TextLightType::White => { + TextLightType::Hue + } + }; + } + AnimationSignal::SetMode(val) => { + animation_type = val; + } + AnimationSignal::SetColor(val) => { + hue = val; + } + } } match animation_type { TextLightType::Hue => { @@ -545,7 +548,27 @@ async fn heartbeat_task(mut pwm: SimplePwm<'static>) { } if let Ok(val) = with_timeout(Duration::from_millis(10), HEART_ANIMATION_SIGNAL.wait()).await { - animation_type = val; + match val { + AnimationSignal::NextAnimation => { + animation_type = match animation_type { + HeartLightType::HeartBeat => { + HeartLightType::ConstantColor + } + HeartLightType::ConstantColor => { + HeartLightType::Hue + } + HeartLightType::Hue => { + HeartLightType::HeartBeat + } + }; + } + AnimationSignal::SetMode(val) => { + animation_type = val; + } + AnimationSignal::SetColor(val) => { + hue = val; + } + } } match animation_type {