fw-rust: Create a print u8 function for setup
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Create `print_u8()` helper function to print `u8` primitives to
lcd. Refactor contrast and backlight variables to also keep them in a
global `AtomicU8`.
This commit is contained in:
finga 2022-03-19 18:40:18 +01:00
parent c2920ea334
commit 7d8f5f6870
3 changed files with 55 additions and 14 deletions

View file

@ -1,5 +1,6 @@
use super::{Home, Screen, Screens, Splash};
use crate::{lcd::Lcd, Input};
use crate::{lcd::Lcd, Input, BACKLIGHT, CONTRAST};
use core::sync::atomic::Ordering;
enum Selection {
Contrast,
@ -46,15 +47,18 @@ impl Setup {
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(89, 2, "00");
lcd.print_u8(89, 2, 2, contrast);
lcd.print(0, 4, "BACKLIGHT:");
lcd.print(83, 4, "000");
lcd.print_u8(83, 2, 3, backlight);
lcd.print(36, 6, "BACK");
}
Selection::Backlight => {
@ -62,9 +66,9 @@ impl Screen for Setup {
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_u8(89, 2, 2, contrast);
lcd.print_inverted(0, 4, "BACKLIGHT:");
lcd.print(83, 4, "000");
lcd.print_u8(83, 2, 3, backlight);
lcd.print(36, 6, "BACK");
}
Selection::Back => {
@ -72,9 +76,9 @@ impl Screen for Setup {
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_u8(89, 2, 2, contrast);
lcd.print(0, 4, "BACKLIGHT:");
lcd.print(83, 4, "000");
lcd.print_u8(83, 2, 3, backlight);
lcd.print_inverted(36, 6, "BACK");
}
}