use if syntax instead of match
This commit is contained in:
parent
475dffe6b2
commit
52c918cf1f
1 changed files with 15 additions and 21 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue