add usb power detection + check to ADC shutdown logic
This commit is contained in:
parent
8ea4b4401e
commit
c43cc5599e
2 changed files with 25 additions and 6 deletions
|
|
@ -310,6 +310,7 @@ pub struct Interfaces {
|
|||
pub pwm_core: SimplePwmCore<'static, ch32_hal::peripherals::TIM1>,
|
||||
pub adc_core: crate::AdcCore,
|
||||
pub amp: crate::Amplifier,
|
||||
pub usb: crate::Usb,
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
|
|
@ -400,12 +401,14 @@ impl App {
|
|||
}
|
||||
if self.timers.batt_adc_timer.need_service() {
|
||||
self.timers.batt_adc_timer.service();
|
||||
let bv = self.interfaces.adc_core.get_battery_voltage();
|
||||
let avg = self.interfaces.adc_core.get_average();
|
||||
// #[cfg(feature = "enable_print")]
|
||||
// println!("batt adc service: {bv}, {avg}");
|
||||
if avg < 421 {
|
||||
self.set_state(State::DeepSleep);
|
||||
if !self.interfaces.usb.powered() {
|
||||
let bv = self.interfaces.adc_core.get_battery_voltage();
|
||||
let avg = self.interfaces.adc_core.get_average();
|
||||
// #[cfg(feature = "enable_print")]
|
||||
// println!("batt adc service: {bv}, {avg}");
|
||||
if avg < 421 {
|
||||
self.set_state(State::DeepSleep);
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.timers.usb_adc_timer.need_service() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue