cargo fmt

This commit is contained in:
Vinzenz Schroeter 2025-01-26 13:16:19 +01:00
parent 3b3e8f4c1d
commit 9d8e2f28c4
6 changed files with 38 additions and 17 deletions

View file

@ -54,4 +54,4 @@ pub struct GuiOptions {
help = "add spacers between tile rows to simulate gaps in real display"
)]
pub spacers: bool,
}
}

View file

@ -1,5 +1,5 @@
use std::ops::Index;
use servicepoint::{Bitmap, DataRef, TILE_SIZE};
use std::ops::Index;
const CHAR_COUNT: usize = u8::MAX as usize + 1;

View file

@ -1,5 +1,5 @@
use crate::execute_command::ExecutionResult::{Failure, Shutdown, Success};
use crate::cp437_font::Cp437Font;
use crate::execute_command::ExecutionResult::{Failure, Shutdown, Success};
use crate::font_renderer::FontRenderer8x8;
use log::{debug, error, info, trace, warn};
use servicepoint::{

View file

@ -60,7 +60,10 @@ impl FontRenderer8x8 {
pub fn from_name(family_name: String) -> Self {
let font = SystemSource::new()
.select_best_match(&[FamilyName::Title(family_name)], &Properties::new())
.select_best_match(
&[FamilyName::Title(family_name)],
&Properties::new(),
)
.unwrap()
.load()
.unwrap();

View file

@ -12,7 +12,7 @@ use winit::event_loop::ActiveEventLoop;
use winit::keyboard::KeyCode::KeyC;
use winit::window::{Window, WindowId};
use crate::cli::{GuiOptions};
use crate::cli::GuiOptions;
pub struct Gui<'t> {
display: &'t RwLock<Bitmap>,
@ -76,7 +76,8 @@ impl<'t> Gui<'t> {
fn draw_frame(&self, frame: &mut ChunksExactMut<u8>) {
let display = self.display.read().unwrap();
let luma = self.luma.read().unwrap();
let brightness_scale = (u8::MAX as f32) / (u8::from(Brightness::MAX) as f32);
let brightness_scale =
(u8::MAX as f32) / (u8::from(Brightness::MAX) as f32);
for tile_y in 0..TILE_HEIGHT {
if self.options.spacers && tile_y != 0 {
@ -90,11 +91,16 @@ impl<'t> Gui<'t> {
for y in start_y..start_y + TILE_SIZE {
for tile_x in 0..TILE_WIDTH {
let brightness = u8::from(luma.get(tile_x, tile_y));
let brightness = (brightness_scale * brightness as f32) as u8;
let brightness =
(brightness_scale * brightness as f32) as u8;
let on_color = self.get_on_color(brightness);
let start_x = tile_x * TILE_SIZE;
for x in start_x..start_x + TILE_SIZE {
let color = if display.get(x, y) { on_color } else { OFF_COLOR };
let color = if display.get(x, y) {
on_color
} else {
OFF_COLOR
};
let pixel = frame.next().unwrap();
pixel.copy_from_slice(&color);
}

View file

@ -1,10 +1,12 @@
#![deny(clippy::all)]
use crate::font_renderer::FontRenderer8x8;
use crate::{
execute_command::{CommandExecutor, ExecutionResult},
gui::{AppEvents, Gui},
};
use clap::Parser;
use cli::Cli;
use log::{error, info, warn, LevelFilter};
use servicepoint::*;
use std::io::ErrorKind;
@ -12,14 +14,12 @@ use std::net::UdpSocket;
use std::sync::{mpsc, RwLock};
use std::time::Duration;
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
use cli::Cli;
use crate::font_renderer::FontRenderer8x8;
mod execute_command;
mod cli;
mod cp437_font;
mod execute_command;
mod font_renderer;
mod gui;
mod cli;
const BUF_SIZE: usize = 8985;
@ -49,7 +49,9 @@ fn main() {
event_loop.set_control_flow(ControlFlow::Wait);
let event_proxy = event_loop.create_proxy();
let font_renderer = cli.font.map(move |font| FontRenderer8x8::from_name(font))
let font_renderer = cli
.font
.map(move |font| FontRenderer8x8::from_name(font))
.unwrap_or_else(move || FontRenderer8x8::default());
let command_executor = CommandExecutor::new(&display, &luma, font_renderer);
@ -59,7 +61,9 @@ fn main() {
while stop_udp_rx.try_recv().is_err() {
receive_into_buf(&socket, &mut buf)
.and_then(move |amount| command_from_slice(&buf[..amount]))
.map(|cmd| handle_command(&event_proxy, &command_executor, cmd));
.map(|cmd| {
handle_command(&event_proxy, &command_executor, cmd)
});
}
});
event_loop
@ -68,7 +72,11 @@ fn main() {
});
}
fn handle_command(event_proxy: &EventLoopProxy<AppEvents>, command_executor: &CommandExecutor, command: Command) {
fn handle_command(
event_proxy: &EventLoopProxy<AppEvents>,
command_executor: &CommandExecutor,
command: Command,
) {
match command_executor.execute(command) {
ExecutionResult::Success => {
event_proxy
@ -100,10 +108,14 @@ fn init_logging(debug: bool) {
fn command_from_slice(slice: &[u8]) -> Option<Command> {
let packet = servicepoint::Packet::try_from(slice)
.inspect_err(|_| warn!("could not load packet with length {}", slice.len()))
.inspect_err(|_| {
warn!("could not load packet with length {}", slice.len())
})
.ok()?;
Command::try_from(packet)
.inspect_err(move |err| warn!("could not read command for packet: {:?}", err))
.inspect_err(move |err| {
warn!("could not read command for packet: {:?}", err)
})
.ok()
}