From 8beca7cdd0d3d891f3d825261ac345d8e9ad892a Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Sat, 27 Aug 2022 12:33:30 +0000 Subject: [PATCH] moved columns and rows constant --- airportdisplay/src/display.rs | 7 ++----- airportdisplay/src/geometry.rs | 3 +++ airportdisplay/src/lib.rs | 5 +---- airportdisplay/src/protocol.rs | 10 +++++----- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/airportdisplay/src/display.rs b/airportdisplay/src/display.rs index de206c2..78a29af 100644 --- a/airportdisplay/src/display.rs +++ b/airportdisplay/src/display.rs @@ -1,10 +1,7 @@ -use std::net::UdpSocket; use std::io::Result; +use std::net::UdpSocket; -use super::{ - commands::Command, - protocol::Data, -}; +use super::{commands::Command, protocol::Data}; pub struct Display { addr: String, diff --git a/airportdisplay/src/geometry.rs b/airportdisplay/src/geometry.rs index 02f6132..870c98c 100644 --- a/airportdisplay/src/geometry.rs +++ b/airportdisplay/src/geometry.rs @@ -1,3 +1,6 @@ +pub const COLUMNS: usize = 56; +pub const ROWS: usize = 20; + /// An origin marks the top left position of the /// data sent to the display. #[derive(Default)] diff --git a/airportdisplay/src/lib.rs b/airportdisplay/src/lib.rs index a0077c1..9660a6b 100644 --- a/airportdisplay/src/lib.rs +++ b/airportdisplay/src/lib.rs @@ -1,12 +1,9 @@ mod commands; mod display; -mod protocol; pub mod geometry; +mod protocol; pub mod text; -pub const TEXT_COLUMNS: usize = 56; -pub const TEXT_ROWS: usize = 20; - pub use commands::Command; pub use display::Display; pub use protocol::Data; diff --git a/airportdisplay/src/protocol.rs b/airportdisplay/src/protocol.rs index dc1d15e..6254c0d 100644 --- a/airportdisplay/src/protocol.rs +++ b/airportdisplay/src/protocol.rs @@ -4,8 +4,8 @@ use codepage_437::{ToCp437, CP437_WINGDINGS}; use super::{ commands::Command, - geometry::{Origin, Size, Window}, - text, TEXT_COLUMNS, TEXT_ROWS, + geometry::{Origin, Size, Window, COLUMNS, ROWS}, + text, }; const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03]; @@ -42,7 +42,7 @@ impl From for Frame { impl From for Data { fn from(text::Raw(origin, bytes): text::Raw) -> Data { let mut bytes = bytes.clone(); - bytes.truncate(TEXT_COLUMNS); + bytes.truncate(COLUMNS); let size = Size(bytes.len() as u16, 1); vec![[CMD_RAW_TEXT.into(), origin.into(), size.into(), bytes].concat()] } @@ -52,14 +52,14 @@ impl From for Data { impl From for Data { fn from(text::Buffer(Origin(x, y), text): text::Buffer) -> Data { let mut lines: Vec<&str> = text.split("\n").collect(); - lines.truncate(TEXT_ROWS); + lines.truncate(ROWS); let mut data = vec![]; for (i, line) in lines.iter().enumerate() { // Convert utf8 to codepage 437 if let Ok(bytes) = line.to_cp437(&CP437_WINGDINGS) { let mut bytes: Frame = bytes.into(); - bytes.truncate(TEXT_COLUMNS); + bytes.truncate(COLUMNS); let len = bytes.len() as u16; let pos = Origin(x, y + i as u16);