fw-rust: Refactor everything
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Remove avr-eeprom dependency for now and introduce events.
This commit is contained in:
finga 2022-03-30 19:29:32 +02:00
parent 6cd8df515d
commit fdd1f4636d
9 changed files with 459 additions and 263 deletions

View file

@ -1,4 +1,4 @@
use super::{Screen, Screens, Setup, Splash};
use super::{Draw, Event, Screens, Setup, Splash};
use crate::{lcd::Lcd, Input};
enum Selection {
@ -19,39 +19,39 @@ impl Home {
}
}
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,
},
pub fn input(&mut self, input: &Input) -> Event {
self.active = match self.active {
Selection::Ch1 => match input {
Input::Next => Selection::Ch2,
Input::Previous => Selection::Setup,
Input::Select => return Event::Screen(Screens::Splash(Splash)),
Input::Back => Selection::Ch1,
},
})
Selection::Ch2 => match input {
Input::Next => Selection::Ch3,
Input::Previous => Selection::Ch1,
Input::Select => return Event::Screen(Screens::Splash(Splash)),
Input::Back => Selection::Ch2,
},
Selection::Ch3 => match input {
Input::Next => Selection::Setup,
Input::Previous => Selection::Ch2,
Input::Select => return Event::Screen(Screens::Splash(Splash)),
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
}
}
impl Screen for Home {
impl Draw for Home {
fn draw(&self, lcd: &mut Lcd) {
match &self.active {
Selection::Ch1 => {