Reworked code to host API using picoserve
This commit is contained in:
57
src/lib.rs
Normal file
57
src/lib.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
#![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 }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SetFanSpeed {
|
||||
speed: FanSpeed,
|
||||
}
|
||||
|
||||
impl SetFanSpeed {
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user