mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-19 02:20:12 +01:00
added luminance support
This commit is contained in:
parent
4a0e762142
commit
9ae7186262
|
@ -1,6 +1,9 @@
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
use super::text;
|
use super::{
|
||||||
|
luminance::Luminance,
|
||||||
|
text::{Buffer as TextBuffer, Raw as TextRaw, Text},
|
||||||
|
};
|
||||||
|
|
||||||
/// Display Commands
|
/// Display Commands
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
@ -8,21 +11,30 @@ pub enum Command {
|
||||||
Clear,
|
Clear,
|
||||||
Reboot,
|
Reboot,
|
||||||
Fadeout,
|
Fadeout,
|
||||||
Text(text::Text),
|
Text(Text),
|
||||||
|
Luminance(Luminance),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Directly converty a raw text into a command which
|
/// Directly converty a raw text into a command which
|
||||||
/// can be sent to the display.
|
/// can be sent to the display.
|
||||||
impl From<text::Raw> for Command {
|
impl From<TextRaw> for Command {
|
||||||
fn from(raw: text::Raw) -> Self {
|
fn from(raw: TextRaw) -> Self {
|
||||||
Command::Text(text::Text::Raw(raw))
|
Command::Text(Text::Raw(raw))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shortcut to directly convert a text buffer into
|
/// Shortcut to directly convert a text buffer into
|
||||||
/// a commmand which can be sent to the display.
|
/// a commmand which can be sent to the display.
|
||||||
impl From<text::Buffer> for Command {
|
impl From<TextBuffer> for Command {
|
||||||
fn from(buffer: text::Buffer) -> Self {
|
fn from(buffer: TextBuffer) -> Self {
|
||||||
Command::Text(text::Text::Buffer(buffer))
|
Command::Text(Text::Buffer(buffer))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shortcut to convert a luminance window
|
||||||
|
/// to a command.
|
||||||
|
impl From<Luminance> for Command {
|
||||||
|
fn from(luminance: Luminance) -> Self {
|
||||||
|
Command::Luminance(luminance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,14 @@ pub struct Origin(pub u16, pub u16);
|
||||||
/// Size defines the width and height of a window
|
/// Size defines the width and height of a window
|
||||||
pub struct Size(pub u16, pub u16);
|
pub struct Size(pub u16, pub u16);
|
||||||
|
|
||||||
|
impl Default for Size {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self(1, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A window
|
/// A window
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Window(pub Origin, pub Size);
|
pub struct Window(pub Origin, pub Size);
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
mod commands;
|
mod commands;
|
||||||
mod display;
|
mod display;
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
|
pub mod luminance;
|
||||||
mod protocol;
|
mod protocol;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
||||||
|
|
4
airportdisplay/src/luminance.rs
Normal file
4
airportdisplay/src/luminance.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
use super::geometry::Window;
|
||||||
|
|
||||||
|
/// Set luminance of [0..5??] at window
|
||||||
|
pub struct Luminance(pub Window, pub u16);
|
|
@ -5,10 +5,12 @@ use codepage_437::{ToCp437, CP437_WINGDINGS};
|
||||||
use super::{
|
use super::{
|
||||||
commands::Command,
|
commands::Command,
|
||||||
geometry::{Origin, Size, Window, COLUMNS, ROWS},
|
geometry::{Origin, Size, Window, COLUMNS, ROWS},
|
||||||
|
luminance::Luminance,
|
||||||
text,
|
text,
|
||||||
};
|
};
|
||||||
|
|
||||||
const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03];
|
const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03];
|
||||||
|
const CMD_RAW_LUM: &'static [u8] = &[0x00, 0x05];
|
||||||
|
|
||||||
/// A frame holds a single encoded display command,
|
/// A frame holds a single encoded display command,
|
||||||
/// like set text at pos x, y.
|
/// like set text at pos x, y.
|
||||||
|
@ -17,17 +19,21 @@ pub type Frame = Vec<u8>;
|
||||||
/// Data is a list of commands to be sent to the display.
|
/// Data is a list of commands to be sent to the display.
|
||||||
pub type Data = Vec<Frame>;
|
pub type Data = Vec<Frame>;
|
||||||
|
|
||||||
|
fn encode_u16(v: u16) -> Frame {
|
||||||
|
vec![(v >> 8) as u8, v as u8]
|
||||||
|
}
|
||||||
|
|
||||||
/// Encode position data as big endian
|
/// Encode position data as big endian
|
||||||
impl From<Origin> for Frame {
|
impl From<Origin> for Frame {
|
||||||
fn from(Origin(x, y): Origin) -> Self {
|
fn from(Origin(x, y): Origin) -> Self {
|
||||||
vec![(x >> 8) as u8, x as u8, (y >> 8) as u8, y as u8]
|
[encode_u16(x), encode_u16(y)].concat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encode size as big endian
|
/// Encode size as big endian
|
||||||
impl From<Size> for Frame {
|
impl From<Size> for Frame {
|
||||||
fn from(Size(w, h): Size) -> Self {
|
fn from(Size(w, h): Size) -> Self {
|
||||||
vec![(w >> 8) as u8, w as u8, (h >> 8) as u8, h as u8]
|
[encode_u16(w), encode_u16(h)].concat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +54,14 @@ impl From<text::Raw> for Data {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Encode luminance
|
||||||
|
impl From<Luminance> for Data {
|
||||||
|
fn from(luminance: Luminance) -> Data {
|
||||||
|
let Luminance(window, value) = luminance;
|
||||||
|
vec![[CMD_RAW_LUM.into(), Vec::from(window), encode_u16(value)].concat()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Encode a text buffer as a series of commands (data).
|
/// Encode a text buffer as a series of commands (data).
|
||||||
impl From<text::Buffer> for Data {
|
impl From<text::Buffer> for Data {
|
||||||
fn from(text::Buffer(Origin(x, y), text): text::Buffer) -> Data {
|
fn from(text::Buffer(Origin(x, y), text): text::Buffer) -> Data {
|
||||||
|
@ -98,6 +112,7 @@ impl From<Command> for Data {
|
||||||
Command::Reboot => vec![vec![0x00, 0x0b]],
|
Command::Reboot => vec![vec![0x00, 0x0b]],
|
||||||
Command::Fadeout => vec![vec![0x00, 0x0d]],
|
Command::Fadeout => vec![vec![0x00, 0x0d]],
|
||||||
Command::Text(text) => text.into(),
|
Command::Text(text) => text.into(),
|
||||||
|
Command::Luminance(lum) => lum.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue