track button state

This commit is contained in:
Evan Feenstra
2023-05-08 09:13:47 +01:00
parent 9b77aa2959
commit 35b7efeb96

View File

@@ -9,14 +9,21 @@ pub fn button_loop(gpio8: gpio::Gpio8, tx: mpsc::Sender<Status>) {
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!");
}
}
}
});