Skip to content

Commit

Permalink
Listing default values, updating buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-summers committed Nov 14, 2023
1 parent 58904b2 commit 6182e1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/hardware/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
26 changes: 19 additions & 7 deletions src/hardware/serial_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<heapless::String<32>>("/") {
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();
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6182e1c

Please sign in to comment.