From e97ce74d6e5a2fd10a7706892512ff69cfb54603 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Fri, 21 Feb 2025 22:18:58 +0100 Subject: [PATCH 01/14] chore(typo): Fix typo in src/protocol.rs --- src/protocol.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/protocol.rs b/src/protocol.rs index 706b55e..80fdba4 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -54,7 +54,7 @@ impl Style { self } - /// Show a dotted border arround the display. + /// Show a dotted border around the display. /// ``` /// use badgemagic::protocol::Style; /// # ( @@ -241,7 +241,7 @@ impl Timestamp { /// Buffer to create a payload /// -/// A payload consits of up to 8 messages +/// A payload consists of up to 8 messages /// ``` /// # #[cfg(feature = "embedded-graphics")] /// # fn main() { @@ -368,7 +368,7 @@ impl PayloadBuffer { &self.data } - /// Convert the payload buffe into bytes (with padding) + /// Convert the payload buffer into bytes (with padding) #[allow(clippy::missing_panics_doc)] // should never panic #[must_use] pub fn into_padded_bytes(self) -> impl AsRef<[u8]> { From f69187d00fbc84efa8e8ab7608765de037543c40 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Fri, 21 Feb 2025 22:19:38 +0100 Subject: [PATCH 02/14] chore(typo): Fix typo in src/usb_hid.rs --- src/usb_hid.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usb_hid.rs b/src/usb_hid.rs index d9324c1..1d9e3ed 100644 --- a/src/usb_hid.rs +++ b/src/usb_hid.rs @@ -29,7 +29,7 @@ pub struct Device { } impl Device { - /// Return a list of all usb devies as a string representation + /// Return a list of all usb devices as a string representation pub fn list_all() -> Result> { let api = HidApi::new().context("create hid api")?; let devices = api.device_list(); From ce7d12fc582c2d4294cb170e49b3878aee0263af Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Fri, 21 Feb 2025 22:26:00 +0100 Subject: [PATCH 03/14] chore(typo): Fix typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd4ea88..664b701 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ chmod +x badgemagic ./badgemagic --help ``` -> Note: The windows and macOS build is not actively tested. Please try it out and report back whether it worked or any problems that might occour. +> Note: The windows and macOS build is not actively tested. Please try it out and report back whether it worked or any problems that might occur. If your system is not listed above (Linux / Windows on ARM, musl, etc.) or you want to do it anyway, you can install this tool from source: From 3724f16edf14c0cb07022b0548c1d198a050455f Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sat, 22 Feb 2025 11:20:02 +0100 Subject: [PATCH 04/14] Feat/u8g2 font lucasfont alternate tf (#1) * 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.lock | 11 +++++++++++ Cargo.toml | 3 ++- LICENSE-MIT | 1 + src/main.rs | 7 ++++--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 918d53b..f096b85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,7 @@ dependencies = [ "time", "tokio", "toml", + "u8g2-fonts", "uuid", "zerocopy", ] @@ -1038,6 +1039,16 @@ dependencies = [ "winnow", ] +[[package]] +name = "u8g2-fonts" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "132e15484caa39440cc9d6317c1f1980a13259234e630db2270ea2a2b1e5c4a2" +dependencies = [ + "embedded-graphics", + "embedded-graphics-core", +] + [[package]] name = "unicode-ident" version = "1.0.12" diff --git a/Cargo.toml b/Cargo.toml index 86272cd..6b7aa58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "badgemagic" version = "0.1.0" -authors = ["Martin Michaelis "] +authors = ["Martin Michaelis ", "Valentin Weber "] edition = "2021" description = "Badge Magic with LEDs - Library and CLI" homepage = "https://badgemagic.fossasia.org" @@ -50,3 +50,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"] } diff --git a/LICENSE-MIT b/LICENSE-MIT index dd968bb..8b49e53 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,4 +1,5 @@ Copyright 2024 Martin Michaelis +Copyright 2025 Valentin Weber Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal diff --git a/src/main.rs b/src/main.rs index fcbe5ff..f9be51e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,12 +13,12 @@ use clap::{Parser, ValueEnum}; use embedded_graphics::{ geometry::Point, image::{Image, ImageRawLE}, - mono_font::{iso_8859_1::FONT_6X9, MonoTextStyle}, pixelcolor::BinaryColor, text::Text, Drawable, Pixel, }; use serde::Deserialize; +use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle}; #[derive(Parser)] /// Upload a configuration with up to 8 messages to an LED badge @@ -161,9 +161,10 @@ fn gnerate_payload(args: &mut Args) -> Result { Content::Text { text } => { let text = Text::new( &text, - Point::new(0, 7), - MonoTextStyle::new(&FONT_6X9, BinaryColor::On), + Point::new(0, 8), + U8g2TextStyle::new(u8g2_font_lucasfont_alternate_tf, BinaryColor::On), ); + payload.add_message_drawable(style, &text); } Content::Bitstring { bitstring } => { From f13e4c215b807ee433293ea53bdccb175c40c55a Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sat, 22 Feb 2025 11:29:22 +0100 Subject: [PATCH 05/14] feat: Add support for brightness control (#3) --- Cargo.lock | 2 +- Cargo.toml | 2 +- examples/hello-world.rs | 4 ++-- src/main.rs | 8 ++++++-- src/protocol.rs | 41 +++++++++++++++++++++++++++++++++-------- 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f096b85..54b1bc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,7 +112,7 @@ dependencies = [ [[package]] name = "badgemagic" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index 6b7aa58..9a60d33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "badgemagic" -version = "0.1.0" +version = "0.2.0" authors = ["Martin Michaelis ", "Valentin Weber "] edition = "2021" description = "Badge Magic with LEDs - Library and CLI" diff --git a/examples/hello-world.rs b/examples/hello-world.rs index aa316b6..9360985 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -5,13 +5,13 @@ use badgemagic::{ embedded_graphics::{ geometry::Point, mono_font::MonoTextStyle, pixelcolor::BinaryColor, text::Text, }, - protocol::{Mode, PayloadBuffer, Style}, + protocol::{Brightness, Mode, PayloadBuffer, Style}, usb_hid::Device, util::DrawableLayoutExt, }; fn main() -> Result<()> { - let mut payload = PayloadBuffer::new(); + let mut payload = PayloadBuffer::new(Brightness::default()); payload.add_message_drawable( Style::default().mode(Mode::Center), diff --git a/src/main.rs b/src/main.rs index f9be51e..8e4ed95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::{fs, path::PathBuf}; use anyhow::{Context, Result}; use badgemagic::{ ble::Device as BleDevice, - protocol::{Mode, PayloadBuffer, Speed, Style}, + protocol::{Brightness, Mode, PayloadBuffer, Speed, Style}, usb_hid::Device as UsbDevice, }; use base64::Engine; @@ -43,6 +43,10 @@ struct Args { #[clap(long)] transport: TransportProtocol, + /// Brightness of the panel + #[clap(long)] + brightness: Option, + /// List all devices visible to a transport and exit #[clap(long)] list_devices: bool, @@ -146,7 +150,7 @@ fn gnerate_payload(args: &mut Args) -> Result { } }; - let mut payload = PayloadBuffer::new(); + let mut payload = PayloadBuffer::new(args.brightness.unwrap_or_default()); for message in config.messages { let mut style = Style::default(); diff --git a/src/protocol.rs b/src/protocol.rs index 80fdba4..2a05dfb 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -1,7 +1,5 @@ //! Protocol used to update the badge -use std::num::TryFromIntError; - #[cfg(feature = "embedded-graphics")] use embedded_graphics::{ draw_target::DrawTarget, @@ -11,6 +9,7 @@ use embedded_graphics::{ primitives::Rectangle, Drawable, }; +use std::num::TryFromIntError; use time::OffsetDateTime; use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U16}; @@ -161,7 +160,7 @@ impl TryFrom for Speed { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] pub enum Mode { - /// Scroll thorugh the message from left to right + /// Scroll through the message from left to right #[default] Left, @@ -193,14 +192,39 @@ pub enum Mode { Laser, } +/// Display Brightness +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "cli", derive(clap::ValueEnum))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))] +pub enum Brightness { + #[default] + Full, + ThreeQuarters, + Half, + OneQuarter, +} + +impl From for u8 { + fn from(value: Brightness) -> Self { + match value { + Brightness::Full => 0x00, + Brightness::ThreeQuarters => 0x10, + Brightness::Half => 0x20, + Brightness::OneQuarter => 0x30, + } + } +} + const MSG_PADDING_ALIGN: usize = 64; -const MAGIC: [u8; 6] = *b"wang\0\0"; +const MAGIC: [u8; 5] = *b"wang\0"; #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)] #[repr(C)] struct Header { - magic: [u8; 6], + magic: [u8; 5], + brightness: u8, blink: u8, border: u8, speed_and_mode: [u8; 8], @@ -252,7 +276,7 @@ impl Timestamp { /// primitives::{PrimitiveStyle, Rectangle, Styled}, /// }; /// -/// let mut buffer = PayloadBuffer::new(); +/// let mut buffer = PayloadBuffer::default(); /// buffer.add_message_drawable( /// Style::default(), /// &Styled::new( @@ -271,18 +295,19 @@ pub struct PayloadBuffer { impl Default for PayloadBuffer { fn default() -> Self { - Self::new() + Self::new(Brightness::Full) } } impl PayloadBuffer { /// Create a new empty buffer #[must_use] - pub fn new() -> Self { + pub fn new(brightness: Brightness) -> Self { Self { num_messages: 0, data: Header { magic: MAGIC, + brightness: brightness.into(), blink: 0, border: 0, speed_and_mode: [0; 8], From 1cb15622ebbb643a01f4e2bfc017070ec0a2181a Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sat, 22 Feb 2025 11:51:06 +0100 Subject: [PATCH 06/14] feat: add support for brightness control --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- LICENSE-MIT | 1 + examples/hello-world.rs | 4 ++-- src/main.rs | 9 ++++++-- src/protocol.rs | 47 +++++++++++++++++++++++++++++++---------- 6 files changed, 49 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 918d53b..1b93e18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,7 +112,7 @@ dependencies = [ [[package]] name = "badgemagic" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index 86272cd..3fa0df4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "badgemagic" -version = "0.1.0" -authors = ["Martin Michaelis "] +version = "0.2.0" +authors = ["Martin Michaelis ", "Valentin Weber "] edition = "2021" description = "Badge Magic with LEDs - Library and CLI" homepage = "https://badgemagic.fossasia.org" diff --git a/LICENSE-MIT b/LICENSE-MIT index dd968bb..8b49e53 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,4 +1,5 @@ Copyright 2024 Martin Michaelis +Copyright 2025 Valentin Weber Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal diff --git a/examples/hello-world.rs b/examples/hello-world.rs index aa316b6..9360985 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -5,13 +5,13 @@ use badgemagic::{ embedded_graphics::{ geometry::Point, mono_font::MonoTextStyle, pixelcolor::BinaryColor, text::Text, }, - protocol::{Mode, PayloadBuffer, Style}, + protocol::{Brightness, Mode, PayloadBuffer, Style}, usb_hid::Device, util::DrawableLayoutExt, }; fn main() -> Result<()> { - let mut payload = PayloadBuffer::new(); + let mut payload = PayloadBuffer::new(Brightness::default()); payload.add_message_drawable( Style::default().mode(Mode::Center), diff --git a/src/main.rs b/src/main.rs index fcbe5ff..298c676 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::{fs, path::PathBuf}; use anyhow::{Context, Result}; use badgemagic::{ ble::Device as BleDevice, - protocol::{Mode, PayloadBuffer, Speed, Style}, + protocol::{Brightness, Mode, PayloadBuffer, Speed, Style}, usb_hid::Device as UsbDevice, }; use base64::Engine; @@ -43,6 +43,10 @@ struct Args { #[clap(long)] transport: TransportProtocol, + /// Brightness of the panel + #[clap(long)] + brightness: Option, + /// List all devices visible to a transport and exit #[clap(long)] list_devices: bool, @@ -146,7 +150,7 @@ fn gnerate_payload(args: &mut Args) -> Result { } }; - let mut payload = PayloadBuffer::new(); + let mut payload = PayloadBuffer::new(args.brightness.unwrap_or_default()); for message in config.messages { let mut style = Style::default(); @@ -164,6 +168,7 @@ fn gnerate_payload(args: &mut Args) -> Result { Point::new(0, 7), MonoTextStyle::new(&FONT_6X9, BinaryColor::On), ); + payload.add_message_drawable(style, &text); } Content::Bitstring { bitstring } => { diff --git a/src/protocol.rs b/src/protocol.rs index 706b55e..2a05dfb 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -1,7 +1,5 @@ //! Protocol used to update the badge -use std::num::TryFromIntError; - #[cfg(feature = "embedded-graphics")] use embedded_graphics::{ draw_target::DrawTarget, @@ -11,6 +9,7 @@ use embedded_graphics::{ primitives::Rectangle, Drawable, }; +use std::num::TryFromIntError; use time::OffsetDateTime; use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U16}; @@ -54,7 +53,7 @@ impl Style { self } - /// Show a dotted border arround the display. + /// Show a dotted border around the display. /// ``` /// use badgemagic::protocol::Style; /// # ( @@ -161,7 +160,7 @@ impl TryFrom for Speed { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] pub enum Mode { - /// Scroll thorugh the message from left to right + /// Scroll through the message from left to right #[default] Left, @@ -193,14 +192,39 @@ pub enum Mode { Laser, } +/// Display Brightness +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "cli", derive(clap::ValueEnum))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))] +pub enum Brightness { + #[default] + Full, + ThreeQuarters, + Half, + OneQuarter, +} + +impl From for u8 { + fn from(value: Brightness) -> Self { + match value { + Brightness::Full => 0x00, + Brightness::ThreeQuarters => 0x10, + Brightness::Half => 0x20, + Brightness::OneQuarter => 0x30, + } + } +} + const MSG_PADDING_ALIGN: usize = 64; -const MAGIC: [u8; 6] = *b"wang\0\0"; +const MAGIC: [u8; 5] = *b"wang\0"; #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)] #[repr(C)] struct Header { - magic: [u8; 6], + magic: [u8; 5], + brightness: u8, blink: u8, border: u8, speed_and_mode: [u8; 8], @@ -241,7 +265,7 @@ impl Timestamp { /// Buffer to create a payload /// -/// A payload consits of up to 8 messages +/// A payload consists of up to 8 messages /// ``` /// # #[cfg(feature = "embedded-graphics")] /// # fn main() { @@ -252,7 +276,7 @@ impl Timestamp { /// primitives::{PrimitiveStyle, Rectangle, Styled}, /// }; /// -/// let mut buffer = PayloadBuffer::new(); +/// let mut buffer = PayloadBuffer::default(); /// buffer.add_message_drawable( /// Style::default(), /// &Styled::new( @@ -271,18 +295,19 @@ pub struct PayloadBuffer { impl Default for PayloadBuffer { fn default() -> Self { - Self::new() + Self::new(Brightness::Full) } } impl PayloadBuffer { /// Create a new empty buffer #[must_use] - pub fn new() -> Self { + pub fn new(brightness: Brightness) -> Self { Self { num_messages: 0, data: Header { magic: MAGIC, + brightness: brightness.into(), blink: 0, border: 0, speed_and_mode: [0; 8], @@ -368,7 +393,7 @@ impl PayloadBuffer { &self.data } - /// Convert the payload buffe into bytes (with padding) + /// Convert the payload buffer into bytes (with padding) #[allow(clippy::missing_panics_doc)] // should never panic #[must_use] pub fn into_padded_bytes(self) -> impl AsRef<[u8]> { From 00cdff615a91541fce51d83caabcc4033f0c3b4c Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sat, 22 Feb 2025 18:50:20 +0100 Subject: [PATCH 07/14] 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), From 1535b571c7162bc34ec1994721bbaa4f30113c32 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sat, 22 Feb 2025 20:04:26 +0100 Subject: [PATCH 08/14] feat(src/protocol.rs): add test Add test for Brightness to u8 conversion. --- src/protocol.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/protocol.rs b/src/protocol.rs index 2a05dfb..e292e78 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -509,10 +509,9 @@ impl DrawTarget for MessageBuffer<'_> { #[cfg(test)] mod test { + use super::{Brightness, Speed}; use std::ops::Range; - use super::Speed; - #[test] fn speed_to_u8_and_back() { const VALID_SPEED_VALUES: Range = 1..8; @@ -524,4 +523,18 @@ mod test { } } } + + #[test] + fn brightness_to_u8() { + const VALID_BRIGHTNESS_VALUES: [(Brightness, u8); 4] = [ + (Brightness::Full, 0x00), + (Brightness::ThreeQuarters, 0x10), + (Brightness::Half, 0x20), + (Brightness::OneQuarter, 0x30), + ]; + + for i in VALID_BRIGHTNESS_VALUES { + assert_eq!(u8::from(Brightness::from(i.0)), i.1); + } + } } From 01828a0e5b2ff7254605985b2f1c8ee548ab9caa Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Sun, 23 Feb 2025 12:21:59 +0100 Subject: [PATCH 09/14] chore: fmt --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 089da3b..0c4815d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,14 +168,13 @@ fn generate_payload(args: &mut Args) -> Result { 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, From 37b7a7d96eab35e83e310495c4e3c972add0e107 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Tue, 8 Jul 2025 19:11:16 +0200 Subject: [PATCH 10/14] bump: cargo versions (#5) --- Cargo.lock | 387 +++++++++++++++++++++++++++++++++++++++-------------- Cargo.toml | 20 +-- 2 files changed, 295 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54b1bc1..859b279 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,15 +68,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.95" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "async-trait" -version = "0.1.83" +version = "0.1.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" dependencies = [ "proc-macro2", "quote", @@ -138,9 +138,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "block2" @@ -153,11 +153,10 @@ dependencies = [ [[package]] name = "bluez-async" -version = "0.7.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce7d4413c940e8e3cb6afc122d3f4a07096aca259d286781128683fc9f39d9b" +checksum = "50ce74d1f22603b879c3a99bd30eddc423460fb73a802655ca615b623ff3a838" dependencies = [ - "async-trait", "bitflags", "bluez-generated", "dbus", @@ -167,25 +166,25 @@ dependencies = [ "log", "serde", "serde-xml-rs", - "thiserror", + "thiserror 2.0.12", "tokio", "uuid", ] [[package]] name = "bluez-generated" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d1c659dbc82f0b8ca75606c91a371e763589b7f6acf36858eeed0c705afe367" +checksum = "9676783265eadd6f11829982792c6f303f3854d014edfba384685dcf237dd062" dependencies = [ "dbus", ] [[package]] name = "btleplug" -version = "0.11.6" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82837101dad9a257a3ffe35fbc2ef4df9a27aecbe5343ce83ac233bcab283394" +checksum = "c9a11621cb2c8c024e444734292482b1ad86fb50ded066cf46252e46643c8748" dependencies = [ "async-trait", "bitflags", @@ -201,13 +200,20 @@ dependencies = [ "objc2-foundation", "once_cell", "static_assertions", - "thiserror", + "thiserror 2.0.12", "tokio", "tokio-stream", "uuid", "windows", + "windows-future", ] +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + [[package]] name = "byteorder" version = "1.5.0" @@ -240,9 +246,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.23" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" dependencies = [ "clap_builder", "clap_derive", @@ -250,9 +256,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.23" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ "anstream", "anstyle", @@ -262,9 +268,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" dependencies = [ "heck", "proc-macro2", @@ -307,7 +313,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown", + "hashbrown 0.14.5", "lock_api", "once_cell", "parking_lot_core", @@ -321,7 +327,7 @@ checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" dependencies = [ "cfg-if", "crossbeam-utils", - "hashbrown", + "hashbrown 0.14.5", "lock_api", "once_cell", "parking_lot_core", @@ -353,9 +359,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.11" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" dependencies = [ "powerfmt", ] @@ -505,6 +511,12 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" + [[package]] name = "heck" version = "0.5.0" @@ -532,12 +544,23 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.4", +] + +[[package]] +name = "io-uring" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" +dependencies = [ + "bitflags", + "cfg-if", + "libc", ] [[package]] @@ -548,9 +571,9 @@ checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" [[package]] name = "itertools" -version = "0.10.5" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" dependencies = [ "either", ] @@ -571,7 +594,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.69", "walkdir", ] @@ -597,10 +620,20 @@ dependencies = [ ] [[package]] -name = "libc" -version = "0.2.155" +name = "js-sys" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libdbus-sys" @@ -623,9 +656,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "memchr" @@ -805,6 +838,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustversion" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" + [[package]] name = "ryu" version = "1.0.18" @@ -828,30 +867,30 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde-xml-rs" -version = "0.6.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3aa78ecda1ebc9ec9847d5d3aba7d618823446a049ba2491940506da6e2782" +checksum = "53630160a98edebde0123eb4dfd0fce6adff091b2305db3154a9e920206eb510" dependencies = [ "log", "serde", - "thiserror", + "thiserror 1.0.69", "xml-rs", ] [[package]] name = "serde_derive" -version = "1.0.217" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", @@ -860,9 +899,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.134" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", "memchr", @@ -872,9 +911,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83" dependencies = [ "serde", ] @@ -933,7 +972,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl 2.0.12", ] [[package]] @@ -948,10 +996,21 @@ dependencies = [ ] [[package]] -name = "time" -version = "0.3.37" +name = "thiserror-impl" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "num-conv", @@ -962,20 +1021,22 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" [[package]] name = "tokio" -version = "1.42.0" +version = "1.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" +checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" dependencies = [ "backtrace", + "io-uring", "libc", "mio", "pin-project-lite", + "slab", "socket2", "windows-sys 0.52.0", ] @@ -1007,43 +1068,48 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.19" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.22.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "f271e09bde39ab52250160a67e88577e0559ad77e9085de6e9051a2c4353f8f8" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", + "toml_parser", + "toml_writer", "winnow", ] [[package]] -name = "u8g2-fonts" -version = "0.5.2" +name = "toml_datetime" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "132e15484caa39440cc9d6317c1f1980a13259234e630db2270ea2a2b1e5c4a2" +checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_parser" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c1c469eda89749d2230d8156a5969a69ffe0d6d01200581cdc6110674d293e" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b679217f2848de74cabd3e8fc5e6d66f40b7da40f8e1954d92054d9010690fd5" + +[[package]] +name = "u8g2-fonts" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e4bdc43a7fb3720ece9ba4405b57db4fc479ad6af6b57090f6ff4c040f5d54b" dependencies = [ "embedded-graphics", "embedded-graphics-core", @@ -1063,9 +1129,13 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.11.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" +checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "walkdir" @@ -1083,6 +1153,64 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1116,31 +1244,55 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.57.0" +version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-link", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" dependencies = [ "windows-core", - "windows-targets 0.52.5", ] [[package]] name = "windows-core" -version = "0.57.0" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ "windows-implement", "windows-interface", + "windows-link", "windows-result", - "windows-targets 0.52.5", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", ] [[package]] name = "windows-implement" -version = "0.57.0" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" dependencies = [ "proc-macro2", "quote", @@ -1149,9 +1301,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.57.0" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" dependencies = [ "proc-macro2", "quote", @@ -1159,12 +1311,37 @@ dependencies = [ ] [[package]] -name = "windows-result" -version = "0.1.2" +name = "windows-link" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" dependencies = [ - "windows-targets 0.52.5", + "windows-core", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", ] [[package]] @@ -1216,6 +1393,15 @@ dependencies = [ "windows_x86_64_msvc 0.52.5", ] +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -1308,12 +1494,9 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.18" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" -dependencies = [ - "memchr", -] +checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" [[package]] name = "xml-rs" diff --git a/Cargo.toml b/Cargo.toml index d1be3d0..a49a0c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,17 +38,17 @@ ble = ["dep:btleplug", "dep:uuid", "dep:tokio"] u8g2-fonts = ["dep:u8g2-fonts"] [dependencies] -anyhow = "1.0.95" +anyhow = "1.0.98" base64 = { version = "0.22.1", optional = true } -clap = { version = "4.5.23", features = ["derive"], optional = true } +clap = { version = "4.5.40", features = ["derive"], optional = true } embedded-graphics = { version = "0.8.1", optional = true } hidapi = { version = "2.6.3", optional = true } -btleplug = { version = "0.11.6", optional = true } -uuid = { version = "1.11.0", optional = true } -tokio = { version = "1.39.2", features = ["rt"], optional = true } -serde = { version = "1.0.217", features = ["derive"], optional = true } -serde_json = { version = "1.0.134", optional = true } -time = "0.3.37" -toml = { version = "0.8.19", optional = true } +btleplug = { version = "0.11.8", optional = true } +uuid = { version = "1.17.0", optional = true } +tokio = { version = "1.46.1", features = ["rt"], optional = true } +serde = { version = "1.0.219", features = ["derive"], optional = true } +serde_json = { version = "1.0.140", optional = true } +time = "0.3.41" +toml = { version = "0.9.0", optional = true } zerocopy = { version = "0.8.14", features = ["derive"] } -u8g2-fonts = { version = "0.5.2", features = ["embedded_graphics_textstyle"], optional = true} +u8g2-fonts = { version = "0.7.1", features = ["embedded_graphics_textstyle"], optional = true} From 6e25fbb266f00e6994518964ad0346021488ab0d Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Tue, 8 Jul 2025 20:19:13 +0200 Subject: [PATCH 11/14] fix(main.rs): switch back to MonoTextStyle for non feature (#6) --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c4815d..09eec56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,8 +171,8 @@ fn generate_payload(args: &mut Args) -> Result { #[cfg(not(any(feature = "u8g2-fonts")))] let text = Text::new( &text, - Point::new(0, 8), - U8g2TextStyle::new(u8g2_font_lucasfont_alternate_tf, BinaryColor::On), + Point::new(0, 7), + MonoTextStyle::new(&FONT_6X9, BinaryColor::On), ); #[cfg(feature = "u8g2-fonts")] From 1dd4c4cc43ffc219360a73ac4e362af780921a22 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Thu, 10 Jul 2025 17:52:57 +0200 Subject: [PATCH 12/14] chore: some typos and fmt --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- src/ble.rs | 2 +- src/main.rs | 18 +++++------------- src/usb_hid.rs | 2 +- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 859b279..7ffb554 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1506,18 +1506,18 @@ checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" [[package]] name = "zerocopy" -version = "0.8.14" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a367f292d93d4eab890745e75a778da40909cab4d6ff8173693812f79c4a2468" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.14" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3931cb58c62c13adec22e38686b559c86a30565e16ad6e8510a337cedc611e1" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index a49a0c5..2c3a988 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,4 +51,4 @@ serde_json = { version = "1.0.140", optional = true } time = "0.3.41" toml = { version = "0.9.0", optional = true } zerocopy = { version = "0.8.14", features = ["derive"] } -u8g2-fonts = { version = "0.7.1", features = ["embedded_graphics_textstyle"], optional = true} +u8g2-fonts = { version = "0.7.1", features = ["embedded_graphics_textstyle"], optional = true } \ No newline at end of file diff --git a/src/ble.rs b/src/ble.rs index 51c8eb5..3ad5159 100644 --- a/src/ble.rs +++ b/src/ble.rs @@ -191,7 +191,7 @@ impl Device { BLE_CHAR_CHUNK_SIZE ); - // the device will brick itself if the payload is too long (more then 8192 bytes) + // the device will brick itself if the payload is too long (more than 8192 bytes) anyhow::ensure!(data.len() <= 8192, "payload too long (max 8192 bytes)"); for chunk in data.chunks(BLE_CHAR_CHUNK_SIZE) { diff --git a/src/main.rs b/src/main.rs index 09eec56..00d379c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ #![warn(clippy::all, clippy::pedantic)] -use std::{fs, path::PathBuf}; - use anyhow::{Context, Result}; use badgemagic::{ ble::Device as BleDevice, @@ -10,6 +8,8 @@ use badgemagic::{ }; use base64::Engine; use clap::{Parser, ValueEnum}; +#[cfg(not(any(feature = "u8g2-fonts")))] +use embedded_graphics::mono_font::{iso_8859_1::FONT_6X9, MonoTextStyle}; use embedded_graphics::{ geometry::Point, image::{Image, ImageRawLE}, @@ -18,9 +18,7 @@ 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}; +use std::{fs, path::PathBuf}; #[cfg(feature = "u8g2-fonts")] use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle}; @@ -99,8 +97,6 @@ enum Content { Bitstring { bitstring: String }, BitmapBase64 { width: u32, bitmap_base64: String }, BitmapFile { width: u32, bitmap_file: PathBuf }, - // TODO: implement png - // PngFile { png_file: PathBuf }, } fn main() -> Result<()> { @@ -208,12 +204,8 @@ fn generate_payload(args: &mut Args) -> Result { // off } 'X' => { - Pixel( - Point::new(x.try_into().unwrap(), y.try_into().unwrap()), - BinaryColor::On, - ) - .draw(&mut buffer) - .unwrap(); + Pixel(Point::new(x.try_into()?, y.try_into()?), BinaryColor::On) + .draw(&mut buffer)?; } _ => anyhow::bail!("invalid bit value for bit ({x}, {y}): {c:?}"), } diff --git a/src/usb_hid.rs b/src/usb_hid.rs index 1d9e3ed..fadb165 100644 --- a/src/usb_hid.rs +++ b/src/usb_hid.rs @@ -92,7 +92,7 @@ impl Device { fn write_raw(device: &HidDevice, data: &[u8]) -> Result<()> { anyhow::ensure!(data.len() % 64 == 0, "payload not padded to 64 bytes"); - // the device will brick itself if the payload is too long (more then 8192 bytes) + // the device will brick itself if the payload is too long (more than 8192 bytes) anyhow::ensure!(data.len() <= 8192, "payload too long (max 8192 bytes)"); // just to be sure From b794eec9a5abf55c501aff9693b1aa6cc161bdc9 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Thu, 10 Jul 2025 17:55:47 +0200 Subject: [PATCH 13/14] feat: add (non-animated) image support --- Cargo.lock | 793 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +- src/main.rs | 19 ++ 3 files changed, 802 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7ffb554..424acca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,21 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aligned-vec" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc890384c8602f339876ded803c97ad529f3842aba97f6392b3dba0dd171769b" +dependencies = [ + "equator", +] + [[package]] name = "anstream" version = "0.6.14" @@ -72,6 +87,29 @@ version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +[[package]] +name = "arbitrary" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" + +[[package]] +name = "arg_enum_proc_macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-trait" version = "0.1.88" @@ -89,6 +127,29 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "av1-grain" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f3efb2ca85bc610acfa917b5aaa36f3fcbebed5b3182d7f877b02531c4b80c8" +dependencies = [ + "anyhow", + "arrayvec", + "log", + "nom", + "num-rational", + "v_frame", +] + +[[package]] +name = "avif-serialize" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea8ef51aced2b9191c08197f55450d830876d9933f8f48a429b354f1d496b42" +dependencies = [ + "arrayvec", +] + [[package]] name = "az" version = "1.2.1" @@ -105,7 +166,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.7.4", "object", "rustc-demangle", ] @@ -120,11 +181,12 @@ dependencies = [ "clap", "embedded-graphics", "hidapi", + "image", "serde", "serde_json", "time", "tokio", - "toml", + "toml 0.9.0", "u8g2-fonts", "uuid", "zerocopy", @@ -136,12 +198,30 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +[[package]] +name = "bitstream-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2" + [[package]] name = "block2" version = "0.5.1" @@ -157,12 +237,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50ce74d1f22603b879c3a99bd30eddc423460fb73a802655ca615b623ff3a838" dependencies = [ - "bitflags", + "bitflags 2.9.1", "bluez-generated", "dbus", "dbus-tokio", "futures", - "itertools", + "itertools 0.14.0", "log", "serde", "serde-xml-rs", @@ -187,7 +267,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9a11621cb2c8c024e444734292482b1ad86fb50ded066cf46252e46643c8748" dependencies = [ "async-trait", - "bitflags", + "bitflags 2.9.1", "bluez-async", "dashmap 6.1.0", "dbus", @@ -208,18 +288,36 @@ dependencies = [ "windows-future", ] +[[package]] +name = "built" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ed6191a7e78c36abdb16ab65341eefd73d64d303fffccdbb00d51e4205967b" + [[package]] name = "bumpalo" version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +[[package]] +name = "bytemuck" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + [[package]] name = "bytes" version = "1.6.1" @@ -231,6 +329,11 @@ name = "cc" version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +dependencies = [ + "jobserver", + "libc", + "once_cell", +] [[package]] name = "cesu8" @@ -238,6 +341,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" +[[package]] +name = "cfg-expr" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" +dependencies = [ + "smallvec", + "target-lexicon", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -284,6 +397,12 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "colorchoice" version = "1.0.1" @@ -300,12 +419,46 @@ dependencies = [ "memchr", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + [[package]] name = "dashmap" version = "5.5.3" @@ -395,12 +548,66 @@ dependencies = [ "byteorder", ] +[[package]] +name = "equator" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4711b213838dfee0117e3be6ac926007d7f433d7bbe33595975d4190cb07e6fc" +dependencies = [ + "equator-macro", +] + +[[package]] +name = "equator-macro" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "exr" +version = "1.73.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83197f59927b46c04a183a619b7c29df34e63e63c7869320862268c0ef687e0" +dependencies = [ + "bit_field", + "half", + "lebe", + "miniz_oxide 0.8.9", + "rayon-core", + "smallvec", + "zune-inflate", +] + +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "flate2" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d" +dependencies = [ + "crc32fast", + "miniz_oxide 0.8.9", +] + [[package]] name = "float-cmp" version = "0.9.0" @@ -499,12 +706,55 @@ dependencies = [ "slab", ] +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", +] + +[[package]] +name = "gif" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae047235e33e2829703574b54fdec96bfbad892062d97fed2f76022287de61b" +dependencies = [ + "color_quant", + "weezl", +] + [[package]] name = "gimli" version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "half" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" +dependencies = [ + "cfg-if", + "crunchy", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -542,6 +792,45 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "image" +version = "0.25.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db35664ce6b9810857a38a906215e75a9c879f0696556a39f59c62829710251a" +dependencies = [ + "bytemuck", + "byteorder-lite", + "color_quant", + "exr", + "gif", + "image-webp", + "num-traits", + "png", + "qoi", + "ravif", + "rayon", + "rgb", + "tiff", + "zune-core", + "zune-jpeg", +] + +[[package]] +name = "image-webp" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6970fe7a5300b4b42e62c52efa0187540a5bef546c60edaf554ef595d2e6f0b" +dependencies = [ + "byteorder-lite", + "quick-error", +] + +[[package]] +name = "imgref" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0263a3d970d5c054ed9312c0057b4f3bde9c0b33836d3637361d4a9e6e7a408" + [[package]] name = "indexmap" version = "2.10.0" @@ -552,13 +841,24 @@ dependencies = [ "hashbrown 0.15.4", ] +[[package]] +name = "interpolate_name" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "io-uring" version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" dependencies = [ - "bitflags", + "bitflags 2.9.1", "cfg-if", "libc", ] @@ -569,6 +869,15 @@ version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.14.0" @@ -619,6 +928,22 @@ dependencies = [ "uuid", ] +[[package]] +name = "jobserver" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" +dependencies = [ + "getrandom 0.3.3", + "libc", +] + +[[package]] +name = "jpeg-decoder" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00810f1d8b74be64b13dbf3db89ac67740615d6c891f0e7b6179326533011a07" + [[package]] name = "js-sys" version = "0.3.77" @@ -629,6 +954,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + [[package]] name = "libc" version = "0.2.174" @@ -644,6 +975,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libfuzzer-sys" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5037190e1f70cbeef565bd267599242926f724d3b8a9f510fd7e0b540cfa4404" +dependencies = [ + "arbitrary", + "cc", +] + [[package]] name = "lock_api" version = "0.4.12" @@ -660,6 +1001,25 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +[[package]] +name = "loop9" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fae87c125b03c1d2c0150c90365d7d6bcc53fb73a9acaef207d2d065860f062" +dependencies = [ + "imgref", +] + +[[package]] +name = "maybe-rayon" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519" +dependencies = [ + "cfg-if", + "rayon", +] + [[package]] name = "memchr" version = "2.7.2" @@ -672,6 +1032,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -681,6 +1047,16 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + [[package]] name = "mio" version = "1.0.1" @@ -689,16 +1065,79 @@ checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" dependencies = [ "hermit-abi", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.52.0", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "noop_proc_macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -730,7 +1169,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a644b62ffb826a5277f536cf0f701493de420b13d40e700c452c36567771111" dependencies = [ - "bitflags", + "bitflags 2.9.1", "objc2", "objc2-foundation", ] @@ -747,7 +1186,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" dependencies = [ - "bitflags", + "bitflags 2.9.1", "block2", "libc", "objc2", @@ -781,6 +1220,12 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -799,12 +1244,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "png" +version = "0.17.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide 0.8.9", +] + [[package]] name = "powerfmt" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.92" @@ -814,6 +1281,40 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "profiling" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773" +dependencies = [ + "profiling-procmacros", +] + +[[package]] +name = "profiling-procmacros" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" + [[package]] name = "quote" version = "1.0.36" @@ -823,15 +1324,127 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.16", +] + +[[package]] +name = "rav1e" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd87ce80a7665b1cce111f8a16c1f3929f6547ce91ade6addf4ec86a8dda5ce9" +dependencies = [ + "arbitrary", + "arg_enum_proc_macro", + "arrayvec", + "av1-grain", + "bitstream-io", + "built", + "cfg-if", + "interpolate_name", + "itertools 0.12.1", + "libc", + "libfuzzer-sys", + "log", + "maybe-rayon", + "new_debug_unreachable", + "noop_proc_macro", + "num-derive", + "num-traits", + "once_cell", + "paste", + "profiling", + "rand", + "rand_chacha", + "simd_helpers", + "system-deps", + "thiserror 1.0.69", + "v_frame", + "wasm-bindgen", +] + +[[package]] +name = "ravif" +version = "0.11.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5825c26fddd16ab9f515930d49028a630efec172e903483c94796cfe31893e6b" +dependencies = [ + "avif-serialize", + "imgref", + "loop9", + "quick-error", + "rav1e", + "rayon", + "rgb", +] + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags", + "bitflags 2.9.1", ] +[[package]] +name = "rgb" +version = "0.8.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a457e416a0f90d246a4c3288bd7a25b2304ca727f253f95be383dd17af56be8f" + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -909,6 +1522,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + [[package]] name = "serde_spanned" version = "1.0.0" @@ -918,6 +1540,21 @@ dependencies = [ "serde", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + +[[package]] +name = "simd_helpers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6" +dependencies = [ + "quote", +] + [[package]] name = "slab" version = "0.4.9" @@ -966,6 +1603,25 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "system-deps" +version = "6.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml 0.8.23", + "version-compare", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + [[package]] name = "thiserror" version = "1.0.69" @@ -1006,6 +1662,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tiff" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.3.41" @@ -1066,6 +1733,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", + "toml_edit", +] + [[package]] name = "toml" version = "0.9.0" @@ -1074,13 +1753,22 @@ checksum = "f271e09bde39ab52250160a67e88577e0559ad77e9085de6e9051a2c4353f8f8" dependencies = [ "indexmap", "serde", - "serde_spanned", - "toml_datetime", + "serde_spanned 1.0.0", + "toml_datetime 0.7.0", "toml_parser", "toml_writer", "winnow", ] +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + [[package]] name = "toml_datetime" version = "0.7.0" @@ -1090,6 +1778,19 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", + "winnow", +] + [[package]] name = "toml_parser" version = "1.0.0" @@ -1137,6 +1838,23 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "v_frame" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "666b7727c8875d6ab5db9533418d7c764233ac9c0cff1d469aec8fa127597be2" +dependencies = [ + "aligned-vec", + "num-traits", + "wasm-bindgen", +] + +[[package]] +name = "version-compare" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" + [[package]] name = "walkdir" version = "2.5.0" @@ -1153,6 +1871,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasm-bindgen" version = "0.2.100" @@ -1211,6 +1938,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "weezl" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a751b3277700db47d3e574514de2eced5e54dc8a5436a3bf7a0b248b2cee16f3" + [[package]] name = "winapi" version = "0.3.9" @@ -1497,6 +2230,18 @@ name = "winnow" version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags 2.9.1", +] [[package]] name = "xml-rs" @@ -1523,3 +2268,27 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zune-core" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" + +[[package]] +name = "zune-inflate" +version = "0.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "zune-jpeg" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9e525af0a6a658e031e95f14b7f889976b74a11ba0eca5a5fc9ac8a1c43a6a" +dependencies = [ + "zune-core", +] diff --git a/Cargo.toml b/Cargo.toml index 2c3a988..c0a3416 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,4 +51,5 @@ serde_json = { version = "1.0.140", optional = true } time = "0.3.41" toml = { version = "0.9.0", optional = true } zerocopy = { version = "0.8.14", features = ["derive"] } -u8g2-fonts = { version = "0.7.1", features = ["embedded_graphics_textstyle"], optional = true } \ No newline at end of file +u8g2-fonts = { version = "0.7.1", features = ["embedded_graphics_textstyle"], optional = true } +image = "0.25.6" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 00d379c..f13132e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ use embedded_graphics::{ text::Text, Drawable, Pixel, }; +use image::{imageops::FilterType, ImageReader}; use serde::Deserialize; use std::{fs, path::PathBuf}; #[cfg(feature = "u8g2-fonts")] @@ -97,6 +98,7 @@ enum Content { Bitstring { bitstring: String }, BitmapBase64 { width: u32, bitmap_base64: String }, BitmapFile { width: u32, bitmap_file: PathBuf }, + ImageFile { img_file: PathBuf }, } fn main() -> Result<()> { @@ -233,6 +235,23 @@ fn generate_payload(args: &mut Args) -> Result { let image = Image::new(&image_raw, Point::zero()); payload.add_message_drawable(style, &image); } + Content::ImageFile { img_file } => { + let img_reader = ImageReader::open(img_file)?; + let img = img_reader + .decode()? + .resize(u32::MAX, 11, FilterType::Nearest) + .into_luma8(); + let (width, height) = img.dimensions(); + let mut buffer = payload.add_message(style, (width as usize + 7) / 8); + for y in 0..height { + for x in 0..width { + if img.get_pixel(x, y).0 > [31] { + Pixel(Point::new(x.try_into()?, y.try_into()?), BinaryColor::On) + .draw(&mut buffer)?; + } + } + } + } } } From b344ac00b12cc62a7e6df113c60fa49a889eff62 Mon Sep 17 00:00:00 2001 From: Valentin Weber Date: Thu, 10 Jul 2025 17:57:06 +0200 Subject: [PATCH 14/14] feat: Add animated GIF support --- src/main.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index f13132e..3feb8e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,9 +17,11 @@ use embedded_graphics::{ text::Text, Drawable, Pixel, }; -use image::{imageops::FilterType, ImageReader}; +use image::{ + codecs::gif::GifDecoder, imageops::FilterType, AnimationDecoder, ImageReader, Pixel as iPixel, +}; use serde::Deserialize; -use std::{fs, path::PathBuf}; +use std::{fs, fs::File, io::BufReader, path::PathBuf}; #[cfg(feature = "u8g2-fonts")] use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle}; @@ -99,6 +101,7 @@ enum Content { BitmapBase64 { width: u32, bitmap_base64: String }, BitmapFile { width: u32, bitmap_file: PathBuf }, ImageFile { img_file: PathBuf }, + GifFile { gif_file: PathBuf }, } fn main() -> Result<()> { @@ -252,6 +255,36 @@ fn generate_payload(args: &mut Args) -> Result { } } } + Content::GifFile { gif_file } => { + let file_in = BufReader::new(File::open(gif_file)?); + let frames = GifDecoder::new(file_in)? + .into_frames() + .collect_frames() + .expect("error decoding gif"); + + let frame_count = frames.len(); + let (width, height) = frames.first().unwrap().buffer().dimensions(); + if height != 11 || width != 44 { + anyhow::bail!("Expected 44x11 pixel gif file"); + } + + let mut buffer = payload.add_message(style, (48 * frame_count + 7) / 8); + + for (i, frame) in frames.iter().enumerate() { + let buf = frame.buffer(); + for y in 0..11 { + for x in 0..44 { + if buf.get_pixel(x, y).to_luma().0 > [31] { + Pixel( + Point::new((x as usize + i * 48).try_into()?, y.try_into()?), + BinaryColor::On, + ) + .draw(&mut buffer)?; + } + } + } + } + } } }