fw-rust: Break everything down in multiple files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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:
parent
91e120b258
commit
c2920ea334
7 changed files with 693 additions and 647 deletions
83
firmware/rust/src/screen/home.rs
Normal file
83
firmware/rust/src/screen/home.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
firmware/rust/src/screen/mod.rs
Normal file
30
firmware/rust/src/screen/mod.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
mod home;
|
||||
mod setup;
|
||||
mod splash;
|
||||
|
||||
use crate::{lcd::Lcd, Input};
|
||||
pub use home::Home;
|
||||
pub use setup::Setup;
|
||||
pub use splash::Splash;
|
||||
|
||||
// TODO: Only update changes instead of whole screen
|
||||
|
||||
pub trait Screen {
|
||||
fn draw(&self, lcd: &mut Lcd);
|
||||
}
|
||||
|
||||
pub enum Screens {
|
||||
Splash(Splash),
|
||||
Home(Home),
|
||||
Setup(Setup),
|
||||
}
|
||||
|
||||
impl Screens {
|
||||
pub fn input(&mut self, input: &Input) {
|
||||
match self {
|
||||
Screens::Splash(_) => {}
|
||||
Screens::Home(home) => *self = home.input(input),
|
||||
Screens::Setup(setup) => *self = setup.input(input),
|
||||
}
|
||||
}
|
||||
}
|
82
firmware/rust/src/screen/setup.rs
Normal file
82
firmware/rust/src/screen/setup.rs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
firmware/rust/src/screen/splash.rs
Normal file
48
firmware/rust/src/screen/splash.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
use super::Screen;
|
||||
use crate::{
|
||||
assets::{ONDERS_ORG, SACRED_CHAO},
|
||||
lcd::Lcd,
|
||||
};
|
||||
use atmega_hal::{clock::MHz8, delay::Delay};
|
||||
use embedded_hal::{blocking::delay::DelayMs, spi::FullDuplex};
|
||||
use nb::block;
|
||||
|
||||
pub struct Splash;
|
||||
|
||||
impl Screen for Splash {
|
||||
fn draw(&self, lcd: &mut Lcd) {
|
||||
let mut delay = Delay::<MHz8>::new();
|
||||
|
||||
for (i, page) in SACRED_CHAO.iter().enumerate() {
|
||||
lcd.move_cursor(31, 1 + i as u8);
|
||||
|
||||
// TODO: This delay fixes issues, try find a better solution
|
||||
delay.delay_ms(1_u8);
|
||||
lcd.cd.set_high();
|
||||
|
||||
for segment in page {
|
||||
block!(lcd.spi.send(*segment)).unwrap();
|
||||
}
|
||||
|
||||
// TODO: This delay fixes issues, try find a better solution
|
||||
delay.delay_ms(1_u8);
|
||||
lcd.cd.set_low();
|
||||
}
|
||||
|
||||
for (i, page) in ONDERS_ORG.iter().enumerate() {
|
||||
lcd.move_cursor(27, 6 + i as u8);
|
||||
|
||||
// TODO: This delay fixes issues, try find a better solution
|
||||
delay.delay_ms(1_u8);
|
||||
lcd.cd.set_high();
|
||||
|
||||
for segment in page {
|
||||
block!(lcd.spi.send(*segment)).unwrap();
|
||||
}
|
||||
|
||||
// TODO: This delay fixes issues, try find a better solution
|
||||
delay.delay_ms(1_u8);
|
||||
lcd.cd.set_low();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue