diff --git a/src/main.rs b/src/main.rs index 9c8dfc4..b86b9f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -384,5 +384,5 @@ fn log_screen_error(error: &E) where E: core::fmt::Debug, { - error!("TODO: {error:?}"); + error!("graphics failed: {error:?}"); } diff --git a/src/screen.rs b/src/screen.rs index e3fc88a..065d6e6 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -1,7 +1,5 @@ //! Screen Output -use alloc::vec; - use embedded_graphics::prelude::*; use embedded_graphics::{geometry, mono_font, pixelcolor, primitives, text}; @@ -46,13 +44,6 @@ where { let num_signals = data.len(); - if num_signals == 0 { - return clear(target); - } - - #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] - let sig_width = (WIDTH as i32) / (num_signals as i32); - let text_style = mono_font::MonoTextStyle::new(&profont::PROFONT_24_POINT, pixelcolor::Rgb565::WHITE); let blank_style = primitives::PrimitiveStyleBuilder::new() @@ -79,6 +70,21 @@ where .into_styled(style) .draw(target)?; + if num_signals == 0 { + text::Text::with_alignment( + "No upcoming SGs", + geometry::Point::new(i32::from(WIDTH) / 2, 130), + text_style, + text::Alignment::Center, + ) + .draw(target)?; + + return Ok(()); + } + + #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] + let sig_width = i32::from(WIDTH) / (num_signals as i32); + for (idx, sig) in data.iter().enumerate() { #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] let offset = (idx as i32) * sig_width; @@ -96,7 +102,7 @@ where }; primitives::Circle::new( geometry::Point::new(offset + circle_margin, 10), - circle_dia as u32, + circle_dia.cast_unsigned(), ) .into_styled(style) .draw(target)?; @@ -105,7 +111,7 @@ where // draw maneuver text::Text::with_alignment( - &alloc::format!("{}", maneuver_to_str(&sig.maneuver)), + &maneuver_to_str(sig.maneuver), geometry::Point::new(centerline, 130), text_style, text::Alignment::Center, @@ -149,24 +155,24 @@ where clear(target)?; - let sig_width = (WIDTH as i32) / 3; + let sig_width = i32::from(WIDTH) / 3; let circle_dia = 50; let circle_margin = (sig_width - circle_dia) / 2; - for (idx, style) in vec![rd_style, ye_style, gn_style].iter().enumerate() { + for (idx, style) in [rd_style, ye_style, gn_style].iter().enumerate() { #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] let offset = (idx as i32) * sig_width; primitives::Circle::new( geometry::Point::new(offset + circle_margin, 10), - circle_dia as u32, + circle_dia.cast_unsigned(), ) .into_styled(*style) .draw(target)?; } // draw welcome text - let centerline = (WIDTH as i32) / 2; + let centerline = i32::from(WIDTH) / 2; text::Text::with_alignment( "C-ITS Signal Phase Display\nWaiting for GNSS fix...", geometry::Point::new(centerline, 130), @@ -178,7 +184,7 @@ where Ok(()) } -fn maneuver_to_str(value: &applogic::v2x::map::Maneuvers) -> alloc::string::String { +fn maneuver_to_str(value: applogic::v2x::map::Maneuvers) -> alloc::string::String { alloc::format!( "{}{}{}", if value.left_allowed { "<" } else { " " },