use std::time::Duration;
use super::quaternion::Quaternion;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum MotionClock {
BootTime,
SystemUptime,
PerformanceNow,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum MotionReference {
#[default]
ArbitraryHeading,
MagneticNorth,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum MotionRate {
#[default]
Fastest,
Period(Duration),
}
impl MotionRate {
pub const fn period(self) -> Option<Duration> {
match self {
Self::Fastest => None,
Self::Period(period) => Some(period),
}
}
pub fn or_faster(self, other: Self) -> Self {
match (self, other) {
(Self::Period(a), Self::Period(b)) => Self::Period(a.min(b)),
_ => Self::Fastest,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum DisplayRotation {
#[default]
Rotation0,
Rotation90,
Rotation180,
Rotation270,
}
impl DisplayRotation {
pub const fn from_degrees(degrees: i32) -> Self {
match degrees.rem_euclid(360) / 90 {
1 => Self::Rotation90,
2 => Self::Rotation180,
3 => Self::Rotation270,
_ => Self::Rotation0,
}
}
pub const fn from_quarter_turns(turns: i32) -> Self {
Self::from_degrees(turns.wrapping_mul(90))
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct MotionConfig {
pub reference: MotionReference,
pub rate: MotionRate,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MotionSample {
pub rotation: Quaternion,
pub timestamp_ns: u64,
pub clock: MotionClock,
pub reference: MotionReference,
pub index: u64,
}