Skip to content

Commit

Permalink
Support boards without button or LED for reboot example (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 authored Dec 4, 2023
1 parent 3f749e1 commit 0b91a03
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions examples/rust/reboot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ use wasefire::sync::AtomicBool;
use wasefire::sync::Ordering::Relaxed;

fn main() -> ! {
debug!("Waiting 5 seconds...");
blink(Duration::from_secs(5));
blink(5);
press();
blink(3);
debug!("Rebooting...");
platform::reboot();
}

fn press() {
if button::count() == 0 {
debug!("Not waiting for button press because there are no buttons.");
return;
}
debug!("Waiting for a button press to reboot...");
static PRESSED: AtomicBool = AtomicBool::new(false);
let button = button::Listener::new(0, |event| match event {
Expand All @@ -31,13 +41,15 @@ fn main() -> ! {
});
scheduling::wait_until(|| PRESSED.load(Relaxed));
drop(button);
debug!("Waiting 3 seconds...");
blink(Duration::from_secs(3));
debug!("Rebooting...");
platform::reboot();
}

fn blink(duration: Duration) {
fn blink(seconds: u64) {
debug!("Waiting {seconds} seconds...");
let duration = Duration::from_secs(seconds);
if led::count() == 0 {
clock::sleep(duration);
return;
}
led::set(0, led::On);
let blink = clock::Timer::new(|| led::set(0, !led::get(0)));
blink.start(clock::Periodic, Duration::from_millis(300));
Expand Down

0 comments on commit 0b91a03

Please sign in to comment.