initial volume and light control button support w/ debouncer
This commit is contained in:
parent
485f617515
commit
144d24cf59
1 changed files with 45 additions and 9 deletions
|
|
@ -66,6 +66,8 @@ struct DebouncedGPIO<'a> {
|
|||
value: bool,
|
||||
// GPIO is ready (debounced)
|
||||
ready: bool,
|
||||
// debouncer is active
|
||||
active: bool,
|
||||
// debounce timer
|
||||
timer: TickTimerService,
|
||||
}
|
||||
|
|
@ -77,6 +79,7 @@ impl<'a> DebouncedGPIO<'a> {
|
|||
input: Input::new(pin, Pull::Up),
|
||||
value: false,
|
||||
ready: false,
|
||||
active: false,
|
||||
timer: TickTimerService::new(
|
||||
TickServiceData::new(system_tick_rate_hz * debounce_time_ms / 1000),
|
||||
false,
|
||||
|
|
@ -88,6 +91,10 @@ impl<'a> DebouncedGPIO<'a> {
|
|||
self.ready
|
||||
}
|
||||
|
||||
pub fn active(&self) -> bool {
|
||||
self.active
|
||||
}
|
||||
|
||||
pub fn value(&self) -> bool {
|
||||
self.value
|
||||
}
|
||||
|
|
@ -95,11 +102,13 @@ impl<'a> DebouncedGPIO<'a> {
|
|||
pub fn begin(&mut self) {
|
||||
self.reset();
|
||||
self.timer.enable(true);
|
||||
self.active = true;
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.timer.reset();
|
||||
self.ready = false;
|
||||
self.active = false;
|
||||
}
|
||||
|
||||
pub fn service(&mut self) {
|
||||
|
|
@ -110,6 +119,9 @@ impl<'a> DebouncedGPIO<'a> {
|
|||
self.ready = true;
|
||||
}
|
||||
}
|
||||
pub fn is_high_immediate(&self) -> bool {
|
||||
self.input.is_high()
|
||||
}
|
||||
}
|
||||
|
||||
// DeepSleep --coin button irq--> Active
|
||||
|
|
@ -291,15 +303,15 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
// set up interrupts
|
||||
unsafe { system::init_gpio_irq(sense_coin_pin.pin(), sense_coin_pin.port(), false, true) };
|
||||
unsafe { system::init_gpio_irq(main_btn_pin.pin(), main_btn_pin.port(), true, true) };
|
||||
unsafe { system::init_gpio_irq(volume_btn_pin.pin(), volume_btn_pin.port(), true, true) };
|
||||
unsafe {
|
||||
system::init_gpio_irq(
|
||||
light_ctrl_btn_pin.pin(),
|
||||
light_ctrl_btn_pin.port(),
|
||||
true,
|
||||
true,
|
||||
)
|
||||
};
|
||||
// unsafe { system::init_gpio_irq(volume_btn_pin.pin(), volume_btn_pin.port(), true, true) };
|
||||
// unsafe {
|
||||
// system::init_gpio_irq(
|
||||
// light_ctrl_btn_pin.pin(),
|
||||
// light_ctrl_btn_pin.port(),
|
||||
// true,
|
||||
// true,
|
||||
// )
|
||||
// };
|
||||
|
||||
// coin debouncer (100ms)
|
||||
let mut sense_coin_input =
|
||||
|
|
@ -414,11 +426,25 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
INPUT_FLAGS.main_btn_flag = false;
|
||||
main_btn_input.begin();
|
||||
}
|
||||
if !volume_btn_input.active() {
|
||||
if !volume_btn_input.is_high_immediate() && !volume_btn_input.active() {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("volume btn triggered: {}", volume_btn_input.active());
|
||||
volume_btn_input.begin();
|
||||
}
|
||||
}
|
||||
if !light_ctrl_btn_input.is_high_immediate() && !light_ctrl_btn_input.active() {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("light ctrl btn triggered!");
|
||||
light_ctrl_btn_input.begin();
|
||||
}
|
||||
}
|
||||
|
||||
// debouncer
|
||||
sense_coin_input.service();
|
||||
main_btn_input.service();
|
||||
volume_btn_input.service();
|
||||
light_ctrl_btn_input.service();
|
||||
|
||||
if sense_coin_input.ready() {
|
||||
#[cfg(feature = "enable_print")]
|
||||
|
|
@ -445,6 +471,16 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
|||
lp_timer.reset();
|
||||
}
|
||||
}
|
||||
if volume_btn_input.ready() {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("volume btn value: {}", volume_btn_input.value());
|
||||
volume_btn_input.reset();
|
||||
}
|
||||
if light_ctrl_btn_input.ready() {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("light_ctrl_btn value: {}", sense_coin_input.value());
|
||||
sense_coin_input.reset();
|
||||
}
|
||||
|
||||
// timers
|
||||
sp_timer.tick();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue