pub trait Clock {
// Required method
fn timestamp_ns(&self) -> i64;
}
Expand description
The BSEC algorithem needs a clock capable of providing timestamps. Implement this trait according to your hardware platform.
Example
A possible implementation based on std::time
could look like this:
use bsec::clock::Clock;
use std::time::{Duration, Instant};
pub struct TimePassed {
start: Instant,
}
impl TimePassed {
fn new() -> Self {
Self { start: Instant::now() }
}
}
impl Clock for TimePassed {
fn timestamp_ns(&self) -> i64 {
self.start.elapsed().as_nanos() as i64
}
}
Required Methods§
sourcefn timestamp_ns(&self) -> i64
fn timestamp_ns(&self) -> i64
Return a monotonically increasing timestamp with nanosecond resolution.
The reference point may be arbitrary.