From 644c0d8e73d78d4437e0df03c0c9192fb8e88d6a Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Mon, 26 Sep 2022 15:22:30 +0200 Subject: [PATCH] initial graphics --- airportdisplay/src/commands.rs | 9 +++++++++ airportdisplay/src/graphics.rs | 9 +++++++++ airportdisplay/src/lib.rs | 1 + airportdisplay/src/protocol.rs | 36 +++++++++++++++++++++++++--------- 4 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 airportdisplay/src/graphics.rs diff --git a/airportdisplay/src/commands.rs b/airportdisplay/src/commands.rs index c34a8dc..f16df68 100644 --- a/airportdisplay/src/commands.rs +++ b/airportdisplay/src/commands.rs @@ -1,6 +1,7 @@ use std::convert::From; use super::{ + graphics::Graphics, luminance::Luminance, text::{Buffer as TextBuffer, Raw as TextRaw, Text}, }; @@ -13,6 +14,7 @@ pub enum Command { Fadeout, Text(Text), Luminance(Luminance), + Graphics(Graphics), } /// Directly converty a raw text into a command which @@ -38,3 +40,10 @@ impl From for Command { Command::Luminance(luminance) } } + +/// Shortcut for graphics +impl From for Command { + fn from(gfx: Graphics) -> Self { + Command::Graphics(gfx) + } +} diff --git a/airportdisplay/src/graphics.rs b/airportdisplay/src/graphics.rs new file mode 100644 index 0000000..800c13a --- /dev/null +++ b/airportdisplay/src/graphics.rs @@ -0,0 +1,9 @@ +pub enum Graphics { + /// Raw is a series + Raw, +} + +/// Raw: Offset + Raw pixel content. +/// Pixels content: series of byte-sized 8 pixel +/// horizontal blocks. highest bit is the top left pixel +pub struct Raw(pub u16, pub Vec); diff --git a/airportdisplay/src/lib.rs b/airportdisplay/src/lib.rs index f61d1ab..227854d 100644 --- a/airportdisplay/src/lib.rs +++ b/airportdisplay/src/lib.rs @@ -1,6 +1,7 @@ mod commands; mod display; pub mod geometry; +pub mod graphics; pub mod luminance; mod protocol; pub mod text; diff --git a/airportdisplay/src/protocol.rs b/airportdisplay/src/protocol.rs index 7c7a056..d187633 100644 --- a/airportdisplay/src/protocol.rs +++ b/airportdisplay/src/protocol.rs @@ -5,12 +5,14 @@ use codepage_437::{ToCp437, CP437_WINGDINGS}; use super::{ commands::Command, geometry::{Origin, Size, Window, COLUMNS, ROWS}, + graphics::Raw as GraphicsRaw, luminance::Luminance, - text, + text::{Buffer as TextBuffer, Raw as TextRaw, Text}, }; const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03]; const CMD_RAW_LUM: &'static [u8] = &[0x00, 0x05]; +const CMD_RAW_GFX: &'static [u8] = &[0x00, 0x12]; /// A frame holds a single encoded display command, /// like set text at pos x, y. @@ -44,9 +46,25 @@ impl From for Frame { } } +/// Encode raw graphics +impl From for Data { + fn from(raw: GraphicsRaw) -> Self { + let GraphicsRaw(offset, data) = raw; + vec![[ + CMD_RAW_GFX.into(), + encode_u16(offset), + encode_u16(data.len() as u16), + encode_u16(0), + encode_u16(0), + data.into(), + ] + .concat()] + } +} + /// Encode raw text byte command -impl From for Data { - fn from(text::Raw(origin, bytes): text::Raw) -> Data { +impl From for Data { + fn from(TextRaw(origin, bytes): TextRaw) -> Data { let mut bytes = bytes.clone(); bytes.truncate(COLUMNS); let size = Size(bytes.len() as u16, 1); @@ -63,8 +81,8 @@ impl From for Data { } /// Encode a text buffer as a series of commands (data). -impl From for Data { - fn from(text::Buffer(Origin(x, y), text): text::Buffer) -> Data { +impl From for Data { + fn from(TextBuffer(Origin(x, y), text): TextBuffer) -> Data { let mut lines: Vec<&str> = text.split("\n").collect(); lines.truncate(ROWS); @@ -94,11 +112,11 @@ impl From for Data { } /// Encode text command -impl From for Data { - fn from(text: text::Text) -> Data { +impl From for Data { + fn from(text: Text) -> Data { match text { - text::Text::Raw(raw) => raw.into(), - text::Text::Buffer(buffer) => buffer.into(), + Text::Raw(raw) => raw.into(), + Text::Buffer(buffer) => buffer.into(), } } }