use esp_idf_svc::timer::{EspTimer, EspTimerService, Task};
use std::time::Duration;
pub struct Timer<'a> {
_timsvc: EspTimerService<Task>,
_tim: EspTimer<'a>,
}
impl<'a> Timer<'a> {
pub fn new<F>(callback: F, period: Duration) -> Self
where
F: FnMut() + Send + 'a,
{
let timsvc = EspTimerService::new().expect("Failed to create system timer service.");
let tim = timsvc
.timer(callback)
.expect("Failed to create system timer.");
tim.every(period).expect("Failed to start system timer.");
Self {
_timsvc: timsvc,
_tim: tim,
}
}
}