move appdata out to new module

This commit is contained in:
sigil-03 2025-11-02 09:14:59 -07:00
parent 0836fc58df
commit 008bf334a4
2 changed files with 76 additions and 42 deletions

View file

@ -13,6 +13,9 @@ mod system;
mod synthesizer;
use synthesizer::AppSynthesizers;
mod app;
use app::App;
use ch32_hal::{adc::AdcChannel, interrupt::typelevel::Handler, timer::low_level::OutputPolarity};
use insert_coin::{CoreConfig, InsertCoin, SimplePwmCore};
@ -28,42 +31,6 @@ use hal::println;
use qingke::riscv;
enum Level {
Off,
Low,
Medium,
High,
Maximum,
}
impl Level {
pub fn next(&mut self) {
*self = match self {
Self::Off => Self::Low,
Self::Low => Self::Medium,
Self::Medium => Self::High,
Self::High => Self::Maximum,
Self::Maximum => Self::Off,
};
}
}
struct Settings {
brightness: Level,
volume: Level,
button_sound_index: usize,
}
impl Default for Settings {
fn default() -> Self {
Self {
brightness: Level::Medium,
volume: Level::Medium,
button_sound_index: 0,
}
}
}
struct DebouncedGPIO<'a> {
input: Input<'a>,
// value of the GPIO
@ -508,7 +475,8 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
interfaces.set_active(true);
// insert_coin.init();
let mut settings = Settings::default();
// let mut settings = Se::default();
let mut app = App::default();
let mut led0_index = 0;
let led0_dcs = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
@ -672,10 +640,10 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
// .dac
// .load_data(button_sounds[settings.button_sound_index]);
settings.button_sound_index += 1;
if settings.button_sound_index > 2 {
app.settings.button_sound_index += 1;
if app.settings.button_sound_index > 2 {
// if settings.button_sound_index > button_sounds.len() - 1 {
settings.button_sound_index = 0;
app.settings.button_sound_index = 0;
}
#[cfg(feature = "enable_print")]
println!("reset hold timers + enable");
@ -691,13 +659,13 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
if volume_btn_input.ready() {
#[cfg(feature = "enable_print")]
println!("volume btn value: {}", volume_btn_input.value());
settings.volume.next();
app.settings.volume.next();
volume_btn_input.reset();
}
if light_ctrl_btn_input.ready() {
#[cfg(feature = "enable_print")]
println!("light_ctrl_btn value: {}", light_ctrl_btn_input.value());
settings.brightness.next();
app.settings.brightness.next();
light_ctrl_btn_input.reset();
}