This commit is contained in:
parent
f55d8d4bd2
commit
f7c643d706
95
src/main.rs
95
src/main.rs
|
|
@ -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,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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue