Watch
0
0
Fork
You've already forked esp32-c_its-companion
0

WIP Add graphics

This commit is contained in:
Jannik Beyerstedt 2026-09-07 12:34:58 +02:00
commit a8434b76d4
6 changed files with 72 additions and 13 deletions

11
Cargo.lock generated
View file

@ -1216,6 +1216,7 @@ dependencies = [
"prost",
"prost-build",
"static_cell",
"tinytga",
"trouble-host",
"ublox",
]
@ -2529,6 +2530,16 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "tinytga"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "477839bd612acb4d0551915eaf6eef8cc1b3a9dd58e18e9c2b746c78614a25d5"
dependencies = [
"embedded-graphics",
"nom",
]
[[package]]
name = "toml_datetime"
version = "1.1.1+spec-1.1.0"

View file

@ -53,7 +53,7 @@ spat = ["c-its-parser/spatem", "c-its-parser/mapem"]
# enable some debug printing (without enabling debug logging of the ESP RTOS)
spat_debug = []
# enable ST7789 based display
screen = ["dep:mipidsi", "dep:embedded-graphics", "dep:embedded-hal-bus", "dep:profont"]
screen = ["dep:mipidsi", "dep:embedded-graphics", "dep:embedded-hal-bus", "dep:profont", "dep:tinytga"]
# enable I/O via UART
uart = ["_uart", "_gnss"]
# enable I/O via BLE
@ -123,6 +123,7 @@ mipidsi = { version = "0.10.0", optional = true }
num-traits = { version = "0.2.19", default-features = false, features = ["libm"] }
profont = { version = "0.7.0", optional = true }
prost = { version = "0.14", default-features = false, features = ["derive"] }
tinytga = { version = "0.5.0", optional = true }
ublox = { version = "0.10", optional = true, default-features = false, features = ["alloc", "ubx_proto27"] }
[dev-dependencies]

View file

@ -119,3 +119,16 @@ The unit tests in this project are meant to be run on the host:
```
cargo test --target host-tuple --bin test --no-default-features -F std,spat
```
## Tips and Tricks
### Create TGA Assets
Images are loaded as TGA assets, but shall not have an alpha channel.
You can convert them using [ImageMagick](https://imagemagick.org) like this:
```shell
# resize to 25px height, adding a black background to the white symbol and vice versa
magick Sinnbild_Radfahrer_StVO_1992-200px-white.png -resize x25 -background black -alpha background -flatten -alpha off -verbose Sinnbild_Radfahrer_StVO_1992-25px-white.tga
magick Sinnbild_Radfahrer_StVO_1992-200px-black.png -resize x25 -background white -alpha background -flatten -alpha off -verbose Sinnbild_Radfahrer_StVO_1992-25px-black.tga
```

Binary file not shown.

Binary file not shown.

View file

@ -23,6 +23,10 @@ where
prev_state: ScreenState,
hb_state: bool,
gnss_hb_state: bool,
// assets
#[cfg(feature = "spat")]
bike_image: tinytga::Tga<'static, pixelcolor::Rgb565>,
}
#[derive(Debug, Default, PartialEq, Eq)]
@ -94,12 +98,19 @@ where
const BIG_HEIGHT_THLD: u16 = 172;
pub fn new(target: D, display_size: DisplaySize) -> Self {
#[cfg(feature = "spat")]
let data = include_bytes!("../graphics/Sinnbild_Radfahrer_StVO_1992-25px-white.tga");
#[cfg(feature = "spat")]
let bike_image = tinytga::Tga::from_slice(data).expect("Failed to parse TGA image");
Self {
target,
size: display_size,
prev_state: ScreenState::Uninitialized,
hb_state: false,
gnss_hb_state: false,
#[cfg(feature = "spat")]
bike_image,
}
}
@ -356,22 +367,38 @@ where
.draw(&mut self.target)?;
// mark bike lanes which are not a vehicle lane, too
let lane_type_symbol = if sig.usages.contains(&applogic::v2x::map::UsageType::Vehicle) {
" "
let lane_symbol_y_pos = 75;
if sig.usages.contains(&applogic::v2x::map::UsageType::Vehicle) {
// clear area
primitives::Rectangle::new(
geometry::Point::new(
centerline - (45 / 2),
lane_symbol_y_pos + self.size.offset_top,
), // TODO: check correct position
geometry::Size::new(45, 25),
)
.into_styled(Self::BK_STYLE)
.draw(&mut self.target)?;
} else if sig.usages.contains(&applogic::v2x::map::UsageType::Bike) {
"B" // TODO: rather do a bike symbol?
// bike symbol (45x25px)
embedded_graphics::image::Image::new(
&self.bike_image,
geometry::Point::new(
centerline - (45 / 2) + 2,
lane_symbol_y_pos + self.size.offset_top,
),
)
.draw(&mut self.target)?;
} else {
"?"
text::Text::with_alignment(
"?",
geometry::Point::new(centerline, lane_symbol_y_pos + 24 + self.size.offset_top),
Self::DEFAULT_TEXT_STYLE,
text::Alignment::Center,
)
.draw(&mut self.target)?;
};
text::Text::with_alignment(
&lane_type_symbol,
geometry::Point::new(centerline, 100 + self.size.offset_top),
Self::DEFAULT_TEXT_STYLE,
text::Alignment::Center,
)
.draw(&mut self.target)?;
// draw maneuver
text::Text::with_alignment(
&maneuver_to_str(sig.maneuver),
@ -449,6 +476,13 @@ where
// draw welcome text
let centerline = i32::from(self.size.width) / 2;
embedded_graphics::image::Image::new(
&self.bike_image,
geometry::Point::new(centerline - (45 / 2) + 2, 75 + self.size.offset_top),
)
.draw(&mut self.target)?;
text::Text::with_alignment(
"C-ITS Signal Phase\nWaiting for GNSS...",
geometry::Point::new(centerline, 130 + self.size.offset_top),