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

Add new function for easier instantiation and refactor the input
function.
This commit is contained in:
finga 2022-03-15 19:03:36 +01:00
parent 2ec8d1aeb9
commit 0003717408

View file

@ -426,38 +426,34 @@ struct HomeScreen {
}
impl HomeScreen {
fn input(&self, input: &Input) -> Screens {
match input {
Input::Next => match self.active {
HomeSelection::Ch1 => Screens::Home(HomeScreen {
active: HomeSelection::Ch2,
}),
HomeSelection::Ch2 => Screens::Home(HomeScreen {
active: HomeSelection::Ch3,
}),
HomeSelection::Ch3 => Screens::Home(HomeScreen {
active: HomeSelection::Setup,
}),
HomeSelection::Setup => Screens::Home(HomeScreen {
active: HomeSelection::Ch1,
}),
},
Input::Previous => match self.active {
HomeSelection::Ch1 => Screens::Home(HomeScreen {
active: HomeSelection::Setup,
}),
HomeSelection::Ch2 => Screens::Home(HomeScreen {
active: HomeSelection::Ch1,
}),
HomeSelection::Ch3 => Screens::Home(HomeScreen {
active: HomeSelection::Ch2,
}),
HomeSelection::Setup => Screens::Home(HomeScreen {
active: HomeSelection::Ch3,
}),
},
fn new() -> Self {
Self {
active: HomeSelection::Ch1,
}
}
fn input(&self, input: &Input) -> Screens {
Screens::Home(Self {
active: match self.active {
HomeSelection::Ch1 => match input {
Input::Next => HomeSelection::Ch2,
Input::Previous => HomeSelection::Setup,
},
HomeSelection::Ch2 => match input {
Input::Next => HomeSelection::Ch3,
Input::Previous => HomeSelection::Ch1,
},
HomeSelection::Ch3 => match input {
Input::Next => HomeSelection::Setup,
Input::Previous => HomeSelection::Ch2,
},
HomeSelection::Setup => match input {
Input::Next => HomeSelection::Ch1,
Input::Previous => HomeSelection::Ch3,
},
},
})
}
}
impl Draw for HomeScreen {
@ -586,9 +582,7 @@ fn main() -> ! {
delay.delay_ms(2000_u16);
// Set home screen
screen = Screens::Home(HomeScreen {
active: HomeSelection::Ch1,
});
screen = Screens::Home(HomeScreen::new());
// Draw screen
lcd.draw(&screen);