From 35b7efeb96ffece367499111b8200d578181f298 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Mon, 8 May 2023 09:13:47 +0100 Subject: [PATCH] track button state --- sphinx-key/src/periph/button.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sphinx-key/src/periph/button.rs b/sphinx-key/src/periph/button.rs index e2ebb84..08749ee 100644 --- a/sphinx-key/src/periph/button.rs +++ b/sphinx-key/src/periph/button.rs @@ -9,14 +9,21 @@ pub fn button_loop(gpio8: gpio::Gpio8, tx: mpsc::Sender) { thread::spawn(move || { let mut button = PinDriver::input(gpio8).unwrap(); button.set_pull(Pull::Down).unwrap(); + let mut high = false; loop { // we are using thread::sleep here to make sure the watchdog isn't triggered - thread::sleep(Duration::from_millis(10)); + thread::sleep(Duration::from_millis(15)); if button.is_high() { - log::info!("=> GPIO8 HIGH!"); + if !high { + high = true; + log::info!("=> GPIO8 HIGH!"); + } tx.send(Status::Reset1).unwrap(); } else { - log::info!("=> GPIO8 LOW!"); + if high { + high = false; + log::info!("=> GPIO8 LOW!"); + } } } });