add persistent settings

This commit is contained in:
sigil-03 2025-11-15 16:03:32 -07:00
parent 60d6aaecd6
commit f26920a099
2 changed files with 20 additions and 7 deletions

View file

@ -9,7 +9,7 @@ pub enum State {
Active,
}
mod settings {
pub mod settings {
#[derive(Debug, Default, Clone, Copy)]
pub enum Level {
@ -333,10 +333,11 @@ impl App {
services: Services,
sequences: Sequences,
interfaces: Interfaces,
settings: Settings,
) -> Self {
Self {
state: State::default(),
settings: Settings::default(),
settings,
timers: Timers::new(config.timers, config.system_tick_rate_hz),
services,
sequences,
@ -659,6 +660,9 @@ impl App {
pub fn get_state(&self) -> State {
self.state
}
pub fn get_settings(&self) -> Settings {
self.settings
}
pub fn should_wake(&self) -> bool {
if self.interfaces.usb.powered() {
return true;

View file

@ -245,10 +245,11 @@ bind_interrupts!(struct Irqs {
});
// TODO: remove
use app::settings::Settings;
use insert_coin::TickTimerService;
use insert_coin::{TickService, TickServiceData};
fn app_main(mut p: hal::Peripherals) {
fn app_main(mut p: hal::Peripherals, app_settings: Settings) -> Settings {
// initialize ADC core first, and exit if battery is too low
let mut adc = hal::adc::Adc::new(p.ADC1, Default::default());
let mut batt_monitor_pin = p.PD4;
@ -256,7 +257,7 @@ fn app_main(mut p: hal::Peripherals) {
let bv = adc_core.get_battery_voltage();
if bv < 421 {
adc_core.shutdown();
return;
return app_settings;
}
// === output setup ===
@ -397,7 +398,13 @@ fn app_main(mut p: hal::Peripherals) {
usb,
};
let mut app = App::new(app_config, app_services, app_sequences, app_interfaces);
let mut app = App::new(
app_config,
app_services,
app_sequences,
app_interfaces,
app_settings,
);
let need_sound = unsafe {
#[allow(static_mut_refs)]
@ -542,7 +549,7 @@ fn app_main(mut p: hal::Peripherals) {
// enter standby
app::State::DeepSleep => {
app.shut_down();
return;
return app.get_settings();
}
_ => {}
}
@ -642,12 +649,14 @@ fn main() -> ! {
// println!("post");
// debug_main(p);
let mut app_settings = Settings::default();
loop {
unsafe {
hal::rcc::init(hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI);
}
let mut p = unsafe { hal::Peripherals::steal() };
app_main(p);
app_settings = app_main(p, app_settings);
unsafe {
hal::rcc::init(hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI);