rename modules
This commit is contained in:
parent
c66e6db498
commit
d195f6100a
34 changed files with 110 additions and 110 deletions
|
|
@ -24,11 +24,11 @@ use servicepoint::*;
|
|||
|
||||
fn main() {
|
||||
// establish connection
|
||||
let connection = connection::Udp::open("172.23.42.29:2342")
|
||||
let connection = connections::Udp::open("172.23.42.29:2342")
|
||||
.expect("connection failed");
|
||||
|
||||
// clear screen content
|
||||
connection.send(command::Clear)
|
||||
connection.send(commands::Clear)
|
||||
.expect("send failed");
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@ fn main() {
|
|||
cli.text.push("Hello, CCCB!".to_string());
|
||||
}
|
||||
|
||||
let connection = connection::Udp::open(&cli.destination)
|
||||
let connection = connections::Udp::open(&cli.destination)
|
||||
.expect("could not connect to display");
|
||||
|
||||
if cli.clear {
|
||||
connection
|
||||
.send(command::Clear)
|
||||
.send(commands::Clear)
|
||||
.expect("sending clear failed");
|
||||
}
|
||||
|
||||
let text = cli.text.join("\n");
|
||||
let command = command::Utf8Data {
|
||||
let command = commands::Utf8Data {
|
||||
origin: Origin::ZERO,
|
||||
grid: CharGrid::wrap_str(TILE_WIDTH, &text),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ struct Cli {
|
|||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let connection = connection::Udp::open(cli.destination)
|
||||
let connection = connections::Udp::open(cli.destination)
|
||||
.expect("could not connect to display");
|
||||
|
||||
let mut bitmap = Bitmap::max_sized();
|
||||
bitmap.fill(true);
|
||||
|
||||
let command = command::BitmapLinearWin {
|
||||
let command = commands::BitmapLinearWin {
|
||||
origin: Origin::ZERO,
|
||||
bitmap,
|
||||
compression: CompressionCode::default(),
|
||||
|
|
@ -31,7 +31,7 @@ fn main() {
|
|||
*byte = Brightness::try_from(level).unwrap();
|
||||
}
|
||||
|
||||
let command = command::CharBrightness {
|
||||
let command = commands::CharBrightness {
|
||||
origin: Origin::ZERO,
|
||||
grid: brightnesses,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ struct Cli {
|
|||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let connection = connection::Udp::open(&cli.destination)
|
||||
let connection = connections::Udp::open(&cli.destination)
|
||||
.expect("could not connect to display");
|
||||
let mut field = make_random_field(cli.probability);
|
||||
|
||||
loop {
|
||||
let command = command::BitmapLinearWin {
|
||||
let command = commands::BitmapLinearWin {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: field.clone(),
|
||||
compression: CompressionCode::default(),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ struct Cli {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let connection = connection::Udp::open(Cli::parse().destination)
|
||||
let connection = connections::Udp::open(Cli::parse().destination)
|
||||
.expect("could not connect to display");
|
||||
|
||||
let mut bitmap = Bitmap::max_sized();
|
||||
|
|
@ -22,7 +22,7 @@ fn main() {
|
|||
bitmap.set((y + x_offset) % PIXEL_WIDTH, y, true);
|
||||
}
|
||||
|
||||
let command = command::BitmapLinearWin {
|
||||
let command = commands::BitmapLinearWin {
|
||||
bitmap: bitmap.clone(),
|
||||
compression: CompressionCode::default(),
|
||||
origin: Origin::ZERO,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ struct Cli {
|
|||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let connection = connection::Udp::open(cli.destination)
|
||||
let connection = connections::Udp::open(cli.destination)
|
||||
.expect("could not connect to display");
|
||||
let wait_duration = Duration::from_millis(cli.wait_ms);
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ fn main() {
|
|||
let mut filled_grid = Bitmap::max_sized();
|
||||
filled_grid.fill(true);
|
||||
|
||||
let command = command::BitmapLinearWin {
|
||||
let command = commands::BitmapLinearWin {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: filled_grid,
|
||||
compression: CompressionCode::default(),
|
||||
|
|
@ -59,7 +59,7 @@ fn main() {
|
|||
}
|
||||
|
||||
connection
|
||||
.send(command::CharBrightness { origin, grid: luma })
|
||||
.send(commands::CharBrightness { origin, grid: luma })
|
||||
.unwrap();
|
||||
std::thread::sleep(wait_duration);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
//! Example for how to use the WebSocket connection
|
||||
|
||||
use servicepoint::connection::Websocket;
|
||||
use servicepoint::connections::Websocket;
|
||||
use servicepoint::*;
|
||||
|
||||
fn main() {
|
||||
let uri = "ws://localhost:8080".parse().unwrap();
|
||||
let connection = Websocket::open(uri).unwrap();
|
||||
|
||||
connection.send(command::Clear).unwrap();
|
||||
connection.send(commands::Clear).unwrap();
|
||||
|
||||
let mut pixels = Bitmap::max_sized();
|
||||
pixels.fill(true);
|
||||
|
||||
let command = command::BitmapLinearWin {
|
||||
let command = commands::BitmapLinearWin {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: pixels,
|
||||
compression: CompressionCode::default(),
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fn main() {
|
|||
Duration::from_millis(cli.time / PIXEL_WIDTH as u64),
|
||||
);
|
||||
|
||||
let connection = connection::Udp::open(cli.destination)
|
||||
let connection = connections::Udp::open(cli.destination)
|
||||
.expect("could not connect to display");
|
||||
|
||||
let mut enabled_pixels = Bitmap::max_sized();
|
||||
|
|
@ -32,7 +32,7 @@ fn main() {
|
|||
enabled_pixels.set(x_offset % PIXEL_WIDTH, y, false);
|
||||
}
|
||||
|
||||
let command = command::BitmapLinearWin {
|
||||
let command = commands::BitmapLinearWin {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: enabled_pixels.clone(),
|
||||
compression: CompressionCode::default(),
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ use rand::{
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use servicepoint::{Brightness, Command, Connection, connection};
|
||||
/// # use servicepoint::{Brightness, Command, Connection, connections};
|
||||
/// let b = Brightness::MAX;
|
||||
/// let val: u8 = b.into();
|
||||
///
|
||||
/// let b = Brightness::try_from(7).unwrap();
|
||||
/// # let connection = connection::Fake;
|
||||
/// # let connection = connections::Fake;
|
||||
/// let result = connection.send(b);
|
||||
/// ```
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ use crate::ByteGrid;
|
|||
/// grid.set(0, 0, Brightness::MIN);
|
||||
/// grid.set(1, 1, Brightness::MIN);
|
||||
///
|
||||
/// # let connection = connection::Fake;
|
||||
/// connection.send(command::CharBrightness {
|
||||
/// origin: Origin::new(3, 7),
|
||||
/// # let connection = connections::Fake;
|
||||
/// connection.send(commands::CharBrightness {
|
||||
/// origin: Origin::new(3, 7),
|
||||
/// grid
|
||||
/// }).unwrap()
|
||||
/// ```
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ use std::string::FromUtf8Error;
|
|||
/// let grid = CharGrid::from("You can\nload multiline\nstrings directly");
|
||||
/// assert_eq!(grid.get_row_str(1), Some("load multiline\0\0".to_string()));
|
||||
///
|
||||
/// # let connection = connection::Fake;
|
||||
/// let command = command::Utf8Data { origin: Origin::ZERO, grid };
|
||||
/// # let connection = connections::Fake;
|
||||
/// let command = commands::Utf8Data { origin: Origin::ZERO, grid };
|
||||
/// connection.send(command).unwrap()
|
||||
/// ```
|
||||
pub type CharGrid = ValueGrid<char>;
|
||||
|
|
|
|||
51
src/commands/bitmap_legacy.rs
Normal file
51
src/commands/bitmap_legacy.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use crate::{
|
||||
commands::check_command_code_only, commands::TryFromPacketError,
|
||||
command_code::CommandCode, Packet, TypedCommand,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// Legacy command code, gets ignored by the real display.
|
||||
///
|
||||
/// Might be useful as a noop package.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// // this sends a packet that does nothing
|
||||
/// # #[allow(deprecated)]
|
||||
/// connection.send(commands::BitmapLegacy).unwrap();
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[deprecated]
|
||||
pub struct BitmapLegacy;
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl TryFrom<Packet> for BitmapLegacy {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(value: Packet) -> Result<Self, Self::Error> {
|
||||
if let Some(e) =
|
||||
check_command_code_only(value, CommandCode::BitmapLegacy)
|
||||
{
|
||||
Err(e)
|
||||
} else {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl From<BitmapLegacy> for Packet {
|
||||
fn from(_: BitmapLegacy) -> Self {
|
||||
Packet::command_code_only(CommandCode::BitmapLegacy)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl From<BitmapLegacy> for TypedCommand {
|
||||
fn from(command: BitmapLegacy) -> Self {
|
||||
Self::BitmapLegacy(command)
|
||||
}
|
||||
}
|
||||
91
src/commands/bitmap_linear.rs
Normal file
91
src/commands/bitmap_linear.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
use crate::{
|
||||
commands::TryFromPacketError, command_code::CommandCode,
|
||||
compression::into_decompressed, BitVec, CompressionCode, Header, Offset,
|
||||
Packet, TypedCommand,
|
||||
};
|
||||
|
||||
/// Set pixel data starting at the pixel offset on screen.
|
||||
///
|
||||
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
||||
/// once the starting row is full, overwriting will continue on column 0.
|
||||
///
|
||||
/// The contained [BitVec] is always uncompressed.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct BitmapLinear {
|
||||
/// where to start overwriting pixel data
|
||||
pub offset: Offset,
|
||||
/// the pixels to send to the display as one long row
|
||||
pub bitvec: BitVec,
|
||||
/// how to compress the command when converting to packet
|
||||
pub compression: CompressionCode,
|
||||
}
|
||||
|
||||
impl From<BitmapLinear> for Packet {
|
||||
fn from(bitmap: BitmapLinear) -> Self {
|
||||
Packet::bitmap_linear_into_packet(
|
||||
CommandCode::BitmapLinear,
|
||||
bitmap.offset,
|
||||
bitmap.compression,
|
||||
bitmap.bitvec.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BitmapLinear {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
let (offset, bitvec, compression) =
|
||||
Self::packet_into_linear_bitmap(packet)?;
|
||||
Ok(Self {
|
||||
offset,
|
||||
bitvec,
|
||||
compression,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinear> for TypedCommand {
|
||||
fn from(command: BitmapLinear) -> Self {
|
||||
Self::BitmapLinear(command)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitmapLinear {
|
||||
/// Helper method for Packets into `BitmapLinear*`-Commands
|
||||
pub(crate) fn packet_into_linear_bitmap(
|
||||
packet: Packet,
|
||||
) -> Result<(Offset, BitVec, CompressionCode), TryFromPacketError> {
|
||||
let Packet {
|
||||
header:
|
||||
Header {
|
||||
a: offset,
|
||||
b: length,
|
||||
c: sub,
|
||||
d: reserved,
|
||||
..
|
||||
},
|
||||
payload,
|
||||
} = packet;
|
||||
if reserved != 0 {
|
||||
return Err(TryFromPacketError::ExtraneousHeaderValues);
|
||||
}
|
||||
let sub = match CompressionCode::try_from(sub) {
|
||||
Err(()) => {
|
||||
return Err(TryFromPacketError::InvalidCompressionCode(sub));
|
||||
}
|
||||
Ok(value) => value,
|
||||
};
|
||||
let payload = match into_decompressed(sub, payload) {
|
||||
None => return Err(TryFromPacketError::DecompressionFailed),
|
||||
Some(value) => value,
|
||||
};
|
||||
if payload.len() != length as usize {
|
||||
return Err(TryFromPacketError::UnexpectedPayloadSize(
|
||||
length as usize,
|
||||
payload.len(),
|
||||
));
|
||||
}
|
||||
Ok((offset as Offset, BitVec::from_vec(payload), sub))
|
||||
}
|
||||
}
|
||||
52
src/commands/bitmap_linear_and.rs
Normal file
52
src/commands/bitmap_linear_and.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use crate::{
|
||||
commands::{BitmapLinear, TryFromPacketError},
|
||||
command_code::CommandCode,
|
||||
BitVec, CompressionCode, Offset, Packet, TypedCommand,
|
||||
};
|
||||
|
||||
/// Set pixel data according to an and-mask starting at the offset.
|
||||
///
|
||||
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
||||
/// once the starting row is full, overwriting will continue on column 0.
|
||||
///
|
||||
/// The contained [BitVec] is always uncompressed.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct BitmapLinearAnd {
|
||||
/// where to start overwriting pixel data
|
||||
pub offset: Offset,
|
||||
/// the pixels to send to the display as one long row
|
||||
pub bitvec: BitVec,
|
||||
/// how to compress the command when converting to packet
|
||||
pub compression: CompressionCode,
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BitmapLinearAnd {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
let (offset, bitvec, compression) =
|
||||
BitmapLinear::packet_into_linear_bitmap(packet)?;
|
||||
Ok(Self {
|
||||
offset,
|
||||
bitvec,
|
||||
compression,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearAnd> for Packet {
|
||||
fn from(bitmap: BitmapLinearAnd) -> Self {
|
||||
Packet::bitmap_linear_into_packet(
|
||||
CommandCode::BitmapLinearAnd,
|
||||
bitmap.offset,
|
||||
bitmap.compression,
|
||||
bitmap.bitvec.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearAnd> for TypedCommand {
|
||||
fn from(command: BitmapLinearAnd) -> Self {
|
||||
Self::BitmapLinearAnd(command)
|
||||
}
|
||||
}
|
||||
52
src/commands/bitmap_linear_or.rs
Normal file
52
src/commands/bitmap_linear_or.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use crate::{
|
||||
commands::{BitmapLinear, TryFromPacketError},
|
||||
command_code::CommandCode,
|
||||
BitVec, CompressionCode, Offset, Packet, TypedCommand,
|
||||
};
|
||||
|
||||
/// Set pixel data according to an or-mask starting at the offset.
|
||||
///
|
||||
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
||||
/// once the starting row is full, overwriting will continue on column 0.
|
||||
///
|
||||
/// The contained [BitVec] is always uncompressed.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct BitmapLinearOr {
|
||||
/// where to start overwriting pixel data
|
||||
pub offset: Offset,
|
||||
/// the pixels to send to the display as one long row
|
||||
pub bitvec: BitVec,
|
||||
/// how to compress the command when converting to packet
|
||||
pub compression: CompressionCode,
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BitmapLinearOr {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
let (offset, bitvec, compression) =
|
||||
BitmapLinear::packet_into_linear_bitmap(packet)?;
|
||||
Ok(Self {
|
||||
offset,
|
||||
bitvec,
|
||||
compression,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearOr> for Packet {
|
||||
fn from(bitmap: BitmapLinearOr) -> Self {
|
||||
Packet::bitmap_linear_into_packet(
|
||||
CommandCode::BitmapLinearOr,
|
||||
bitmap.offset,
|
||||
bitmap.compression,
|
||||
bitmap.bitvec.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearOr> for TypedCommand {
|
||||
fn from(command: BitmapLinearOr) -> Self {
|
||||
Self::BitmapLinearOr(command)
|
||||
}
|
||||
}
|
||||
157
src/commands/bitmap_linear_win.rs
Normal file
157
src/commands/bitmap_linear_win.rs
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
use crate::{
|
||||
commands::TryFromPacketError, command_code::CommandCode,
|
||||
compression::into_compressed, compression::into_decompressed, Bitmap,
|
||||
CompressionCode, Grid, Header, Origin, Packet, Pixels, TypedCommand,
|
||||
TILE_SIZE,
|
||||
};
|
||||
|
||||
/// Overwrites a rectangular region of pixels.
|
||||
///
|
||||
/// Origin coordinates must be divisible by 8.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// #
|
||||
/// let mut bitmap = Bitmap::max_sized();
|
||||
/// // draw something to the pixels here
|
||||
/// # bitmap.set(2, 5, true);
|
||||
///
|
||||
/// // create command to send pixels
|
||||
/// let command = commands::BitmapLinearWin {
|
||||
/// bitmap,
|
||||
/// origin: Origin::ZERO,
|
||||
/// compression: CompressionCode::Uncompressed
|
||||
/// };
|
||||
///
|
||||
/// connection.send(command).expect("send failed");
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct BitmapLinearWin {
|
||||
/// where to start drawing the pixels
|
||||
pub origin: Origin<Pixels>,
|
||||
/// the pixels to send
|
||||
pub bitmap: Bitmap,
|
||||
/// how to compress the command when converting to packet
|
||||
pub compression: CompressionCode,
|
||||
}
|
||||
|
||||
impl From<BitmapLinearWin> for Packet {
|
||||
fn from(value: BitmapLinearWin) -> Self {
|
||||
assert_eq!(value.origin.x % 8, 0);
|
||||
assert_eq!(value.bitmap.width() % 8, 0);
|
||||
|
||||
let tile_x = (value.origin.x / TILE_SIZE) as u16;
|
||||
let tile_w = (value.bitmap.width() / TILE_SIZE) as u16;
|
||||
let pixel_h = value.bitmap.height() as u16;
|
||||
let payload = into_compressed(value.compression, value.bitmap.into());
|
||||
let command = match value.compression {
|
||||
CompressionCode::Uncompressed => {
|
||||
CommandCode::BitmapLinearWinUncompressed
|
||||
}
|
||||
#[cfg(feature = "compression_zlib")]
|
||||
CompressionCode::Zlib => CommandCode::BitmapLinearWinZlib,
|
||||
#[cfg(feature = "compression_bzip2")]
|
||||
CompressionCode::Bzip2 => CommandCode::BitmapLinearWinBzip2,
|
||||
#[cfg(feature = "compression_lzma")]
|
||||
CompressionCode::Lzma => CommandCode::BitmapLinearWinLzma,
|
||||
#[cfg(feature = "compression_zstd")]
|
||||
CompressionCode::Zstd => CommandCode::BitmapLinearWinZstd,
|
||||
};
|
||||
|
||||
Packet {
|
||||
header: Header {
|
||||
command_code: command.into(),
|
||||
a: tile_x,
|
||||
b: value.origin.y as u16,
|
||||
c: tile_w,
|
||||
d: pixel_h,
|
||||
},
|
||||
payload,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BitmapLinearWin {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
let code = CommandCode::try_from(packet.header.command_code).map_err(
|
||||
|_| TryFromPacketError::InvalidCommand(packet.header.command_code),
|
||||
)?;
|
||||
|
||||
match code {
|
||||
CommandCode::BitmapLinearWinUncompressed => {
|
||||
Self::packet_into_bitmap_win(
|
||||
packet,
|
||||
CompressionCode::Uncompressed,
|
||||
)
|
||||
}
|
||||
#[cfg(feature = "compression_zlib")]
|
||||
CommandCode::BitmapLinearWinZlib => {
|
||||
Self::packet_into_bitmap_win(packet, CompressionCode::Zlib)
|
||||
}
|
||||
#[cfg(feature = "compression_bzip2")]
|
||||
CommandCode::BitmapLinearWinBzip2 => {
|
||||
Self::packet_into_bitmap_win(packet, CompressionCode::Bzip2)
|
||||
}
|
||||
#[cfg(feature = "compression_lzma")]
|
||||
CommandCode::BitmapLinearWinLzma => {
|
||||
Self::packet_into_bitmap_win(packet, CompressionCode::Lzma)
|
||||
}
|
||||
#[cfg(feature = "compression_zstd")]
|
||||
CommandCode::BitmapLinearWinZstd => {
|
||||
Self::packet_into_bitmap_win(packet, CompressionCode::Zstd)
|
||||
}
|
||||
|
||||
_ => Err(TryFromPacketError::InvalidCommand(
|
||||
packet.header.command_code,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearWin> for TypedCommand {
|
||||
fn from(command: BitmapLinearWin) -> Self {
|
||||
Self::BitmapLinearWin(command)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitmapLinearWin {
|
||||
fn packet_into_bitmap_win(
|
||||
packet: Packet,
|
||||
compression: CompressionCode,
|
||||
) -> Result<Self, TryFromPacketError> {
|
||||
let Packet {
|
||||
header:
|
||||
Header {
|
||||
command_code: _,
|
||||
a: tiles_x,
|
||||
b: pixels_y,
|
||||
c: tile_w,
|
||||
d: pixel_h,
|
||||
},
|
||||
payload,
|
||||
} = packet;
|
||||
|
||||
let payload = match into_decompressed(compression, payload) {
|
||||
None => return Err(TryFromPacketError::DecompressionFailed),
|
||||
Some(decompressed) => decompressed,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
origin: Origin::new(
|
||||
tiles_x as usize * TILE_SIZE,
|
||||
pixels_y as usize,
|
||||
),
|
||||
bitmap: Bitmap::load(
|
||||
tile_w as usize * TILE_SIZE,
|
||||
pixel_h as usize,
|
||||
&payload,
|
||||
),
|
||||
compression,
|
||||
})
|
||||
}
|
||||
}
|
||||
52
src/commands/bitmap_linear_xor.rs
Normal file
52
src/commands/bitmap_linear_xor.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use crate::{
|
||||
commands::{BitmapLinear, TryFromPacketError},
|
||||
command_code::CommandCode,
|
||||
BitVec, CompressionCode, Offset, Packet, TypedCommand,
|
||||
};
|
||||
|
||||
/// Set pixel data according to a xor-mask starting at the offset.
|
||||
///
|
||||
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
||||
/// once the starting row is full, overwriting will continue on column 0.
|
||||
///
|
||||
/// The contained [BitVec] is always uncompressed.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct BitmapLinearXor {
|
||||
/// where to start overwriting pixel data
|
||||
pub offset: Offset,
|
||||
/// the pixels to send to the display as one long row
|
||||
pub bitvec: BitVec,
|
||||
/// how to compress the command when converting to packet
|
||||
pub compression: CompressionCode,
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BitmapLinearXor {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
let (offset, bitvec, compression) =
|
||||
BitmapLinear::packet_into_linear_bitmap(packet)?;
|
||||
Ok(Self {
|
||||
offset,
|
||||
bitvec,
|
||||
compression,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearXor> for Packet {
|
||||
fn from(bitmap: BitmapLinearXor) -> Self {
|
||||
Packet::bitmap_linear_into_packet(
|
||||
CommandCode::BitmapLinearXor,
|
||||
bitmap.offset,
|
||||
bitmap.compression,
|
||||
bitmap.bitvec.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearXor> for TypedCommand {
|
||||
fn from(command: BitmapLinearXor) -> Self {
|
||||
Self::BitmapLinearXor(command)
|
||||
}
|
||||
}
|
||||
58
src/commands/char_brightness.rs
Normal file
58
src/commands/char_brightness.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use crate::{
|
||||
commands::TryFromPacketError, command_code::CommandCode, BrightnessGrid,
|
||||
ByteGrid, Header, Origin, Packet, Tiles, TypedCommand,
|
||||
};
|
||||
|
||||
/// Set the brightness of individual tiles in a rectangular area of the display.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct CharBrightness {
|
||||
/// which tile the brightness rectangle should start
|
||||
pub origin: Origin<Tiles>,
|
||||
/// the brightness values per tile
|
||||
pub grid: BrightnessGrid,
|
||||
}
|
||||
|
||||
impl From<CharBrightness> for Packet {
|
||||
fn from(value: CharBrightness) -> Self {
|
||||
Packet::origin_grid_to_packet(
|
||||
value.origin,
|
||||
value.grid,
|
||||
CommandCode::CharBrightness,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for CharBrightness {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
let Packet {
|
||||
header:
|
||||
Header {
|
||||
command_code: _,
|
||||
a: x,
|
||||
b: y,
|
||||
c: width,
|
||||
d: height,
|
||||
},
|
||||
payload,
|
||||
} = packet;
|
||||
|
||||
let grid = ByteGrid::load(width as usize, height as usize, &*payload);
|
||||
let grid = match BrightnessGrid::try_from(grid) {
|
||||
Ok(grid) => grid,
|
||||
Err(val) => return Err(TryFromPacketError::InvalidBrightness(val)),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
grid,
|
||||
origin: Origin::new(x as usize, y as usize),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CharBrightness> for TypedCommand {
|
||||
fn from(command: CharBrightness) -> Self {
|
||||
Self::CharBrightness(command)
|
||||
}
|
||||
}
|
||||
41
src/commands/clear.rs
Normal file
41
src/commands/clear.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use crate::{
|
||||
commands::check_command_code_only, commands::TryFromPacketError,
|
||||
command_code::CommandCode, Packet, TypedCommand,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// Set all pixels to the off state. Does not affect brightness.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{connections, Command, Connection, commands};
|
||||
/// # let connection = connections::Fake;
|
||||
/// connection.send(commands::Clear).unwrap();
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
/// ```
|
||||
pub struct Clear;
|
||||
|
||||
impl TryFrom<Packet> for Clear {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(value: Packet) -> Result<Self, Self::Error> {
|
||||
if let Some(e) = check_command_code_only(value, CommandCode::Clear) {
|
||||
Err(e)
|
||||
} else {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Clear> for Packet {
|
||||
fn from(_: Clear) -> Self {
|
||||
Packet::command_code_only(CommandCode::Clear)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Clear> for TypedCommand {
|
||||
fn from(command: Clear) -> Self {
|
||||
Self::Clear(command)
|
||||
}
|
||||
}
|
||||
73
src/commands/cp437_data.rs
Normal file
73
src/commands/cp437_data.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
use crate::{
|
||||
commands::TryFromPacketError, command_code::CommandCode, Cp437Grid, Header,
|
||||
Origin, Packet, Tiles, TypedCommand,
|
||||
};
|
||||
|
||||
/// Show text on the screen.
|
||||
///
|
||||
/// The text is sent in the form of a 2D grid of [CP-437] encoded characters.
|
||||
///
|
||||
/// <div class="warning">You probably want to use [Command::Utf8Data] instead</div>
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// let grid = CharGrid::from("Hello,\nWorld!");
|
||||
/// let grid = Cp437Grid::from(&grid);
|
||||
/// connection.send(commands::Cp437Data{ origin: Origin::ZERO, grid }).expect("send failed");
|
||||
/// ```
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// let grid = Cp437Grid::load_ascii("Hello\nWorld", 5, false).unwrap();
|
||||
/// connection.send(commands::Cp437Data{ origin: Origin::new(2, 2), grid }).unwrap();
|
||||
/// ```
|
||||
/// [CP-437]: https://en.wikipedia.org/wiki/Code_page_437
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Cp437Data {
|
||||
/// which tile the text should start
|
||||
pub origin: Origin<Tiles>,
|
||||
/// the text to send to the display
|
||||
pub grid: Cp437Grid,
|
||||
}
|
||||
|
||||
impl From<Cp437Data> for Packet {
|
||||
fn from(value: Cp437Data) -> Self {
|
||||
Packet::origin_grid_to_packet(
|
||||
value.origin,
|
||||
value.grid,
|
||||
CommandCode::Cp437Data,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for Cp437Data {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
let Packet {
|
||||
header:
|
||||
Header {
|
||||
command_code: _,
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
},
|
||||
payload,
|
||||
} = packet;
|
||||
Ok(Self {
|
||||
origin: Origin::new(a as usize, b as usize),
|
||||
grid: Cp437Grid::load(c as usize, d as usize, &*payload),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Cp437Data> for TypedCommand {
|
||||
fn from(command: Cp437Data) -> Self {
|
||||
Self::Cp437Data(command)
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue