do interrupt handling for sleep

This commit is contained in:
sigil-03 2025-11-06 17:46:41 -07:00
parent 935129baed
commit a7cd209989
3 changed files with 93 additions and 46 deletions

View file

@ -372,16 +372,18 @@ impl App {
pub fn service(&mut self) {
// timers
if self.timers.sp_timer.need_service() {
self.timers.batt_adc_timer.service();
self.timers.sp_timer.service();
#[cfg(feature = "enable_print")]
println!("sp service");
self.timers.sp_timer.reset();
self.main_button_short_press();
}
if self.timers.lp_timer.need_service() {
self.timers.batt_adc_timer.service();
self.timers.lp_timer.service();
#[cfg(feature = "enable_print")]
println!("lp service");
self.timers.lp_timer.reset();
self.main_button_long_press();
}
if self.timers.batt_adc_timer.need_service() {
self.timers.batt_adc_timer.service();
@ -470,7 +472,7 @@ impl App {
if self.services.sample_player.need_service() {
self.services.sample_player.service();
let out = self.services.sample_player.get_amplitude() / 2;
let out = self.services.sample_player.get_amplitude() / 5;
self.interfaces
.pwm_core
.write_amplitude(ch32_hal::timer::Channel::Ch4, out as u8);
@ -480,6 +482,20 @@ impl App {
// interfaces to the app (for buttons, etc.)
impl App {
pub fn shut_down(&mut self) {
self.interfaces
.pwm_core
.write_amplitude(self.services.led0.channel, 0);
self.interfaces
.pwm_core
.write_amplitude(self.services.led1.channel, 0);
self.interfaces
.pwm_core
.write_amplitude(self.services.led2.channel, 0);
self.interfaces
.pwm_core
.disable(ch32_hal::timer::Channel::Ch4);
}
pub fn volume_button(&mut self) {
self.settings.volume.next();
#[cfg(feature = "enable_print")]
@ -498,26 +514,29 @@ impl App {
self.timers.lp_timer.reset();
self.timers.sp_timer.enable(true);
self.timers.lp_timer.enable(true);
self.main_button_click();
}
pub fn main_button_release(&mut self) {
// TODO
#[cfg(feature = "enable_print")]
println!("main button release");
match (
self.timers.sp_timer.is_enabled(),
self.timers.lp_timer.is_enabled(),
) {
// click
(true, true) => self.main_button_click(),
// short press
(false, true) => self.main_button_short_press(),
// long press
(false, false) => self.main_button_long_press(),
// anything else is not possible
_ => {}
}
// #[cfg(feature = "enable_print")]
// println!("main button release");
// let timers = (
// self.timers.sp_timer.is_enabled(),
// self.timers.lp_timer.is_enabled(),
// );
self.timers.sp_timer.reset();
self.timers.lp_timer.reset();
// match timers {
// // click
// (true, true) => self.main_button_click(),
// // short press
// (false, true) => self.main_button_short_press(),
// // long press
// (false, false) => self.main_button_long_press(),
// // anything else is not possible
// _ => {}
// }
}
pub fn coin_detect(&mut self) {
#[cfg(feature = "enable_print")]