Skip to content

Commit

Permalink
Adds temp temperature command
Browse files Browse the repository at this point in the history
  • Loading branch information
ansg191 committed Jan 4, 2024
1 parent 751b163 commit d64f327
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<const N: usize> Storage<N> {
iter: self.temps.oldest_ordered(),
}
}

pub fn recent(&self) -> Option<(u32, Temperature)> {
self.temps.recent().map(|temp| (*temp).into())
}
}

#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -70,6 +74,12 @@ impl Temp {
}
}

impl From<Temp> 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>,
Expand All @@ -79,6 +89,6 @@ impl<'a, const N: usize> Iterator for OldestOrdered<'a, N> {
type Item = (u32, Temperature);

fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|temp| (temp.secs(), temp.value()))
self.iter.next().map(|temp| (*temp).into())
}
}
15 changes: 14 additions & 1 deletion src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<ok>\r\n";

const HELP_STR: &str = "Commands:\r
help\r
Expand Down Expand Up @@ -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, "<missing>\r\n");
}
}
Some(b"cooler") => match args.next() {
None | Some(&[]) => {
if unwrap!(cx.shared.cooler.lock(|c| c.is_set_high())) {
Expand Down

0 comments on commit d64f327

Please sign in to comment.