Add parameters to end screen

This commit is contained in:
Max Känner 2023-02-01 16:55:17 +01:00
parent adf731dd29
commit ab775e32de
2 changed files with 36 additions and 7 deletions

View File

@ -88,21 +88,50 @@ pub fn draw_driving(screen: &mut Screen, font: &Font) {
} }
#[allow(clippy::similar_names)] #[allow(clippy::similar_names)]
pub fn draw_finished(screen: &mut Screen, time: Duration, font: &Font) { pub fn draw_finished(
screen: &mut Screen,
time: Duration,
(k_p, k_i, k_d): (f32, f32, f32),
v: i32,
font: &Font,
) {
clear(screen); clear(screen);
#[allow(clippy::cast_precision_loss)] #[allow(clippy::cast_precision_loss)]
let text_scale = Scale::uniform(screen.yres() as f32 / 2.0 - 8.0); let text_scale = Scale::uniform(screen.yres() as f32 / 4.0 - 8.0);
#[allow(clippy::cast_precision_loss)]
let time_scale = Scale::uniform(screen.yres() as f32 / 2.0 - 8.0);
#[allow(clippy::cast_precision_loss)]
let value_scale = Scale {
x: screen.xres() as f32 / 10.0,
y: screen.yres() as f32 / 4.0 - 8.0,
};
let xres = i32::try_from(screen.xres()).expect("range checked"); let xres = i32::try_from(screen.xres()).expect("range checked");
let yres = i32::try_from(screen.yres()).expect("range checked"); let yres = i32::try_from(screen.yres()).expect("range checked");
draw_centered_text(screen, xres / 2, 4, text_scale, font, "Zeit:"); draw_centered_text(screen, xres / 2, 4, text_scale, font, "Zeit:");
draw_centered_text( draw_centered_text(
screen, screen,
xres / 2, xres / 2,
yres / 2 + 4, yres / 4 + 4,
text_scale, time_scale,
font, font,
format!("{:.2}s", time.as_secs_f32()).as_str(), format!("{:.2}s", time.as_secs_f32()).as_str(),
); );
macro_rules! draw_param {
($param: ident, $index: literal) => {
draw_centered_text(
screen,
xres * (1 + 2 * $index) / 8,
yres * 3 / 4 + 4,
value_scale,
font,
format!("{:.2}", $param).as_str(),
);
};
}
draw_param!(k_p, 0);
draw_param!(k_i, 1);
draw_param!(k_d, 2);
draw_param!(v, 3);
screen.update(); screen.update();
} }
@ -115,7 +144,7 @@ fn draw_setting(
screen: &mut Screen, screen: &mut Screen,
value: impl Display, value: impl Display,
selected: bool, selected: bool,
index: u8, index: i32,
name: &str, name: &str,
font: &Font, font: &Font,
) { ) {
@ -128,7 +157,7 @@ fn draw_setting(
}; };
let xres = i32::try_from(screen.xres()).expect("range checked"); let xres = i32::try_from(screen.xres()).expect("range checked");
let yres = i32::try_from(screen.yres()).expect("range checked"); let yres = i32::try_from(screen.yres()).expect("range checked");
let x = xres / 8 + xres * i32::from(index) / 4; let x = xres * (1 + 2 * index) / 8;
draw_centered_text(screen, x, yres / 4 + 4, text_scale, font, name); draw_centered_text(screen, x, yres / 4 + 4, text_scale, font, name);
draw_centered_text( draw_centered_text(
screen, screen,

View File

@ -52,7 +52,7 @@ fn main() -> Result<(), Box<dyn Error>> {
e => e?, e => e?,
}; };
draw_finished(&mut screen, time, &font); draw_finished(&mut screen, time, (k_p, k_i, k_d), v, &font);
buttons.process(); buttons.process();
while !buttons.is_enter_pressed() { while !buttons.is_enter_pressed() {
buttons.process(); buttons.process();