now displays a (for now fake) target temp.

This commit is contained in:
Gabe Venberg 2023-12-02 22:10:48 -06:00
parent c1e16006f3
commit 8bbc5a6c43

View file

@ -7,18 +7,12 @@
)]
mod app {
extern crate alloc;
use alloc::{
format,
string::{self, String, ToString},
};
use alloc::format;
use core::fmt::Write;
use cortex_m::delay::Delay;
use defmt_rtt as _;
use embedded_alloc::Heap;
use embedded_hal::{
digital::v2::{OutputPin, ToggleableOutputPin},
spi::MODE_0,
};
use embedded_hal::{digital::v2::ToggleableOutputPin, spi::MODE_0};
use hd44780::{bus::FourBitBus, HD44780};
use panic_probe as _;
@ -110,6 +104,7 @@ mod app {
struct Shared {
delay: Delay,
recent_temp: f32,
target_temp: f32,
uart: Uart,
}
@ -177,8 +172,8 @@ mod app {
defmt::info!("Program start");
writeln!(uart, "Program start\r",).unwrap();
let mut led_pin: Led = pins.led.into_push_pull_output();
let mut external_led_pin: ExternalLed = pins.gpio14.into_push_pull_output();
let led_pin: Led = pins.led.into_push_pull_output();
let external_led_pin: ExternalLed = pins.gpio14.into_push_pull_output();
//cs
let thermometer_spi_device = ctx.device.SPI0;
@ -206,7 +201,7 @@ mod app {
),
};
let mut lcd: Lcd = hd44780::HD44780::new_4bit(
let lcd: Lcd = hd44780::HD44780::new_4bit(
pins.gpio16.into_push_pull_output(), //rs
pins.gpio17.into_push_pull_output(), //enable
pins.gpio18.into_push_pull_output(), //d4
@ -219,7 +214,6 @@ mod app {
let mono = Rp2040Mono::new(ctx.device.TIMER);
display::spawn(ToString::to_string(&"Starting")).unwrap();
heartbeat::spawn().unwrap();
second_heartbeat::spawn().unwrap();
@ -227,6 +221,7 @@ mod app {
Shared {
delay,
recent_temp: 0.0,
target_temp: 25.0,
uart,
},
Local {
@ -237,47 +232,40 @@ mod app {
},
init::Monotonics(mono),
)
// loop {
// led_pin.set_high().unwrap();
// external_led_pin.set_low().unwrap();
// delay.delay_ms(500);
// led_pin.set_low().unwrap();
// external_led_pin.set_high().unwrap();
// delay.delay_ms(500);
// match thermocouple.read_temp() {
// Ok(v) => {
// writeln!(uart, "Current: {} \r", v).unwrap();
// write_lcd(&mut lcd, &mut delay, &format!("{:02.2} C", v))
// }
// Err(e) => defmt::error!("error reading temp {}", defmt::Debug2Format(&e)),
// };
// }
}
#[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();
.lock(|u| writeln!(u, "{:02.2} C\r", v).unwrap());
ctx.shared.recent_temp.lock(|t| *t = v);
update_display::spawn().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) {
#[task(local = [lcd], shared = [delay, recent_temp, target_temp])]
fn update_display(mut ctx: update_display::Context) {
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();
ctx.shared.recent_temp.lock(|t| {
ctx.local
.lcd
.write_str(&format!("{:02.2} C", t), d)
.unwrap();
});
ctx.local.lcd.set_cursor_pos(40, d).unwrap();
ctx.shared.target_temp.lock(|t| {
ctx.local
.lcd
.write_str(&format!("Target: {:02.2} C", t), d)
.unwrap()
})
});
}
@ -288,6 +276,7 @@ mod app {
// Re-spawn this task after 1 second
let one_second = Duration::<u64, MONO_NUM, MONO_DENOM>::from_ticks(ONE_SEC_TICKS);
read_temp::spawn().unwrap();
heartbeat::spawn_after(one_second).unwrap();
}