From 343b14db5b9ad66ad9bda177b5d3bc4ef26e0374 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 31 Oct 2017 00:04:52 -0400 Subject: support continous press --- rom | Bin 11408 -> 13232 bytes src/main.rs | 345 +++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 235 insertions(+), 110 deletions(-) diff --git a/rom b/rom index 84409b4..8907f04 100755 Binary files a/rom and b/rom differ diff --git a/src/main.rs b/src/main.rs index d162e2e..161c987 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,7 +61,7 @@ struct Time { hr: u8, } -#[derive(PartialEq, Clone, Copy)] +#[derive(Clone, Copy)] enum DispState { On, Off, @@ -86,22 +86,24 @@ struct GlobalState<'a> { blink_state: Cell, blinky_enabled: Cell>, pidx: usize, - panels: [&'a Panel; 6], + panels: [&'a Panel<'a>; 6], } -#[derive(PartialEq, Clone, Copy)] +#[derive(Clone, Copy)] enum ButtonState { Idle, PressedLock, PressedUnlock, - ReleaseLock + ReleaseLock, + Continous } struct Button<'a> { state: Cell, long: Cell, events: &'a AlarmEventManager<'a>, - ev_id: Cell + ev_id: Cell, + cont: Cell } enum ButtonResult { @@ -110,11 +112,34 @@ enum ButtonResult { LongPress } -trait Panel { +trait Panel<'a> { + fn btn1_press(&'a self) -> bool { + self.get_gs().btn1.as_ref().unwrap().press(false); + true + } + + fn btn1_release_extra(&self) {} + + fn btn1_release(&'a self) -> bool { + self.btn1_release_extra(); + let gs = self.get_gs(); + let btn1 = gs.btn1.as_ref().unwrap(); + match btn1.release() { + ButtonResult::FalseAlarm => true, + ButtonResult::ShortPress => self.btn1_short(), + ButtonResult::LongPress => { + gs.disp_state.set(DispState::Off); + gs.tempon_cnt.set(gs.tempon_cycle.get()); + true + } + } + } + fn btn1_short(&self) -> bool {false} fn btn1_long(&self) -> bool {false} fn btn2_short(&self) -> bool {false} fn btn2_long(&self) -> bool {false} + fn get_gs(&'a self) -> &GlobalState<'a>; fn update_output(&self); } @@ -122,7 +147,7 @@ trait Timeoutable<'a> { fn timeout(&'a self); } -#[derive(PartialEq, Clone, Copy)] +#[derive(Clone, Copy)] enum TimePanelState { Inactive, View, @@ -135,7 +160,8 @@ struct TimePanel<'a> { gs: &'a GlobalState<'a>, state: Cell, time: RefCell