move appdata out to new module
This commit is contained in:
parent
0836fc58df
commit
008bf334a4
2 changed files with 76 additions and 42 deletions
66
ch32v-insert-coin/src/app.rs
Normal file
66
ch32v-insert-coin/src/app.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
#[derive(Default)]
|
||||||
|
pub enum State {
|
||||||
|
// system is asleep, waiting for wake from coin insertion
|
||||||
|
DeepSleep,
|
||||||
|
// system is in low-power mode, dimmed lights, waiting for interaction
|
||||||
|
Idle,
|
||||||
|
// system is active. on entry: play coin sound. on button press: play different sound
|
||||||
|
#[default]
|
||||||
|
Active,
|
||||||
|
}
|
||||||
|
|
||||||
|
mod settings {
|
||||||
|
pub 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Settings {
|
||||||
|
pub brightness: Level,
|
||||||
|
pub volume: Level,
|
||||||
|
pub button_sound_index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Settings {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
brightness: Level::Medium,
|
||||||
|
volume: Level::Medium,
|
||||||
|
button_sound_index: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub use settings::Settings;
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
state: State,
|
||||||
|
pub settings: Settings,
|
||||||
|
// TODO: make this the "sound module" or whatever.
|
||||||
|
// synthesizers: AppSynthesizers,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for App {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
state: State::default(),
|
||||||
|
settings: Settings::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,9 @@ mod system;
|
||||||
mod synthesizer;
|
mod synthesizer;
|
||||||
use synthesizer::AppSynthesizers;
|
use synthesizer::AppSynthesizers;
|
||||||
|
|
||||||
|
mod app;
|
||||||
|
use app::App;
|
||||||
|
|
||||||
use ch32_hal::{adc::AdcChannel, interrupt::typelevel::Handler, timer::low_level::OutputPolarity};
|
use ch32_hal::{adc::AdcChannel, interrupt::typelevel::Handler, timer::low_level::OutputPolarity};
|
||||||
use insert_coin::{CoreConfig, InsertCoin, SimplePwmCore};
|
use insert_coin::{CoreConfig, InsertCoin, SimplePwmCore};
|
||||||
|
|
||||||
|
|
@ -28,42 +31,6 @@ use hal::println;
|
||||||
|
|
||||||
use qingke::riscv;
|
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> {
|
struct DebouncedGPIO<'a> {
|
||||||
input: Input<'a>,
|
input: Input<'a>,
|
||||||
// value of the GPIO
|
// value of the GPIO
|
||||||
|
|
@ -508,7 +475,8 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
||||||
interfaces.set_active(true);
|
interfaces.set_active(true);
|
||||||
// insert_coin.init();
|
// insert_coin.init();
|
||||||
|
|
||||||
let mut settings = Settings::default();
|
// let mut settings = Se::default();
|
||||||
|
let mut app = App::default();
|
||||||
|
|
||||||
let mut led0_index = 0;
|
let mut led0_index = 0;
|
||||||
let led0_dcs = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
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
|
// .dac
|
||||||
// .load_data(button_sounds[settings.button_sound_index]);
|
// .load_data(button_sounds[settings.button_sound_index]);
|
||||||
|
|
||||||
settings.button_sound_index += 1;
|
app.settings.button_sound_index += 1;
|
||||||
if settings.button_sound_index > 2 {
|
if app.settings.button_sound_index > 2 {
|
||||||
// if settings.button_sound_index > button_sounds.len() - 1 {
|
// if settings.button_sound_index > button_sounds.len() - 1 {
|
||||||
settings.button_sound_index = 0;
|
app.settings.button_sound_index = 0;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("reset hold timers + enable");
|
println!("reset hold timers + enable");
|
||||||
|
|
@ -691,13 +659,13 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
||||||
if volume_btn_input.ready() {
|
if volume_btn_input.ready() {
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("volume btn value: {}", volume_btn_input.value());
|
println!("volume btn value: {}", volume_btn_input.value());
|
||||||
settings.volume.next();
|
app.settings.volume.next();
|
||||||
volume_btn_input.reset();
|
volume_btn_input.reset();
|
||||||
}
|
}
|
||||||
if light_ctrl_btn_input.ready() {
|
if light_ctrl_btn_input.ready() {
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("light_ctrl_btn value: {}", light_ctrl_btn_input.value());
|
println!("light_ctrl_btn value: {}", light_ctrl_btn_input.value());
|
||||||
settings.brightness.next();
|
app.settings.brightness.next();
|
||||||
light_ctrl_btn_input.reset();
|
light_ctrl_btn_input.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue