#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Orientation {
XUp,
XDown,
YUp,
YDown,
ZUp,
ZDown,
#[default]
Unknown,
}
impl Orientation {
pub fn gravity_vector(self) -> (f32, f32, f32) {
match self {
Orientation::XUp => (1.0, 0.0, 0.0),
Orientation::XDown => (-1.0, 0.0, 0.0),
Orientation::YUp => (0.0, 1.0, 0.0),
Orientation::YDown => (0.0, -1.0, 0.0),
Orientation::ZUp => (0.0, 0.0, 1.0),
Orientation::ZDown => (0.0, 0.0, -1.0),
Orientation::Unknown => (0.0, 0.0, 0.0),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[must_use]
pub struct GForce(f32);
impl GForce {
pub const fn new(value: f32) -> Self {
Self(value)
}
pub const fn as_f32(self) -> f32 {
self.0
}
pub fn to_meters_per_second_squared(self) -> f32 {
self.0 * 9.80665
}
}
impl From<GForce> for f32 {
fn from(g: GForce) -> Self {
g.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[must_use]
pub struct Gauss(f32);
impl Gauss {
pub const fn new(value: f32) -> Self {
Self(value)
}
pub const fn as_f32(self) -> f32 {
self.0
}
pub fn to_tesla(self) -> f32 {
self.0 * 0.0001
}
pub fn to_microtesla(self) -> f32 {
self.0 * 100.0
}
}
impl From<Gauss> for f32 {
fn from(g: Gauss) -> Self {
g.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[must_use]
pub struct DegreesPerSecond(f32);
impl DegreesPerSecond {
pub const fn new(value: f32) -> Self {
Self(value)
}
pub const fn as_f32(self) -> f32 {
self.0
}
pub fn to_radians_per_second(self) -> f32 {
self.0 * core::f32::consts::PI / 180.0
}
}
impl From<DegreesPerSecond> for f32 {
fn from(dps: DegreesPerSecond) -> Self {
dps.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[must_use]
pub struct Celsius(f32);
impl Celsius {
pub const fn new(value: f32) -> Self {
Self(value)
}
pub const fn as_f32(self) -> f32 {
self.0
}
pub fn to_fahrenheit(self) -> f32 {
self.0 * 9.0 / 5.0 + 32.0
}
pub fn to_kelvin(self) -> f32 {
self.0 + 273.15
}
}
impl From<Celsius> for f32 {
fn from(c: Celsius) -> Self {
c.0
}
}
#[derive(Debug, Clone, Copy, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[must_use]
pub struct SensorData {
pub gyro: (DegreesPerSecond, DegreesPerSecond, DegreesPerSecond),
pub accel: (GForce, GForce, GForce),
pub mag: (Gauss, Gauss, Gauss),
pub temp: Celsius,
}
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[must_use]
pub struct SelfTestResult {
pub gyro_passed: bool,
pub gyro_delta: (f32, f32, f32),
pub accel_passed: bool,
pub accel_delta: (f32, f32, f32),
}