From 5aa56a244d0ea7f4563d22a0a5ef89613cfeb6fb Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Wed, 5 Nov 2025 14:26:50 -0700 Subject: [PATCH] add click, short, and long press handling / detection --- ch32v-insert-coin/src/app.rs | 32 +++++++++++++++++++ .../src/insert_coin/services/tick_timer.rs | 13 +++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/ch32v-insert-coin/src/app.rs b/ch32v-insert-coin/src/app.rs index a50aad7..a5d573b 100644 --- a/ch32v-insert-coin/src/app.rs +++ b/ch32v-insert-coin/src/app.rs @@ -396,6 +396,19 @@ impl App { // TODO #[cfg(feature = "enable_print")] println!("main button release"); + match ( + self.timers.sp_timer.is_enabled(), + self.timers.lp_timer.is_enabled(), + ) { + // click + (true, true) => self.main_button_click(), + // short press + (false, true) => self.main_button_short_press(), + // long press + (false, false) => self.main_button_long_press(), + // anything else is not possible + _ => {} + } self.timers.sp_timer.reset(); self.timers.lp_timer.reset(); } @@ -406,6 +419,25 @@ impl App { } } +// Events +impl App { + fn main_button_click(&self) { + // TODO + #[cfg(feature = "enable_print")] + println!("click"); + } + fn main_button_short_press(&self) { + // TODO + #[cfg(feature = "enable_print")] + println!("short press"); + } + fn main_button_long_press(&self) { + // TODO + #[cfg(feature = "enable_print")] + println!("long press"); + } +} + // TODO LIST // // AUDIO: diff --git a/ch32v-insert-coin/src/insert_coin/services/tick_timer.rs b/ch32v-insert-coin/src/insert_coin/services/tick_timer.rs index a10ab74..863314a 100644 --- a/ch32v-insert-coin/src/insert_coin/services/tick_timer.rs +++ b/ch32v-insert-coin/src/insert_coin/services/tick_timer.rs @@ -1,4 +1,4 @@ -use crate::insert_coin::services::{TickServiceData, TickService}; +use crate::insert_coin::services::{TickService, TickServiceData}; pub struct TickTimerService { service_data: core::cell::RefCell, @@ -15,22 +15,21 @@ impl TickTimerService { } } - // pub fn is_enabled(&self) -> bool { - // self.enabled - // } + pub fn is_enabled(&self) -> bool { + self.enabled + } pub fn reset(&mut self) { let mut sd = self.service_data.borrow_mut(); sd.ticks_remaining = sd.ticks_per_service; self.enabled = false; - } + } pub fn enable(&mut self, enable: bool) { self.enabled = enable; } } - impl TickService for TickTimerService { fn tick(&self) { if self.enabled { @@ -48,5 +47,3 @@ impl TickService for TickTimerService { tc.ticks_remaining = tc.ticks_per_service; } } - -