use if syntax instead of match

This commit is contained in:
soffee 2025-03-08 15:03:50 +03:00
parent 475dffe6b2
commit 52c918cf1f

View file

@ -81,32 +81,26 @@ fn main() -> Result<()> {
// when we receive button event, button interrupt will be automatically disabled until we enable it manually
// so we use this feature to "debounce" our button by enabling interrupt only after some time passes
let not = btn1.button.wait_event(esp_idf_svc::hal::delay::NON_BLOCK);
match not {
Some(n) => {
println!("Button 1 pressed!");
if not.is_some() {
println!("Button 1 pressed!");
if heater_drv_pin.is_set_high() {
heater_drv_pin.set_low()?;
btn1.indicator.set_state(false)?;
} else {
heater_drv_pin.set_high()?;
btn1.indicator.set_state(true)?;
}
if heater_drv_pin.is_set_high() {
heater_drv_pin.set_low()?;
btn1.indicator.set_state(false)?;
} else {
heater_drv_pin.set_high()?;
btn1.indicator.set_state(true)?;
}
input_time = Option::from(Instant::now());
},
None => (),
input_time = Option::from(Instant::now());
}
// enable button interrupt again after 300ms from last click
match input_time {
Some(time) => {
if time.elapsed().as_millis() >= 300 {
btn1.button.enable_interrupt()?;
input_time.take();
}
},
None => (),
if let Some(time) = input_time {
if time.elapsed().as_millis() >= 300 {
btn1.button.enable_interrupt()?;
input_time.take();
}
}
if measure_time.elapsed().as_millis() >= 10 {