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