mirror of
https://github.com/fossasia/badgemagic-rs
synced 2025-07-16 09:33:59 +00:00
chore: some typos and fmt
This commit is contained in:
parent
6e25fbb266
commit
1dd4c4cc43
5 changed files with 12 additions and 20 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -1506,18 +1506,18 @@ checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.8.14"
|
version = "0.8.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a367f292d93d4eab890745e75a778da40909cab4d6ff8173693812f79c4a2468"
|
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zerocopy-derive",
|
"zerocopy-derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy-derive"
|
name = "zerocopy-derive"
|
||||||
version = "0.8.14"
|
version = "0.8.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d3931cb58c62c13adec22e38686b559c86a30565e16ad6e8510a337cedc611e1"
|
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl Device {
|
||||||
BLE_CHAR_CHUNK_SIZE
|
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)");
|
anyhow::ensure!(data.len() <= 8192, "payload too long (max 8192 bytes)");
|
||||||
|
|
||||||
for chunk in data.chunks(BLE_CHAR_CHUNK_SIZE) {
|
for chunk in data.chunks(BLE_CHAR_CHUNK_SIZE) {
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -1,7 +1,5 @@
|
||||||
#![warn(clippy::all, clippy::pedantic)]
|
#![warn(clippy::all, clippy::pedantic)]
|
||||||
|
|
||||||
use std::{fs, path::PathBuf};
|
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use badgemagic::{
|
use badgemagic::{
|
||||||
ble::Device as BleDevice,
|
ble::Device as BleDevice,
|
||||||
|
@ -10,6 +8,8 @@ use badgemagic::{
|
||||||
};
|
};
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
|
#[cfg(not(any(feature = "u8g2-fonts")))]
|
||||||
|
use embedded_graphics::mono_font::{iso_8859_1::FONT_6X9, MonoTextStyle};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
geometry::Point,
|
geometry::Point,
|
||||||
image::{Image, ImageRawLE},
|
image::{Image, ImageRawLE},
|
||||||
|
@ -18,9 +18,7 @@ use embedded_graphics::{
|
||||||
Drawable, Pixel,
|
Drawable, Pixel,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::{fs, path::PathBuf};
|
||||||
#[cfg(not(any(feature = "u8g2-fonts")))]
|
|
||||||
use embedded_graphics::mono_font::{iso_8859_1::FONT_6X9, MonoTextStyle};
|
|
||||||
#[cfg(feature = "u8g2-fonts")]
|
#[cfg(feature = "u8g2-fonts")]
|
||||||
use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle};
|
use u8g2_fonts::{fonts::u8g2_font_lucasfont_alternate_tf, U8g2TextStyle};
|
||||||
|
|
||||||
|
@ -99,8 +97,6 @@ enum Content {
|
||||||
Bitstring { bitstring: String },
|
Bitstring { bitstring: String },
|
||||||
BitmapBase64 { width: u32, bitmap_base64: String },
|
BitmapBase64 { width: u32, bitmap_base64: String },
|
||||||
BitmapFile { width: u32, bitmap_file: PathBuf },
|
BitmapFile { width: u32, bitmap_file: PathBuf },
|
||||||
// TODO: implement png
|
|
||||||
// PngFile { png_file: PathBuf },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
@ -208,12 +204,8 @@ fn generate_payload(args: &mut Args) -> Result<PayloadBuffer> {
|
||||||
// off
|
// off
|
||||||
}
|
}
|
||||||
'X' => {
|
'X' => {
|
||||||
Pixel(
|
Pixel(Point::new(x.try_into()?, y.try_into()?), BinaryColor::On)
|
||||||
Point::new(x.try_into().unwrap(), y.try_into().unwrap()),
|
.draw(&mut buffer)?;
|
||||||
BinaryColor::On,
|
|
||||||
)
|
|
||||||
.draw(&mut buffer)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
_ => anyhow::bail!("invalid bit value for bit ({x}, {y}): {c:?}"),
|
_ => anyhow::bail!("invalid bit value for bit ({x}, {y}): {c:?}"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl Device {
|
||||||
fn write_raw(device: &HidDevice, data: &[u8]) -> Result<()> {
|
fn write_raw(device: &HidDevice, data: &[u8]) -> Result<()> {
|
||||||
anyhow::ensure!(data.len() % 64 == 0, "payload not padded to 64 bytes");
|
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)");
|
anyhow::ensure!(data.len() <= 8192, "payload too long (max 8192 bytes)");
|
||||||
|
|
||||||
// just to be sure
|
// just to be sure
|
||||||
|
|
Loading…
Reference in a new issue