clock_generator/firmware/rust/src/screen/home.rs
finga 343b95dc78
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
fw-rust: Refactor printing to the LCD
Pass iterators for control and display data to the printing function
instead of just printing it.
2022-04-10 18:18:37 +02:00

94 lines
3.2 KiB
Rust

use super::{Channel, Event, Screens, Setup};
use crate::{lcd::Lcd, screen::ClockChannel, 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(&mut self, input: &Input, channels: [ClockChannel; 3]) -> Event {
self.active = match self.active {
Selection::Ch1 => match input {
Input::Next => Selection::Ch2,
Input::Previous => Selection::Setup,
Input::Select => return Event::Screen(Screens::Channel(Channel::new(channels[0]))),
Input::Back => Selection::Ch1,
},
Selection::Ch2 => match input {
Input::Next => Selection::Ch3,
Input::Previous => Selection::Ch1,
Input::Select => return Event::Screen(Screens::Channel(Channel::new(channels[1]))),
Input::Back => Selection::Ch2,
},
Selection::Ch3 => match input {
Input::Next => Selection::Setup,
Input::Previous => Selection::Ch2,
Input::Select => return Event::Screen(Screens::Channel(Channel::new(channels[2]))),
Input::Back => Selection::Ch3,
},
Selection::Setup => match input {
Input::Next => Selection::Ch1,
Input::Previous => Selection::Ch3,
Input::Select => return Event::Screen(Screens::Setup(Setup::new())),
Input::Back => Selection::Setup,
},
};
Event::None
}
pub fn draw(&self, lcd: &mut Lcd, channels: [ClockChannel; 3]) {
match &self.active {
Selection::Ch1 => {
lcd.print(0, 0, true, "CH1");
channels[0].print(lcd, 0);
lcd.print(0, 2, false, "CH2");
channels[1].print(lcd, 2);
lcd.print(0, 4, false, "CH3");
channels[2].print(lcd, 4);
lcd.print(33, 6, false, "SETUP");
}
Selection::Ch2 => {
lcd.print(0, 0, false, "CH1");
channels[0].print(lcd, 0);
lcd.print(0, 2, true, "CH2");
channels[1].print(lcd, 2);
lcd.print(0, 4, false, "CH3");
channels[2].print(lcd, 4);
lcd.print(33, 6, false, "SETUP");
}
Selection::Ch3 => {
lcd.print(0, 0, false, "CH1");
channels[0].print(lcd, 0);
lcd.print(0, 2, false, "CH2");
channels[1].print(lcd, 2);
lcd.print(0, 4, true, "CH3");
channels[2].print(lcd, 4);
lcd.print(33, 6, false, "SETUP");
}
Selection::Setup => {
lcd.print(0, 0, false, "CH1");
channels[0].print(lcd, 0);
lcd.print(0, 2, false, "CH2");
channels[1].print(lcd, 2);
lcd.print(0, 4, false, "CH3");
channels[2].print(lcd, 4);
lcd.print(33, 6, true, "SETUP");
}
}
}
}