diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 9d70a53..1c9f3e8 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -26,6 +26,10 @@ impl Storage { iter: self.temps.oldest_ordered(), } } + + pub fn recent(&self) -> Option<(u32, Temperature)> { + self.temps.recent().map(|temp| (*temp).into()) + } } #[derive(Debug, Copy, Clone)] @@ -70,6 +74,12 @@ impl Temp { } } +impl From for (u32, Temperature) { + fn from(value: Temp) -> Self { + (value.secs(), value.value()) + } +} + #[derive(Clone)] pub struct OldestOrdered<'a, const N: usize> { iter: heapless::OldestOrdered<'a, Temp, N>, @@ -79,6 +89,6 @@ impl<'a, const N: usize> Iterator for OldestOrdered<'a, N> { type Item = (u32, Temperature); fn next(&mut self) -> Option { - self.iter.next().map(|temp| (temp.secs(), temp.value())) + self.iter.next().map(|temp| (*temp).into()) } } diff --git a/src/terminal.rs b/src/terminal.rs index 3a15e8c..4b414ff 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -10,7 +10,7 @@ use stm32f0xx_hal::prelude::*; use crate::{app::terminal::Context, ds18b20::Resolution, thermometer::Temperature}; pub const BUFFER_SIZE: usize = 32; -const OK_STR: &str = "ok\r\n"; +const OK_STR: &str = "\r\n"; const HELP_STR: &str = "Commands:\r help\r @@ -81,6 +81,19 @@ pub fn terminal(mut cx: Context<'_>) { } Some(b) => unknown_argument(&mut cx, b), }, + Some(b"temp") => { + let temp = cx.shared.storage.lock(|s| s.recent()); + if let Some((secs, temp)) = temp { + cx.shared.usart.lock(|tx| { + print_uint(tx, secs); + print_uart_locked(tx, " "); + print_temp(tx, temp); + print_uart_locked(tx, "\r\n"); + }); + } else { + print_uart(&mut cx, "\r\n"); + } + } Some(b"cooler") => match args.next() { None | Some(&[]) => { if unwrap!(cx.shared.cooler.lock(|c| c.is_set_high())) {