Addition of vague failsafes and speaker beep when probe goes out of range
This commit is contained in:
@@ -32,4 +32,4 @@ rustflags = [
|
|||||||
|
|
||||||
# This runner will find a supported SWD debug probe and flash your RP2040 over
|
# This runner will find a supported SWD debug probe and flash your RP2040 over
|
||||||
# SWD:
|
# SWD:
|
||||||
runner = "probe-rs run --chip RP2040"
|
runner = "probe-rs run --chip RP2040 --protocol swd"
|
||||||
56
src/main.rs
56
src/main.rs
@@ -12,6 +12,7 @@
|
|||||||
mod rotary;
|
mod rotary;
|
||||||
|
|
||||||
use defmt::println;
|
use defmt::println;
|
||||||
|
use embedded_hal::pwm::SetDutyCycle;
|
||||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||||
// be linked)
|
// be linked)
|
||||||
use panic_probe as _;
|
use panic_probe as _;
|
||||||
@@ -131,7 +132,7 @@ fn main() -> ! {
|
|||||||
let mut tick = 0u32;
|
let mut tick = 0u32;
|
||||||
let mut last_gfx_push = 0u32;
|
let mut last_gfx_push = 0u32;
|
||||||
|
|
||||||
let mut target_temp = 220;
|
let mut target_temp = 250;
|
||||||
|
|
||||||
let mut gate_pin = pins.gpio15.into_push_pull_output_in_state(rp2040_hal::gpio::PinState::Low);
|
let mut gate_pin = pins.gpio15.into_push_pull_output_in_state(rp2040_hal::gpio::PinState::Low);
|
||||||
|
|
||||||
@@ -141,6 +142,17 @@ fn main() -> ! {
|
|||||||
let mut clk_pin = pins.gpio16.into_pull_up_input();
|
let mut clk_pin = pins.gpio16.into_pull_up_input();
|
||||||
let mut dt_pin = pins.gpio17.into_pull_up_input();
|
let mut dt_pin = pins.gpio17.into_pull_up_input();
|
||||||
|
|
||||||
|
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);
|
||||||
|
let pwm = &mut pwm_slices.pwm1;
|
||||||
|
pwm.set_ph_correct();
|
||||||
|
pwm.set_div_int(3);
|
||||||
|
pwm.enable();
|
||||||
|
|
||||||
|
let beep_channel = &mut pwm.channel_a;
|
||||||
|
beep_channel.set_duty_cycle(5000);
|
||||||
|
beep_channel.output_to(pins.gpio2);
|
||||||
|
let mut emergency = 0u32;
|
||||||
|
|
||||||
let mut last_rotary = 0u32;
|
let mut last_rotary = 0u32;
|
||||||
|
|
||||||
const CYCLES_PER_FRAME:u32 = 100_000;
|
const CYCLES_PER_FRAME:u32 = 100_000;
|
||||||
@@ -150,6 +162,17 @@ fn main() -> ! {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
||||||
|
match emergency {
|
||||||
|
0 => beep_channel.set_enabled(false),
|
||||||
|
e => {
|
||||||
|
beep_channel.set_enabled((e % 5_000_000) < 70000);
|
||||||
|
emergency += 1;
|
||||||
|
if emergency == 0 {
|
||||||
|
emergency = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if tick - last_rotary > CYCLES_PER_ROTARY {
|
if tick - last_rotary > CYCLES_PER_ROTARY {
|
||||||
rotary_input_allowed = true;
|
rotary_input_allowed = true;
|
||||||
}
|
}
|
||||||
@@ -161,13 +184,13 @@ fn main() -> ! {
|
|||||||
|
|
||||||
match rotary.update(clk_now, dt_now) {
|
match rotary.update(clk_now, dt_now) {
|
||||||
RotaryResponse::UP => {
|
RotaryResponse::UP => {
|
||||||
target_temp += 1;
|
target_temp += 5;
|
||||||
rotary_input_allowed = false;
|
rotary_input_allowed = false;
|
||||||
last_rotary = tick;
|
last_rotary = tick;
|
||||||
// println!("Rotary up");
|
// println!("Rotary up");
|
||||||
}
|
}
|
||||||
RotaryResponse::DOWN => {
|
RotaryResponse::DOWN => {
|
||||||
target_temp -= 1;
|
target_temp -= 5;
|
||||||
rotary_input_allowed = false;
|
rotary_input_allowed = false;
|
||||||
last_rotary = tick;
|
last_rotary = tick;
|
||||||
// println!("Rotary dn");
|
// println!("Rotary dn");
|
||||||
@@ -224,13 +247,11 @@ fn main() -> ! {
|
|||||||
adc_avg += *v as u32;
|
adc_avg += *v as u32;
|
||||||
});
|
});
|
||||||
|
|
||||||
if accepted_samps < 10 {
|
|
||||||
println!("Not enough accepted samples, skipping");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let adc_val = (adc_avg / accepted_samps) as u16;
|
|
||||||
|
|
||||||
|
let adc_val = match accepted_samps >= 10 {
|
||||||
|
true => (adc_avg / accepted_samps) as u16,
|
||||||
|
false => 0u16
|
||||||
|
};
|
||||||
// println!("ADC {=u16}, samps {}", adc_val, accepted_samps);
|
// println!("ADC {=u16}, samps {}", adc_val, accepted_samps);
|
||||||
|
|
||||||
let deg = match adc_val {
|
let deg = match adc_val {
|
||||||
@@ -251,7 +272,16 @@ fn main() -> ! {
|
|||||||
let probe_temp = (deg * 10.) as u32;
|
let probe_temp = (deg * 10.) as u32;
|
||||||
|
|
||||||
let mut itoa_result = itoa(probe_temp);
|
let mut itoa_result = itoa(probe_temp);
|
||||||
let deg_str = itoa_result.as_degrees_decicentigrade_str();
|
let deg_str =match probe_temp {
|
||||||
|
0 | 900.. => {
|
||||||
|
emergency |= 1;
|
||||||
|
"ERR"
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
emergency = 0;
|
||||||
|
itoa_result.as_degrees_decicentigrade_str()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// println!("tenths of a deg {}, deg {}", probe_temp, deg_str);
|
// println!("tenths of a deg {}, deg {}", probe_temp, deg_str);
|
||||||
@@ -259,9 +289,9 @@ fn main() -> ! {
|
|||||||
|
|
||||||
gfx_buf.draw_string(10, START_Y+30, "Target Temp");
|
gfx_buf.draw_string(10, START_Y+30, "Target Temp");
|
||||||
|
|
||||||
gate_pin.set_state(match target_temp > probe_temp {
|
gate_pin.set_state(match (probe_temp > 0, target_temp > probe_temp) {
|
||||||
true => rp2040_hal::gpio::PinState::High,
|
(true, true) => rp2040_hal::gpio::PinState::High,
|
||||||
false => rp2040_hal::gpio::PinState::Low
|
_ => rp2040_hal::gpio::PinState::Low
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
// dancing sprite just for heartbeat visibility
|
// dancing sprite just for heartbeat visibility
|
||||||
|
|||||||
Reference in New Issue
Block a user