WIP Add graphics
This commit is contained in:
parent
c29eb92388
commit
a8434b76d4
6 changed files with 72 additions and 13 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -1216,6 +1216,7 @@ dependencies = [
|
||||||
"prost",
|
"prost",
|
||||||
"prost-build",
|
"prost-build",
|
||||||
"static_cell",
|
"static_cell",
|
||||||
|
"tinytga",
|
||||||
"trouble-host",
|
"trouble-host",
|
||||||
"ublox",
|
"ublox",
|
||||||
]
|
]
|
||||||
|
|
@ -2529,6 +2530,16 @@ dependencies = [
|
||||||
"cfg-if",
|
"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]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "1.1.1+spec-1.1.0"
|
version = "1.1.1+spec-1.1.0"
|
||||||
|
|
|
||||||
|
|
@ -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)
|
# enable some debug printing (without enabling debug logging of the ESP RTOS)
|
||||||
spat_debug = []
|
spat_debug = []
|
||||||
# enable ST7789 based display
|
# 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
|
# enable I/O via UART
|
||||||
uart = ["_uart", "_gnss"]
|
uart = ["_uart", "_gnss"]
|
||||||
# enable I/O via BLE
|
# 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"] }
|
num-traits = { version = "0.2.19", default-features = false, features = ["libm"] }
|
||||||
profont = { version = "0.7.0", optional = true }
|
profont = { version = "0.7.0", optional = true }
|
||||||
prost = { version = "0.14", default-features = false, features = ["derive"] }
|
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"] }
|
ublox = { version = "0.10", optional = true, default-features = false, features = ["alloc", "ubx_proto27"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
||||||
13
Readme.md
13
Readme.md
|
|
@ -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
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
||||||
BIN
graphics/Sinnbild_Radfahrer_StVO_1992-25px-black.tga
Normal file
BIN
graphics/Sinnbild_Radfahrer_StVO_1992-25px-black.tga
Normal file
Binary file not shown.
BIN
graphics/Sinnbild_Radfahrer_StVO_1992-25px-white.tga
Normal file
BIN
graphics/Sinnbild_Radfahrer_StVO_1992-25px-white.tga
Normal file
Binary file not shown.
|
|
@ -23,6 +23,10 @@ where
|
||||||
prev_state: ScreenState,
|
prev_state: ScreenState,
|
||||||
hb_state: bool,
|
hb_state: bool,
|
||||||
gnss_hb_state: bool,
|
gnss_hb_state: bool,
|
||||||
|
|
||||||
|
// assets
|
||||||
|
#[cfg(feature = "spat")]
|
||||||
|
bike_image: tinytga::Tga<'static, pixelcolor::Rgb565>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq)]
|
#[derive(Debug, Default, PartialEq, Eq)]
|
||||||
|
|
@ -94,12 +98,19 @@ where
|
||||||
const BIG_HEIGHT_THLD: u16 = 172;
|
const BIG_HEIGHT_THLD: u16 = 172;
|
||||||
|
|
||||||
pub fn new(target: D, display_size: DisplaySize) -> Self {
|
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 {
|
Self {
|
||||||
target,
|
target,
|
||||||
size: display_size,
|
size: display_size,
|
||||||
prev_state: ScreenState::Uninitialized,
|
prev_state: ScreenState::Uninitialized,
|
||||||
hb_state: false,
|
hb_state: false,
|
||||||
gnss_hb_state: false,
|
gnss_hb_state: false,
|
||||||
|
#[cfg(feature = "spat")]
|
||||||
|
bike_image,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -356,22 +367,38 @@ where
|
||||||
.draw(&mut self.target)?;
|
.draw(&mut self.target)?;
|
||||||
|
|
||||||
// mark bike lanes which are not a vehicle lane, too
|
// 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) {
|
} 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 {
|
} 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
|
// draw maneuver
|
||||||
text::Text::with_alignment(
|
text::Text::with_alignment(
|
||||||
&maneuver_to_str(sig.maneuver),
|
&maneuver_to_str(sig.maneuver),
|
||||||
|
|
@ -449,6 +476,13 @@ where
|
||||||
|
|
||||||
// draw welcome text
|
// draw welcome text
|
||||||
let centerline = i32::from(self.size.width) / 2;
|
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(
|
text::Text::with_alignment(
|
||||||
"C-ITS Signal Phase\nWaiting for GNSS...",
|
"C-ITS Signal Phase\nWaiting for GNSS...",
|
||||||
geometry::Point::new(centerline, 130 + self.size.offset_top),
|
geometry::Point::new(centerline, 130 + self.size.offset_top),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue