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),