Moved types into seperate library
This commit is contained in:
81
src/lib.rs
81
src/lib.rs
@@ -1,81 +0,0 @@
|
||||
#![no_std]
|
||||
|
||||
use core::fmt::Debug;
|
||||
|
||||
use bme280::Measurements;
|
||||
use defmt::Format;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Format, PartialEq, Clone, Copy, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum FanSpeed {
|
||||
Off,
|
||||
Low,
|
||||
Medium,
|
||||
High,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct FanState {
|
||||
pub speed: FanSpeed,
|
||||
pub manual: bool,
|
||||
}
|
||||
|
||||
impl FanState {
|
||||
pub fn new(speed: FanSpeed, manual: bool) -> Self {
|
||||
Self { speed, manual }
|
||||
}
|
||||
|
||||
pub fn speed(&self) -> FanSpeed {
|
||||
self.speed
|
||||
}
|
||||
|
||||
pub fn manual(&self) -> bool {
|
||||
self.manual
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SetFanSpeed {
|
||||
speed: FanSpeed,
|
||||
}
|
||||
|
||||
impl SetFanSpeed {
|
||||
pub fn new(speed: FanSpeed) -> Self {
|
||||
Self { speed }
|
||||
}
|
||||
|
||||
pub fn speed(&self) -> FanSpeed {
|
||||
self.speed
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct SensorData {
|
||||
temperature: f32,
|
||||
humidity: f32,
|
||||
pressure: f32,
|
||||
}
|
||||
|
||||
impl SensorData {
|
||||
pub fn new<E: Debug>(measurements: Measurements<E>) -> Self {
|
||||
Self {
|
||||
temperature: measurements.temperature,
|
||||
humidity: measurements.humidity,
|
||||
pressure: measurements.pressure,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn temperature(&self) -> f32 {
|
||||
self.temperature
|
||||
}
|
||||
|
||||
pub fn humidity(&self) -> f32 {
|
||||
self.humidity
|
||||
}
|
||||
|
||||
pub fn pressure(&self) -> f32 {
|
||||
self.pressure
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ use updater::firmware_router;
|
||||
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
use air_filter::{FanSpeed, FanState, SensorData, SetFanSpeed};
|
||||
use air_filter_types::{FanSpeed, FanState, SensorData, SetFanSpeed};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => pio::InterruptHandler<PIO0>;
|
||||
|
||||
Reference in New Issue
Block a user