From d815507bcc6ad5ded9c0ecff8f334ef2ec009b49 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Wed, 5 Nov 2025 12:14:21 -0700 Subject: [PATCH] add main button press handling --- ch32v-insert-coin/src/app.rs | 9 ++++++++- ch32v-insert-coin/src/main.rs | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ch32v-insert-coin/src/app.rs b/ch32v-insert-coin/src/app.rs index e1c9bf8..03800fa 100644 --- a/ch32v-insert-coin/src/app.rs +++ b/ch32v-insert-coin/src/app.rs @@ -381,8 +381,15 @@ impl App { #[cfg(feature = "enable_print")] println!("new brightness: {:?}", self.settings.brightness); } - pub fn main_button(&mut self) { + pub fn main_button_press(&mut self) { // TODO + #[cfg(feature = "enable_print")] + println!("main button press"); + } + pub fn main_button_release(&mut self) { + // TODO + #[cfg(feature = "enable_print")] + println!("main button release"); } pub fn coin_detect(&self) { #[cfg(feature = "enable_print")] diff --git a/ch32v-insert-coin/src/main.rs b/ch32v-insert-coin/src/main.rs index d8c1cc3..34d5222 100644 --- a/ch32v-insert-coin/src/main.rs +++ b/ch32v-insert-coin/src/main.rs @@ -408,6 +408,30 @@ fn app_main(mut p: hal::Peripherals) -> ! { } } + // main button handling + unsafe { + #[allow(static_mut_refs)] + if INPUT_FLAGS.main_btn_flag.active() { + #[cfg(feature = "enable_print")] + println!("button flag active"); + #[allow(static_mut_refs)] + INPUT_FLAGS.main_btn_flag.clear(); + main_btn_input.begin(); + } + } + main_btn_input.service(); + if main_btn_input.ready() { + let value = main_btn_input.value(); + main_btn_input.reset(); + // #[cfg(feature = "enable_print")] + // println!("main button", value); + + match value { + true => app.main_button_release(), + false => app.main_button_press(), + } + } + // systick tick if unsafe { #[allow(static_mut_refs)]