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