add persistent settings
This commit is contained in:
parent
60d6aaecd6
commit
f26920a099
2 changed files with 20 additions and 7 deletions
|
|
@ -9,7 +9,7 @@ pub enum State {
|
||||||
Active,
|
Active,
|
||||||
}
|
}
|
||||||
|
|
||||||
mod settings {
|
pub mod settings {
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
pub enum Level {
|
pub enum Level {
|
||||||
|
|
@ -333,10 +333,11 @@ impl App {
|
||||||
services: Services,
|
services: Services,
|
||||||
sequences: Sequences,
|
sequences: Sequences,
|
||||||
interfaces: Interfaces,
|
interfaces: Interfaces,
|
||||||
|
settings: Settings,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
state: State::default(),
|
state: State::default(),
|
||||||
settings: Settings::default(),
|
settings,
|
||||||
timers: Timers::new(config.timers, config.system_tick_rate_hz),
|
timers: Timers::new(config.timers, config.system_tick_rate_hz),
|
||||||
services,
|
services,
|
||||||
sequences,
|
sequences,
|
||||||
|
|
@ -659,6 +660,9 @@ impl App {
|
||||||
pub fn get_state(&self) -> State {
|
pub fn get_state(&self) -> State {
|
||||||
self.state
|
self.state
|
||||||
}
|
}
|
||||||
|
pub fn get_settings(&self) -> Settings {
|
||||||
|
self.settings
|
||||||
|
}
|
||||||
pub fn should_wake(&self) -> bool {
|
pub fn should_wake(&self) -> bool {
|
||||||
if self.interfaces.usb.powered() {
|
if self.interfaces.usb.powered() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -245,10 +245,11 @@ bind_interrupts!(struct Irqs {
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
|
use app::settings::Settings;
|
||||||
use insert_coin::TickTimerService;
|
use insert_coin::TickTimerService;
|
||||||
use insert_coin::{TickService, TickServiceData};
|
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
|
// initialize ADC core first, and exit if battery is too low
|
||||||
let mut adc = hal::adc::Adc::new(p.ADC1, Default::default());
|
let mut adc = hal::adc::Adc::new(p.ADC1, Default::default());
|
||||||
let mut batt_monitor_pin = p.PD4;
|
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();
|
let bv = adc_core.get_battery_voltage();
|
||||||
if bv < 421 {
|
if bv < 421 {
|
||||||
adc_core.shutdown();
|
adc_core.shutdown();
|
||||||
return;
|
return app_settings;
|
||||||
}
|
}
|
||||||
// === output setup ===
|
// === output setup ===
|
||||||
|
|
||||||
|
|
@ -397,7 +398,13 @@ fn app_main(mut p: hal::Peripherals) {
|
||||||
usb,
|
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 {
|
let need_sound = unsafe {
|
||||||
#[allow(static_mut_refs)]
|
#[allow(static_mut_refs)]
|
||||||
|
|
@ -542,7 +549,7 @@ fn app_main(mut p: hal::Peripherals) {
|
||||||
// enter standby
|
// enter standby
|
||||||
app::State::DeepSleep => {
|
app::State::DeepSleep => {
|
||||||
app.shut_down();
|
app.shut_down();
|
||||||
return;
|
return app.get_settings();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
@ -642,12 +649,14 @@ fn main() -> ! {
|
||||||
// println!("post");
|
// println!("post");
|
||||||
// debug_main(p);
|
// debug_main(p);
|
||||||
|
|
||||||
|
let mut app_settings = Settings::default();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
unsafe {
|
unsafe {
|
||||||
hal::rcc::init(hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI);
|
hal::rcc::init(hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI);
|
||||||
}
|
}
|
||||||
let mut p = unsafe { hal::Peripherals::steal() };
|
let mut p = unsafe { hal::Peripherals::steal() };
|
||||||
app_main(p);
|
app_settings = app_main(p, app_settings);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
hal::rcc::init(hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI);
|
hal::rcc::init(hal::rcc::Config::SYSCLK_FREQ_48MHZ_HSI);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue