implement From<X> for XCommand
All checks were successful
Rust / build (pull_request) Successful in 2m15s
All checks were successful
Rust / build (pull_request) Successful in 2m15s
This commit is contained in:
parent
cbab86bd93
commit
1cf37413e6
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
CharGrid, CharGridCommand, ClearCommand, Connection, Origin, UdpConnection,
|
CharGrid, CharGridCommand, ClearCommand, Connection, UdpConnection,
|
||||||
TILE_WIDTH,
|
TILE_WIDTH,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,9 +42,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = cli.text.join("\n");
|
let text = cli.text.join("\n");
|
||||||
let command = CharGridCommand {
|
let command: CharGridCommand = CharGrid::wrap_str(TILE_WIDTH, &text).into();
|
||||||
grid: CharGrid::wrap_str(TILE_WIDTH, &text),
|
|
||||||
origin: Origin::ZERO,
|
|
||||||
};
|
|
||||||
connection.send(command).expect("sending text failed");
|
connection.send(command).expect("sending text failed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Bitmap, BitmapCommand, Brightness, BrightnessGrid, BrightnessGridCommand,
|
Bitmap, BitmapCommand, Brightness, BrightnessGrid, BrightnessGridCommand,
|
||||||
CompressionCode, Connection, DataRef, Grid, Origin, UdpConnection,
|
Connection, DataRef, Grid, UdpConnection, TILE_HEIGHT, TILE_WIDTH,
|
||||||
TILE_HEIGHT, TILE_WIDTH,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
@ -21,12 +20,9 @@ fn main() {
|
||||||
let mut bitmap = Bitmap::max_sized();
|
let mut bitmap = Bitmap::max_sized();
|
||||||
bitmap.fill(true);
|
bitmap.fill(true);
|
||||||
|
|
||||||
let command = BitmapCommand {
|
connection
|
||||||
bitmap,
|
.send(BitmapCommand::from(bitmap))
|
||||||
origin: Origin::ZERO,
|
.expect("send failed");
|
||||||
compression: CompressionCode::default(),
|
|
||||||
};
|
|
||||||
connection.send(command).expect("send failed");
|
|
||||||
|
|
||||||
let max_brightness: u8 = Brightness::MAX.into();
|
let max_brightness: u8 = Brightness::MAX.into();
|
||||||
let mut brightnesses = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT);
|
let mut brightnesses = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||||
|
@ -35,9 +31,6 @@ fn main() {
|
||||||
*byte = Brightness::try_from(level).unwrap();
|
*byte = Brightness::try_from(level).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let command = BrightnessGridCommand {
|
let command: BrightnessGridCommand = brightnesses.into();
|
||||||
origin: Origin::ZERO,
|
|
||||||
grid: brightnesses,
|
|
||||||
};
|
|
||||||
connection.send(command).expect("send failed");
|
connection.send(command).expect("send failed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rand::{distributions, Rng};
|
use rand::{distributions, Rng};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin,
|
Bitmap, BitmapCommand, Connection, Grid, UdpConnection, FRAME_PACING,
|
||||||
UdpConnection, FRAME_PACING,
|
|
||||||
};
|
};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
@ -24,11 +23,7 @@ fn main() {
|
||||||
let mut field = make_random_field(cli.probability);
|
let mut field = make_random_field(cli.probability);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let command = BitmapCommand {
|
let command = BitmapCommand::from(field.clone());
|
||||||
bitmap: field.clone(),
|
|
||||||
origin: Origin::ZERO,
|
|
||||||
compression: CompressionCode::default(),
|
|
||||||
};
|
|
||||||
connection.send(command).expect("could not send");
|
connection.send(command).expect("could not send");
|
||||||
thread::sleep(FRAME_PACING);
|
thread::sleep(FRAME_PACING);
|
||||||
field = iteration(field);
|
field = iteration(field);
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin,
|
Bitmap, BitmapCommand, Connection, Grid, UdpConnection, FRAME_PACING,
|
||||||
UdpConnection, FRAME_PACING, PIXEL_HEIGHT, PIXEL_WIDTH,
|
PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||||
};
|
};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
@ -25,11 +25,7 @@ fn main() {
|
||||||
bitmap.set((y + x_offset) % PIXEL_WIDTH, y, true);
|
bitmap.set((y + x_offset) % PIXEL_WIDTH, y, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let command = BitmapCommand {
|
let command = BitmapCommand::from(bitmap.clone());
|
||||||
bitmap: bitmap.clone(),
|
|
||||||
compression: CompressionCode::default(),
|
|
||||||
origin: Origin::ZERO,
|
|
||||||
};
|
|
||||||
connection.send(command).expect("send failed");
|
connection.send(command).expect("send failed");
|
||||||
thread::sleep(FRAME_PACING);
|
thread::sleep(FRAME_PACING);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ use clap::Parser;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Bitmap, BitmapCommand, Brightness, BrightnessCommand, BrightnessGrid,
|
Bitmap, BitmapCommand, Brightness, BrightnessCommand, BrightnessGrid,
|
||||||
BrightnessGridCommand, CompressionCode, Connection, Grid, Origin,
|
BrightnessGridCommand, Connection, Grid, Origin, UdpConnection,
|
||||||
UdpConnection, TILE_HEIGHT, TILE_WIDTH,
|
TILE_HEIGHT, TILE_WIDTH,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
@ -32,11 +32,7 @@ fn main() {
|
||||||
let mut filled_grid = Bitmap::max_sized();
|
let mut filled_grid = Bitmap::max_sized();
|
||||||
filled_grid.fill(true);
|
filled_grid.fill(true);
|
||||||
|
|
||||||
let command = BitmapCommand {
|
let command = BitmapCommand::from(filled_grid);
|
||||||
bitmap: filled_grid,
|
|
||||||
origin: Origin::ZERO,
|
|
||||||
compression: CompressionCode::default(),
|
|
||||||
};
|
|
||||||
connection.send(command).expect("send failed");
|
connection.send(command).expect("send failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
//! Example for how to use the WebSocket connection
|
//! Example for how to use the WebSocket connection
|
||||||
|
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Bitmap, BitmapCommand, ClearCommand, CompressionCode, Connection, Grid,
|
Bitmap, BitmapCommand, ClearCommand, Connection, Grid, WebsocketConnection,
|
||||||
Origin, WebsocketConnection,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -14,10 +13,6 @@ fn main() {
|
||||||
let mut pixels = Bitmap::max_sized();
|
let mut pixels = Bitmap::max_sized();
|
||||||
pixels.fill(true);
|
pixels.fill(true);
|
||||||
|
|
||||||
let command = BitmapCommand {
|
let command = BitmapCommand::from(pixels);
|
||||||
bitmap: pixels,
|
|
||||||
origin: Origin::ZERO,
|
|
||||||
compression: CompressionCode::default(),
|
|
||||||
};
|
|
||||||
connection.send(command).unwrap();
|
connection.send(command).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin,
|
Bitmap, BitmapCommand, Connection, Grid, UdpConnection, FRAME_PACING,
|
||||||
UdpConnection, FRAME_PACING, PIXEL_HEIGHT, PIXEL_WIDTH,
|
PIXEL_HEIGHT, PIXEL_WIDTH,
|
||||||
};
|
};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -35,11 +35,7 @@ fn main() {
|
||||||
enabled_pixels.set(x_offset % PIXEL_WIDTH, y, false);
|
enabled_pixels.set(x_offset % PIXEL_WIDTH, y, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
let command = BitmapCommand {
|
let command = BitmapCommand::from(enabled_pixels.clone());
|
||||||
bitmap: enabled_pixels.clone(),
|
|
||||||
origin: Origin::ZERO,
|
|
||||||
compression: CompressionCode::default(),
|
|
||||||
};
|
|
||||||
connection
|
connection
|
||||||
.send(command)
|
.send(command)
|
||||||
.expect("could not send command to display");
|
.expect("could not send command to display");
|
||||||
|
|
|
@ -106,6 +106,10 @@ mod tests {
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
fn test() {
|
fn test() {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
assert_ne!(rng.r#gen::<Brightness>(), rng.r#gen());
|
// two so test failure is less likely
|
||||||
|
assert_ne!(
|
||||||
|
[rng.r#gen::<Brightness>(), rng.r#gen()],
|
||||||
|
[rng.r#gen(), rng.r#gen()]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,16 @@ impl From<BitmapCommand> for TypedCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Bitmap> for BitmapCommand {
|
||||||
|
fn from(bitmap: Bitmap) -> Self {
|
||||||
|
Self {
|
||||||
|
bitmap,
|
||||||
|
origin: Origin::default(),
|
||||||
|
compression: CompressionCode::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BitmapCommand {
|
impl BitmapCommand {
|
||||||
fn packet_into_bitmap_win(
|
fn packet_into_bitmap_win(
|
||||||
packet: Packet,
|
packet: Packet,
|
||||||
|
|
|
@ -127,6 +127,17 @@ impl From<BitVecCommand> for TypedCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BitVec> for BitVecCommand {
|
||||||
|
fn from(bitvec: BitVec) -> Self {
|
||||||
|
Self {
|
||||||
|
bitvec,
|
||||||
|
operation: BinaryOperation::default(),
|
||||||
|
offset: Offset::default(),
|
||||||
|
compression: CompressionCode::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -25,6 +25,15 @@ impl TryFrom<BrightnessGridCommand> for Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BrightnessGrid> for BrightnessGridCommand {
|
||||||
|
fn from(grid: BrightnessGrid) -> Self {
|
||||||
|
Self {
|
||||||
|
grid,
|
||||||
|
origin: Origin::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<Packet> for BrightnessGridCommand {
|
impl TryFrom<Packet> for BrightnessGridCommand {
|
||||||
type Error = TryFromPacketError;
|
type Error = TryFromPacketError;
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,15 @@ impl From<CharGridCommand> for TypedCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<CharGrid> for CharGridCommand {
|
||||||
|
fn from(grid: CharGrid) -> Self {
|
||||||
|
Self {
|
||||||
|
grid,
|
||||||
|
origin: Origin::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::commands::tests::{round_trip, TestImplementsCommand};
|
use crate::commands::tests::{round_trip, TestImplementsCommand};
|
||||||
|
|
|
@ -90,6 +90,15 @@ impl From<Cp437GridCommand> for TypedCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Cp437Grid> for Cp437GridCommand {
|
||||||
|
fn from(grid: Cp437Grid) -> Self {
|
||||||
|
Self {
|
||||||
|
grid,
|
||||||
|
origin: Origin::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue