From 68abb4c6d986c3d7f3f04aa5c6610190960c1104 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 3 Jan 2025 20:49:02 +0100 Subject: [PATCH] chore: tidy up rust code --- linux_app/src/main.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/linux_app/src/main.rs b/linux_app/src/main.rs index 0817d9d..451508d 100644 --- a/linux_app/src/main.rs +++ b/linux_app/src/main.rs @@ -1,15 +1,7 @@ -use futures::stream::StreamExt; use image::ImageReader; -use core::any::Any; -use std::{env, io, str}; -use tokio_util::codec::{Decoder, Encoder}; -use tokio::time::{sleep, Duration}; - +use std::{env, str}; use image::imageops::FilterType; - use tokio::io::AsyncWriteExt; - -use bytes::BytesMut; use tokio_serial::SerialPortBuilderExt; @@ -23,14 +15,12 @@ async fn main() -> tokio_serial::Result<()> { let tty_path = args.nth(2).unwrap_or_else(|| DEFAULT_TTY.into()); - let mut port = tokio_serial::new(tty_path, 115200).open_native_async()?; - const WIDTH: usize = 800; const HEIGHT: usize = 480; const TOTAL_BYTES: usize = WIDTH * HEIGHT * 3; const MAX_WRITE_LEN: usize = 115_200; - if (img.width() < img.height()) { + if img.width() < img.height() { img = img.rotate90(); } @@ -41,16 +31,18 @@ async fn main() -> tokio_serial::Result<()> { let mut raw_img = rgb_img.into_raw(); raw_img.resize(TOTAL_BYTES, 0x00); + let mut port = tokio_serial::new(tty_path, TOTAL_BYTES.try_into().unwrap()).open_native_async()?; + port.write(&[ 'i' as u8 ] ).await?; port.flush().await?; let mut total: usize = raw_img.len(); let mut pos: usize = 0; - while (total > 0) { + while total > 0 { let mut size = MAX_WRITE_LEN; - if (size > total) { + if size > total { size = total; } -- 2.48.1