From 6182e1c790d6b1f1f5a8e824419c6f877bdcd4f1 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 14 Nov 2023 11:20:05 +0100 Subject: [PATCH] Listing default values, updating buffer size --- src/hardware/flash.rs | 2 +- src/hardware/serial_terminal.rs | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/hardware/flash.rs b/src/hardware/flash.rs index a8a91de68..60c73d991 100644 --- a/src/hardware/flash.rs +++ b/src/hardware/flash.rs @@ -2,7 +2,7 @@ use core::fmt::Write; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; use stm32h7xx_hal::flash::{LockedFlashBank, UnlockedFlashBank}; -#[derive(serde::Serialize, serde::Deserialize, miniconf::Tree)] +#[derive(Clone, serde::Serialize, serde::Deserialize, miniconf::Tree)] pub struct Settings { pub broker: heapless::String<255>, pub id: heapless::String<23>, diff --git a/src/hardware/serial_terminal.rs b/src/hardware/serial_terminal.rs index b5f280aab..6f9d0c69d 100644 --- a/src/hardware/serial_terminal.rs +++ b/src/hardware/serial_terminal.rs @@ -111,12 +111,26 @@ fn handle_list( ) { writeln!(context, "Available properties:").unwrap(); + let mut defaults = context.flash.settings.clone(); + defaults.reset(); + let mut buf = [0; 256]; + let mut default_buf = [0; 256]; for path in Settings::iter_paths::>("/") { let path = path.unwrap(); - let len = context.flash.settings.get_json(&path, &mut buf).unwrap(); - let stringified = core::str::from_utf8(&buf[..len]).unwrap(); - writeln!(context, "{path}: {stringified}").unwrap(); + let current_value = { + let len = context.flash.settings.get_json(&path, &mut buf).unwrap(); + core::str::from_utf8(&buf[..len]).unwrap() + }; + let default_value = { + let len = defaults.get_json(&path, &mut default_buf).unwrap(); + core::str::from_utf8(&default_buf[..len]).unwrap() + }; + writeln!( + context, + "{path}: {current_value} [default: {default_value}]" + ) + .unwrap(); } } @@ -165,9 +179,7 @@ fn handle_setting_write( args: &[&str], context: &mut Context, ) { - let key = menu::argument_finder(item, args, "item") - .unwrap() - .unwrap(); + let key = menu::argument_finder(item, args, "item").unwrap().unwrap(); let value = menu::argument_finder(item, args, "value").unwrap().unwrap(); // Now, write the new value into memory. @@ -204,7 +216,7 @@ impl SerialTerminal { let (producer, consumer) = OUTPUT_BUFFER.try_split().unwrap(); let input_buffer = - cortex_m::singleton!(: [u8; 255] = [0; 255]).unwrap(); + cortex_m::singleton!(: [u8; 256] = [0; 256]).unwrap(); let context = Context { output: OutputBuffer { producer }, flash,