Reworked code to host API using picoserve

This commit is contained in:
2025-01-11 02:51:38 +01:00
parent 0fef57c37d
commit 148943ff42
6 changed files with 814 additions and 1174 deletions

57
src/lib.rs Normal file
View 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,
}
}
}