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,
}
#[derive(Copy, Clone, Eq, PartialEq, Format)]
pub enum AnimationSignal<T> {
NextAnimation,
SetMode(T),
SetColor(u16),
}
static TOUCH_SIGNAL: Signal<ThreadModeRawMutex, TouchAction> = Signal::new();
static RADAR_SIGNAL: Signal<ThreadModeRawMutex, u8> = Signal::new();
static TEXT_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, TextLightType> = Signal::new();
static HEART_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, HeartLightType> = Signal::new();
static TEXT_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, AnimationSignal<TextLightType>> = Signal::new();
static HEART_ANIMATION_SIGNAL: Signal<ThreadModeRawMutex, AnimationSignal<HeartLightType>> = Signal::new();
static SYS_ACTION: Mutex<ThreadModeRawMutex, SysAction> = Mutex::new(SysAction::PresentenceOn);
static TEXT_ANIMATION: Mutex<ThreadModeRawMutex, TextLightType> = Mutex::new(TextLightType::Hue);
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,
_ => 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,8 +438,28 @@ async fn light_task(mut pwm: SimplePwm<'static>) {
}
if let Ok(val) = with_timeout(Duration::from_millis(10), TEXT_ANIMATION_SIGNAL.wait()).await {
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 => {
let (r, g, b) = hue_to_rgb(hue, MAX_DUTY);
@ -545,8 +548,28 @@ async fn heartbeat_task(mut pwm: SimplePwm<'static>) {
}
if let Ok(val) = with_timeout(Duration::from_millis(10), HEART_ANIMATION_SIGNAL.wait()).await {
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 {
HeartLightType::ConstantColor => {