badgemagic-rs/examples/hello-world.rs
Martin Michaelis 97d5561e81 Initial commit
2024-06-07 13:33:27 +00:00

51 lines
1.3 KiB
Rust

#![warn(clippy::all, clippy::pedantic)]
use anyhow::Result;
use badgemagic::{
embedded_graphics::{
geometry::Point, mono_font::MonoTextStyle, pixelcolor::BinaryColor, text::Text,
},
protocol::{Mode, PayloadBuffer, Style},
usb_hid::Device,
util::DrawableLayoutExt,
};
fn main() -> Result<()> {
let mut payload = PayloadBuffer::new();
payload.add_message_drawable(
Style::default().mode(Mode::Center),
&Text::new(
"Hello",
Point::new(0, 8),
MonoTextStyle::new(
&embedded_graphics::mono_font::iso_8859_1::FONT_6X9,
BinaryColor::On,
),
),
);
payload.add_message_drawable(
Style::default().mode(Mode::Center),
&Text::new(
"Hello",
Point::new(0, 5),
MonoTextStyle::new(
&embedded_graphics::mono_font::iso_8859_1::FONT_4X6,
BinaryColor::On,
),
)
.z_stack(Text::new(
"World",
Point::new(23, 8),
MonoTextStyle::new(
&embedded_graphics::mono_font::iso_8859_1::FONT_4X6,
BinaryColor::On,
),
)),
);
Device::single()?.write(payload)?;
Ok(())
}