clock_generator/firmware/rust/src/screen/setup.rs
finga 7d8f5f6870
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
fw-rust: Create a print u8 function for setup
Create `print_u8()` helper function to print `u8` primitives to
lcd. Refactor contrast and backlight variables to also keep them in a
global `AtomicU8`.
2022-03-21 12:46:18 +01:00

87 lines
3 KiB
Rust

use super::{Home, Screen, Screens, Splash};
use crate::{lcd::Lcd, Input, BACKLIGHT, CONTRAST};
use core::sync::atomic::Ordering;
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) {
let contrast = CONTRAST.load(Ordering::SeqCst);
let backlight = BACKLIGHT.load(Ordering::SeqCst);
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_u8(89, 2, 2, contrast);
lcd.print(0, 4, "BACKLIGHT:");
lcd.print_u8(83, 2, 3, backlight);
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_u8(89, 2, 2, contrast);
lcd.print_inverted(0, 4, "BACKLIGHT:");
lcd.print_u8(83, 2, 3, backlight);
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_u8(89, 2, 2, contrast);
lcd.print(0, 4, "BACKLIGHT:");
lcd.print_u8(83, 2, 3, backlight);
lcd.print_inverted(36, 6, "BACK");
}
}
}
}