add click, short, and long press handling / detection

This commit is contained in:
sigil-03 2025-11-05 14:26:50 -07:00
parent 2d8e2ce6ee
commit 5aa56a244d
2 changed files with 37 additions and 8 deletions

View file

@ -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:

View file

@ -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<TickServiceData>,
@ -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;
}
}