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 // 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 // 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); let not = btn1.button.wait_event(esp_idf_svc::hal::delay::NON_BLOCK);
match not { if not.is_some() {
Some(n) => { println!("Button 1 pressed!");
println!("Button 1 pressed!");
if heater_drv_pin.is_set_high() { if heater_drv_pin.is_set_high() {
heater_drv_pin.set_low()?; heater_drv_pin.set_low()?;
btn1.indicator.set_state(false)?; btn1.indicator.set_state(false)?;
} else { } else {
heater_drv_pin.set_high()?; heater_drv_pin.set_high()?;
btn1.indicator.set_state(true)?; btn1.indicator.set_state(true)?;
} }
input_time = Option::from(Instant::now()); input_time = Option::from(Instant::now());
},
None => (),
} }
// enable button interrupt again after 300ms from last click // enable button interrupt again after 300ms from last click
match input_time { if let Some(time) = input_time {
Some(time) => { if time.elapsed().as_millis() >= 300 {
if time.elapsed().as_millis() >= 300 { btn1.button.enable_interrupt()?;
btn1.button.enable_interrupt()?; input_time.take();
input_time.take(); }
}
},
None => (),
} }
if measure_time.elapsed().as_millis() >= 10 { if measure_time.elapsed().as_millis() >= 10 {