added temp reading.
This commit is contained in:
parent
188fb05b25
commit
c1e16006f3
43
src/main.rs
43
src/main.rs
|
@ -7,7 +7,10 @@
|
|||
)]
|
||||
mod app {
|
||||
extern crate alloc;
|
||||
use alloc::{format, string::{self, String, ToString}};
|
||||
use alloc::{
|
||||
format,
|
||||
string::{self, String, ToString},
|
||||
};
|
||||
use core::fmt::Write;
|
||||
use cortex_m::delay::Delay;
|
||||
use defmt_rtt as _;
|
||||
|
@ -89,7 +92,7 @@ mod app {
|
|||
#[monotonic(binds = TIMER_IRQ_0, default = true)]
|
||||
type Rp2040Mono = Rp2040Monotonic;
|
||||
|
||||
struct Thermocouple {
|
||||
pub struct Thermocouple {
|
||||
cs: Pin<Gpio5, FunctionSio<SioOutput>, PullDown>,
|
||||
spi: ThermocoupleSpi,
|
||||
}
|
||||
|
@ -107,6 +110,7 @@ mod app {
|
|||
struct Shared {
|
||||
delay: Delay,
|
||||
recent_temp: f32,
|
||||
uart: Uart,
|
||||
}
|
||||
|
||||
#[local]
|
||||
|
@ -215,14 +219,16 @@ mod app {
|
|||
|
||||
let mono = Rp2040Mono::new(ctx.device.TIMER);
|
||||
|
||||
// write_lcd(&mut lcd, &mut delay, "Starting");
|
||||
|
||||
display::spawn(ToString::to_string(&"Starting")).unwrap();
|
||||
heartbeat::spawn().unwrap();
|
||||
second_heartbeat::spawn().unwrap();
|
||||
|
||||
(
|
||||
Shared { delay, recent_temp: 0.0 },
|
||||
Shared {
|
||||
delay,
|
||||
recent_temp: 0.0,
|
||||
uart,
|
||||
},
|
||||
Local {
|
||||
led: led_pin,
|
||||
thermocouple,
|
||||
|
@ -249,15 +255,26 @@ mod app {
|
|||
// }
|
||||
}
|
||||
|
||||
fn write_lcd(lcd: &mut Lcd, delay: &mut Delay, string: &str) {
|
||||
lcd.reset(delay).unwrap();
|
||||
lcd.clear(delay).unwrap();
|
||||
lcd.write_str(string, delay).unwrap();
|
||||
#[task(local = [thermocouple], shared = [recent_temp, uart])]
|
||||
fn read_temp(mut ctx: read_temp::Context) {
|
||||
match ctx.local.thermocouple.read_temp() {
|
||||
Ok(v) => {
|
||||
ctx.shared.recent_temp.lock(|t| *t = v);
|
||||
ctx.shared
|
||||
.uart
|
||||
.lock(|u| writeln!(u, "{:02.2} C", v).unwrap());
|
||||
let str = format!("{:02.2} C", v);
|
||||
display::spawn(str).unwrap();
|
||||
}
|
||||
Err(e) => defmt::error!("error reading temp {}", defmt::Debug2Format(&e)),
|
||||
}
|
||||
let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS);
|
||||
read_temp::spawn_after(one_second).unwrap();
|
||||
}
|
||||
|
||||
#[task(local = [lcd], shared = [delay], capacity = 5)]
|
||||
fn display(mut ctx: display::Context, str: String){
|
||||
ctx.shared.delay.lock(|d|{
|
||||
fn display(mut ctx: display::Context, str: String) {
|
||||
ctx.shared.delay.lock(|d| {
|
||||
ctx.local.lcd.reset(d).unwrap();
|
||||
ctx.local.lcd.clear(d).unwrap();
|
||||
ctx.local.lcd.write_str(&str, d).unwrap();
|
||||
|
@ -272,7 +289,6 @@ mod app {
|
|||
// Re-spawn this task after 1 second
|
||||
let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS);
|
||||
heartbeat::spawn_after(one_second).unwrap();
|
||||
display::spawn(ToString::to_string(&"tick")).unwrap();
|
||||
}
|
||||
|
||||
#[task(local = [external_led])]
|
||||
|
@ -282,8 +298,7 @@ mod app {
|
|||
|
||||
// Re-spawn this task after 1 second
|
||||
let one_and_one_half_second =
|
||||
Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks((ONE_SEC_TICKS as f64*1.14)as u64);
|
||||
Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks((ONE_SEC_TICKS as f64 * 1.14) as u64);
|
||||
second_heartbeat::spawn_after(one_and_one_half_second).unwrap();
|
||||
display::spawn(ToString::to_string(&"tock")).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue