From 21480cef4fbc03dab40a266e32f84f9d3272efed Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Fri, 15 Aug 2025 16:46:44 +0200 Subject: [PATCH] added serde for serializing in the webserver --- Cargo.lock | 1 + Cargo.toml | 4 +--- src/main.rs | 2 ++ src/store/id_mapping.rs | 6 +++--- src/store/id_store.rs | 8 ++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 542fbfc..bed633e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1062,6 +1062,7 @@ dependencies = [ "heapless", "log", "picoserve", + "serde", "smart-leds", "smoltcp", "static_cell", diff --git a/Cargo.toml b/Cargo.toml index f40d8f2..2f4a832 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,15 +60,13 @@ edge-nal = "0.5.0" edge-nal-embassy = { version = "0.6.0", features = ["log"] } picoserve = { version = "0.16.0", features = ["embassy", "log"] } embassy-sync = { version = "0.7.0", features = ["log"] } - ds3231 = { version = "0.3.0", features = ["async", "temperature_f32"] } chrono = { version = "0.4.41", default-features = false } dir-embed = "0.3.0" embedded-sdmmc-dev = "0.8.2" - esp-hal-smartled = { git = "https://github.com/esp-rs/esp-hal-community.git", package = "esp-hal-smartled", branch = "main", features = ["esp32c6"]} smart-leds = "0.4.0" - +serde = { version = "1.0.219", default-features = false, features = ["derive", "alloc"] } [profile.dev] # Rust debug is too slow. diff --git a/src/main.rs b/src/main.rs index 48c09c3..ce84e7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,8 @@ use static_cell::make_static; use crate::{store::TallyID, webserver::start_webserver}; +extern crate alloc; + mod drivers; mod feedback; mod init; diff --git a/src/store/id_mapping.rs b/src/store/id_mapping.rs index de25995..ac54b5f 100644 --- a/src/store/id_mapping.rs +++ b/src/store/id_mapping.rs @@ -1,14 +1,15 @@ -extern crate alloc; - use super::TallyID; use alloc::collections::BTreeMap; use alloc::string::String; +use serde::Serialize; +#[derive(Clone, Serialize)] pub struct Name { pub first: String, pub last: String, } +#[derive(Clone, Serialize)] pub struct IDMapping { id_map: BTreeMap, } @@ -28,4 +29,3 @@ impl IDMapping { self.id_map.insert(id, name); } } - diff --git a/src/store/id_store.rs b/src/store/id_store.rs index bc82b35..45bf2f8 100644 --- a/src/store/id_store.rs +++ b/src/store/id_store.rs @@ -1,11 +1,10 @@ -extern crate alloc; - use super::Date; use super::IDMapping; use super::TallyID; use alloc::collections::BTreeMap; use alloc::vec::Vec; +#[derive(Clone)] pub struct AttendanceDay { date: Date, ids: Vec, @@ -30,9 +29,10 @@ impl AttendanceDay { } } +#[derive(Clone)] pub struct IDStore { - days: BTreeMap, - mapping: IDMapping, + pub days: BTreeMap, + pub mapping: IDMapping, } impl IDStore {