#[async_trait::async_trait]
pub trait WatchdogPlatform: Send {
async fn on_timeout(&mut self);
async fn read_and_clear_boot_status(&mut self) -> bool;
}
pub struct SimpleWatchdogPlatform {
watchdog_status: bool,
cb: Box<dyn Fn() + Send + Sync>,
}
impl SimpleWatchdogPlatform {
pub fn new(on_timeout: Box<dyn Fn() + Send + Sync>) -> Self {
SimpleWatchdogPlatform {
watchdog_status: false,
cb: on_timeout,
}
}
}
#[async_trait::async_trait]
impl WatchdogPlatform for SimpleWatchdogPlatform {
async fn on_timeout(&mut self) {
self.watchdog_status = true;
(self.cb)()
}
async fn read_and_clear_boot_status(&mut self) -> bool {
if self.watchdog_status {
self.watchdog_status = false;
}
self.watchdog_status
}
}