All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
To reduce length of `main.rs` and therefor improve readability create source files for: - Assets (`assets.rs`): Contains all graphical assets such as the splash screen assets, symbols and the symbol table. - LCD (`lcd.rs`): Contains all lower level things regarding the LCD such as the `Lcd` struct and its implementations. - Screen (`screen/mod.rs`): - Splash (`screen/splash.rs`) - Home (`screen/home.rs`) - Setup (`screen/setup.rs`) In the future it would probably make sense to move the LCD module into the screen module.
83 lines
2.5 KiB
Rust
83 lines
2.5 KiB
Rust
use super::{Screen, Screens, Setup, Splash};
|
|
use crate::{lcd::Lcd, Input};
|
|
|
|
enum Selection {
|
|
Ch1,
|
|
Ch2,
|
|
Ch3,
|
|
Setup,
|
|
}
|
|
|
|
pub struct Home {
|
|
active: Selection,
|
|
}
|
|
|
|
impl Home {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
active: Selection::Ch1,
|
|
}
|
|
}
|
|
|
|
pub fn input(&self, input: &Input) -> Screens {
|
|
Screens::Home(Self {
|
|
active: match self.active {
|
|
Selection::Ch1 => match input {
|
|
Input::Next => Selection::Ch2,
|
|
Input::Previous => Selection::Setup,
|
|
Input::Select => return Screens::Splash(Splash),
|
|
Input::Back => Selection::Ch1,
|
|
},
|
|
Selection::Ch2 => match input {
|
|
Input::Next => Selection::Ch3,
|
|
Input::Previous => Selection::Ch1,
|
|
Input::Select => return Screens::Splash(Splash),
|
|
Input::Back => Selection::Ch2,
|
|
},
|
|
Selection::Ch3 => match input {
|
|
Input::Next => Selection::Setup,
|
|
Input::Previous => Selection::Ch2,
|
|
Input::Select => return Screens::Splash(Splash),
|
|
Input::Back => Selection::Ch3,
|
|
},
|
|
Selection::Setup => match input {
|
|
Input::Next => Selection::Ch1,
|
|
Input::Previous => Selection::Ch3,
|
|
Input::Select => return Screens::Setup(Setup::new()),
|
|
Input::Back => Selection::Setup,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
impl Screen for Home {
|
|
fn draw(&self, lcd: &mut Lcd) {
|
|
match &self.active {
|
|
Selection::Ch1 => {
|
|
lcd.print_inverted(0, 0, "CH1");
|
|
lcd.print(0, 2, "CH2");
|
|
lcd.print(0, 4, "CH3");
|
|
lcd.print(33, 6, "SETUP");
|
|
}
|
|
Selection::Ch2 => {
|
|
lcd.print(0, 0, "CH1");
|
|
lcd.print_inverted(0, 2, "CH2");
|
|
lcd.print(0, 4, "CH3");
|
|
lcd.print(33, 6, "SETUP");
|
|
}
|
|
Selection::Ch3 => {
|
|
lcd.print(0, 0, "CH1");
|
|
lcd.print(0, 2, "CH2");
|
|
lcd.print_inverted(0, 4, "CH3");
|
|
lcd.print(33, 6, "SETUP");
|
|
}
|
|
Selection::Setup => {
|
|
lcd.print(0, 0, "CH1");
|
|
lcd.print(0, 2, "CH2");
|
|
lcd.print(0, 4, "CH3");
|
|
lcd.print_inverted(33, 6, "SETUP");
|
|
}
|
|
}
|
|
}
|
|
}
|