use embedded_time::Timer;
use embedded_time::duration::Duration;
use embedded_time::fixed_point::FixedPoint;
use core::convert::TryFrom;
pub struct Delay<'a, Clock>
where Clock: embedded_time::Clock
{
clock: &'a Clock
}
impl<Clock> Clone for Delay<'_, Clock>
where Clock: embedded_time::Clock {
fn clone(&self) -> Self {
Self {
clock: self.clock,
}
}
}
impl<Clock> Copy for Delay<'_, Clock>
where Clock: embedded_time::Clock { }
impl<'a, Clock> Delay<'a, Clock>
where
Clock: embedded_time::Clock,
{
pub fn new(clock: &'a Clock) -> Self {
Self {
clock,
}
}
pub fn delay<Delay>(&self, delay: Delay)
where
Delay: Duration + FixedPoint,
Clock::T: TryFrom<Delay::T>,
{
let timer = Timer::new(self.clock, delay);
let timer = timer.start().unwrap();
timer.wait().unwrap();
}
}