From 00cdff615a91541fce51d83caabcc4033f0c3b4c Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sat, 22 Feb 2025 18:50:20 +0100 Subject: [PATCH] Squashed commit of the following: commit 9f6c282e48c620afc8c4937c050ad5136d0e6057 Author: Valentin Weber Date: Sat Feb 22 18:42:03 2025 +0100 feat: move proporional font functonality to feature commit 36f748c092fc8393feff58e1741ac6afa3914e67 Author: Valentin Weber Date: Sat Feb 22 02:51:54 2025 +0100 chore: clean up LICENSE-MIT copyriht notice commit fe3abd83d7206a6ff8cb1980ab3f7b48e9a3aa03 Author: Valentin Weber Date: Fri Feb 21 22:28:40 2025 +0100 feat: Move to proportional font To use the available space on the bade more efficient, I changed the font to u8g2_font_lucasfont_alternate_tf from [u8g2-fonts](https://docs.rs/crate/u8g2-fonts/). Lucasfont Alternate was created by Patrick Lauke and is licensed under [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/). No changes to the font were made. --- Cargo.toml | 3 ++- src/main.rs | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a60d33..d1be3d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ embedded-graphics = ["dep:embedded-graphics"] serde = ["dep:serde"] usb-hid = ["dep:hidapi"] ble = ["dep:btleplug", "dep:uuid", "dep:tokio"] +u8g2-fonts = ["dep:u8g2-fonts"] [dependencies] anyhow = "1.0.95" @@ -50,4 +51,4 @@ serde_json = { version = "1.0.134", optional = true } time = "0.3.37" toml = { version = "0.8.19", optional = true } zerocopy = { version = "0.8.14", features = ["derive"] } -u8g2-fonts = { version = "0.5.2", features = ["embedded_graphics_textstyle"] } +u8g2-fonts = { version = "0.5.2", features = ["embedded_graphics_textstyle"], optional = true} diff --git a/src/main.rs b/src/main.rs index 8e4ed95..089da3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,10 @@ use embedded_graphics::{ Drawable, Pixel, }; use serde::Deserialize; + +#[cfg(not(any(feature = "u8g2-fonts")))] +use embedded_graphics::mono_font::{iso_8859_1::FONT_6X9, MonoTextStyle}; +#[cfg(feature = "u8g2-fonts")] use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle}; #[derive(Parser)] @@ -106,7 +110,7 @@ fn main() -> Result<()> { return list_devices(&args.transport); } - let payload = gnerate_payload(&mut args)?; + let payload = generate_payload(&mut args)?; write_payload(&args.transport, payload) } @@ -132,7 +136,7 @@ fn list_devices(transport: &TransportProtocol) -> Result<()> { Ok(()) } -fn gnerate_payload(args: &mut Args) -> Result { +fn generate_payload(args: &mut Args) -> Result { let config_path = args.config.take().unwrap_or_default(); let config = fs::read_to_string(&config_path) .with_context(|| format!("load config: {config_path:?}"))?; @@ -161,8 +165,18 @@ fn gnerate_payload(args: &mut Args) -> Result { style = style.border(); } style = style.speed(message.speed).mode(message.mode); + match message.content { Content::Text { text } => { + + #[cfg(not(any(feature = "u8g2-fonts")))] + let text = Text::new( + &text, + Point::new(0, 8), + U8g2TextStyle::new(u8g2_font_lucasfont_alternate_tf, BinaryColor::On), + ); + + #[cfg(feature = "u8g2-fonts")] let text = Text::new( &text, Point::new(0, 8),