This commit is contained in:
Vitalii 2026-02-10 02:42:21 +02:00
parent f55d8d4bd2
commit f7c643d706
Signed by: SymbX
GPG Key ID: FF51F4E4BCE459EE
1 changed files with 59 additions and 36 deletions

View File

@ -56,10 +56,17 @@ pub enum TouchAction {
Hold, Hold,
} }
#[derive(Copy, Clone, Eq, PartialEq, Format)]
pub enum AnimationSignal<T> {
NextAnimation,
SetMode(T),
SetColor(u16),
}
static TOUCH_SIGNAL: Signal<ThreadModeRawMutex, TouchAction> = Signal::new(); static TOUCH_SIGNAL: Signal<ThreadModeRawMutex, TouchAction> = Signal::new();
static RADAR_SIGNAL: Signal<ThreadModeRawMutex, u8> = Signal::new(); static RADAR_SIGNAL: Signal<ThreadModeRawMutex, u8> = Signal::new();
static TEXT_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, TextLightType> = Signal::new(); static TEXT_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, AnimationSignal<TextLightType>> = Signal::new();
static HEART_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, HeartLightType> = Signal::new(); static HEART_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, AnimationSignal<HeartLightType>> = Signal::new();
static SYS_ACTION: Mutex<ThreadModeRawMutex, SysAction> = Mutex::new(SysAction::PresentenceOn); static SYS_ACTION: Mutex<ThreadModeRawMutex, SysAction> = Mutex::new(SysAction::PresentenceOn);
static TEXT_ANIMATION: Mutex<ThreadModeRawMutex, TextLightType> = Mutex::new(TextLightType::Hue); static TEXT_ANIMATION: Mutex<ThreadModeRawMutex, TextLightType> = Mutex::new(TextLightType::Hue);
static HEART_ANIMATION: Mutex<ThreadModeRawMutex, HeartLightType> = Mutex::new(HeartLightType::HeartBeat); static HEART_ANIMATION: Mutex<ThreadModeRawMutex, HeartLightType> = Mutex::new(HeartLightType::HeartBeat);
@ -188,13 +195,15 @@ async fn gatt_task(server: Server, sd: &'static Softdevice) {
2 => TextLightType::White, 2 => TextLightType::White,
_ => TextLightType::Hue, _ => TextLightType::Hue,
}; };
TEXT_ANIMATION_SIGNAL.signal(next); TEXT_ANIMATION_SIGNAL.signal(AnimationSignal::SetMode(next));
} }
AnimationServiceEvent::TextColorWrite(val) => { AnimationServiceEvent::TextColorWrite(val) => {
let val = val % 1536;
info!("wrote text color: {}", val); info!("wrote text color: {}", val);
if let Err(e) = server.light.text_color_notify(&conn, &(val)) { if let Err(e) = server.light.text_color_notify(&conn, &(val)) {
info!("send notification error: {:?}", e); info!("send notification error: {:?}", e);
} }
TEXT_ANIMATION_SIGNAL.signal(AnimationSignal::SetColor(val));
} }
AnimationServiceEvent::HeartModeWrite(val) => { AnimationServiceEvent::HeartModeWrite(val) => {
let val = val % 3; let val = val % 3;
@ -208,13 +217,15 @@ async fn gatt_task(server: Server, sd: &'static Softdevice) {
2 => HeartLightType::ConstantColor, 2 => HeartLightType::ConstantColor,
_ => HeartLightType::HeartBeat, _ => HeartLightType::HeartBeat,
}; };
HEART_ANIMATION_SIGNAL.signal(next); HEART_ANIMATION_SIGNAL.signal(AnimationSignal::SetMode(next));
} }
AnimationServiceEvent::HeartColorWrite(val) => { AnimationServiceEvent::HeartColorWrite(val) => {
let val = val % 1536;
info!("wrote heart color: {}", val); info!("wrote heart color: {}", val);
if let Err(e) = server.light.heart_color_notify(&conn, &(val)) { if let Err(e) = server.light.heart_color_notify(&conn, &(val)) {
info!("send notification error: {:?}", e); info!("send notification error: {:?}", e);
} }
HEART_ANIMATION_SIGNAL.signal(AnimationSignal::SetColor(val));
} }
AnimationServiceEvent::TextModeCccdWrite { AnimationServiceEvent::TextModeCccdWrite {
indications, indications,
@ -330,39 +341,11 @@ async fn actions_task() {
} }
// change text animation // change text animation
TouchAction::DoubleTap => { TouchAction::DoubleTap => {
let mut current = TEXT_ANIMATION.lock().await; TEXT_ANIMATION_SIGNAL.signal(AnimationSignal::NextAnimation);
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);
} }
// change anchor animation // change anchor animation
TouchAction::TripleTap => { TouchAction::TripleTap => {
let mut current = HEART_ANIMATION.lock().await; HEART_ANIMATION_SIGNAL.signal(AnimationSignal::NextAnimation);
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);
} }
// enter pairing mode // enter pairing mode
TouchAction::Hold => { 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 { 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 { match animation_type {
TextLightType::Hue => { 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 { 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 { match animation_type {