mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-17 21:54:24 +01:00
track button state
This commit is contained in:
@@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user