fw-rust: Break everything down in multiple files
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.
This commit is contained in:
finga 2022-03-17 12:03:22 +01:00
parent 91e120b258
commit c2920ea334
7 changed files with 693 additions and 647 deletions

View file

@ -0,0 +1,82 @@
use super::{Home, Screen, Screens, Splash};
use crate::{lcd::Lcd, Input};
enum Selection {
Contrast,
Backlight,
Back,
}
pub struct Setup {
active: Selection,
}
impl Setup {
pub fn new() -> Self {
Self {
active: Selection::Contrast,
}
}
pub fn input(&self, input: &Input) -> Screens {
Screens::Setup(Self {
active: match self.active {
Selection::Contrast => match input {
Input::Next => Selection::Backlight,
Input::Previous => Selection::Back,
Input::Select => return Screens::Splash(Splash),
Input::Back => return Screens::Home(Home::new()),
},
Selection::Backlight => match input {
Input::Next => Selection::Back,
Input::Previous => Selection::Contrast,
Input::Select => return Screens::Splash(Splash),
Input::Back => return Screens::Home(Home::new()),
},
Selection::Back => match input {
Input::Next => Selection::Contrast,
Input::Previous => Selection::Backlight,
Input::Select => return Screens::Home(Home::new()),
Input::Back => return Screens::Home(Home::new()),
},
},
})
}
}
impl Screen for Setup {
fn draw(&self, lcd: &mut Lcd) {
match &self.active {
Selection::Contrast => {
lcd.fill_area(0, 0, 33, 2, 0xFF);
lcd.print_inverted(33, 0, "SETUP");
lcd.fill_area(69, 0, 33, 2, 0xFF);
lcd.print_inverted(0, 2, "CONTRAST:");
lcd.print(89, 2, "00");
lcd.print(0, 4, "BACKLIGHT:");
lcd.print(83, 4, "000");
lcd.print(36, 6, "BACK");
}
Selection::Backlight => {
lcd.fill_area(0, 0, 33, 2, 0xFF);
lcd.print_inverted(33, 0, "SETUP");
lcd.fill_area(69, 0, 33, 2, 0xFF);
lcd.print(0, 2, "CONTRAST:");
lcd.print(89, 2, "00");
lcd.print_inverted(0, 4, "BACKLIGHT:");
lcd.print(83, 4, "000");
lcd.print(36, 6, "BACK");
}
Selection::Back => {
lcd.fill_area(0, 0, 33, 2, 0xFF);
lcd.print_inverted(33, 0, "SETUP");
lcd.fill_area(69, 0, 33, 2, 0xFF);
lcd.print(0, 2, "CONTRAST:");
lcd.print(89, 2, "00");
lcd.print(0, 4, "BACKLIGHT:");
lcd.print(83, 4, "000");
lcd.print_inverted(36, 6, "BACK");
}
}
}
}