servicepoint/examples/brightness_tester.rs
Vinzenz Schroeter 1cf37413e6
All checks were successful
Rust / build (pull_request) Successful in 2m15s
implement From<X> for XCommand
2025-03-25 22:20:44 +01:00

36 lines
1.1 KiB
Rust

//! Show a brightness level test pattern on screen
use clap::Parser;
use servicepoint::{
Bitmap, BitmapCommand, Brightness, BrightnessGrid, BrightnessGridCommand,
Connection, DataRef, Grid, UdpConnection, TILE_HEIGHT, TILE_WIDTH,
};
#[derive(Parser, Debug)]
struct Cli {
#[arg(short, long, default_value = "localhost:2342")]
destination: String,
}
fn main() {
let cli = Cli::parse();
let connection = UdpConnection::open(cli.destination)
.expect("could not connect to display");
let mut bitmap = Bitmap::max_sized();
bitmap.fill(true);
connection
.send(BitmapCommand::from(bitmap))
.expect("send failed");
let max_brightness: u8 = Brightness::MAX.into();
let mut brightnesses = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT);
for (index, byte) in brightnesses.data_ref_mut().iter_mut().enumerate() {
let level = index as u8 % max_brightness;
*byte = Brightness::try_from(level).unwrap();
}
let command: BrightnessGridCommand = brightnesses.into();
connection.send(command).expect("send failed");
}