rename commands, add suffix and export on top level
This commit is contained in:
parent
9bff9bd346
commit
e3fc56c200
31 changed files with 230 additions and 234 deletions
11
README.md
11
README.md
|
|
@ -23,13 +23,12 @@ The [GitHub repository](https://github.com/cccb/servicepoint) remains available
|
|||
use servicepoint::*;
|
||||
|
||||
fn main() {
|
||||
// establish connection
|
||||
let connection = connections::Udp::open("172.23.42.29:2342")
|
||||
.expect("connection failed");
|
||||
// establish connection
|
||||
let connection = UdpConnection::open("172.23.42.29:2342")
|
||||
.expect("connection failed");
|
||||
|
||||
// clear screen content
|
||||
connection.send(commands::Clear)
|
||||
.expect("send failed");
|
||||
// clear screen content
|
||||
connection.send(ClearCommand).expect("send failed");
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@ fn main() {
|
|||
cli.text.push("Hello, CCCB!".to_string());
|
||||
}
|
||||
|
||||
let connection = connections::Udp::open(&cli.destination)
|
||||
let connection = UdpConnection::open(&cli.destination)
|
||||
.expect("could not connect to display");
|
||||
|
||||
if cli.clear {
|
||||
connection
|
||||
.send(commands::Clear)
|
||||
.send(ClearCommand)
|
||||
.expect("sending clear failed");
|
||||
}
|
||||
|
||||
let text = cli.text.join("\n");
|
||||
let command = commands::Utf8Data {
|
||||
let command = CharGridCommand {
|
||||
origin: Origin::ZERO,
|
||||
grid: CharGrid::wrap_str(TILE_WIDTH, &text),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ struct Cli {
|
|||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let connection = connections::Udp::open(cli.destination)
|
||||
let connection = UdpConnection::open(cli.destination)
|
||||
.expect("could not connect to display");
|
||||
|
||||
let mut bitmap = Bitmap::max_sized();
|
||||
bitmap.fill(true);
|
||||
|
||||
let command = commands::BitmapLinearWin {
|
||||
let command = BitmapCommand {
|
||||
origin: Origin::ZERO,
|
||||
bitmap,
|
||||
compression: CompressionCode::default(),
|
||||
|
|
@ -31,7 +31,7 @@ fn main() {
|
|||
*byte = Brightness::try_from(level).unwrap();
|
||||
}
|
||||
|
||||
let command = commands::CharBrightness {
|
||||
let command = BrightnessGridCommand {
|
||||
origin: Origin::ZERO,
|
||||
grid: brightnesses,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ struct Cli {
|
|||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let connection = connections::Udp::open(&cli.destination)
|
||||
let connection = UdpConnection::open(&cli.destination)
|
||||
.expect("could not connect to display");
|
||||
let mut field = make_random_field(cli.probability);
|
||||
|
||||
loop {
|
||||
let command = commands::BitmapLinearWin {
|
||||
let command = BitmapCommand {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: field.clone(),
|
||||
compression: CompressionCode::default(),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ struct Cli {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let connection = connections::Udp::open(Cli::parse().destination)
|
||||
let connection = UdpConnection::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 = commands::BitmapLinearWin {
|
||||
let command = BitmapCommand {
|
||||
bitmap: bitmap.clone(),
|
||||
compression: CompressionCode::default(),
|
||||
origin: Origin::ZERO,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ struct Cli {
|
|||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let connection = connections::Udp::open(cli.destination)
|
||||
let connection = UdpConnection::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 = commands::BitmapLinearWin {
|
||||
let command = BitmapCommand {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: filled_grid,
|
||||
compression: CompressionCode::default(),
|
||||
|
|
@ -59,7 +59,7 @@ fn main() {
|
|||
}
|
||||
|
||||
connection
|
||||
.send(commands::CharBrightness { origin, grid: luma })
|
||||
.send(BrightnessGridCommand { origin, grid: luma })
|
||||
.unwrap();
|
||||
std::thread::sleep(wait_duration);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
//! Example for how to use the WebSocket connection
|
||||
|
||||
use servicepoint::connections::Websocket;
|
||||
use servicepoint::*;
|
||||
|
||||
fn main() {
|
||||
let uri = "ws://localhost:8080".parse().unwrap();
|
||||
let connection = Websocket::open(uri).unwrap();
|
||||
let connection = WebsocketConnection::open(uri).unwrap();
|
||||
|
||||
connection.send(commands::Clear).unwrap();
|
||||
connection.send(ClearCommand).unwrap();
|
||||
|
||||
let mut pixels = Bitmap::max_sized();
|
||||
pixels.fill(true);
|
||||
|
||||
let command = commands::BitmapLinearWin {
|
||||
let command = BitmapCommand {
|
||||
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 = connections::Udp::open(cli.destination)
|
||||
let connection = UdpConnection::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 = commands::BitmapLinearWin {
|
||||
let command = BitmapCommand {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: enabled_pixels.clone(),
|
||||
compression: CompressionCode::default(),
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ use rand::{
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use servicepoint::{Brightness, Command, Connection, connections};
|
||||
/// # use servicepoint::*;
|
||||
/// let b = Brightness::MAX;
|
||||
/// let val: u8 = b.into();
|
||||
///
|
||||
/// let b = Brightness::try_from(7).unwrap();
|
||||
/// # let connection = connections::Fake;
|
||||
/// # let connection = FakeConnection;
|
||||
/// let result = connection.send(b);
|
||||
/// ```
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ use crate::ByteGrid;
|
|||
/// grid.set(0, 0, Brightness::MIN);
|
||||
/// grid.set(1, 1, Brightness::MIN);
|
||||
///
|
||||
/// # let connection = connections::Fake;
|
||||
/// connection.send(commands::CharBrightness {
|
||||
/// # let connection = FakeConnection;
|
||||
/// connection.send(BrightnessGridCommand {
|
||||
/// 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 = connections::Fake;
|
||||
/// let command = commands::Utf8Data { origin: Origin::ZERO, grid };
|
||||
/// # let connection = FakeConnection;
|
||||
/// let command = CharGridCommand { origin: Origin::ZERO, grid };
|
||||
/// connection.send(command).unwrap()
|
||||
/// ```
|
||||
pub type CharGrid = ValueGrid<char>;
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ use crate::{
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// # let connection = FakeConnection;
|
||||
/// #
|
||||
/// 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 {
|
||||
/// let command = BitmapCommand {
|
||||
/// bitmap,
|
||||
/// origin: Origin::ZERO,
|
||||
/// compression: CompressionCode::Uncompressed
|
||||
|
|
@ -29,7 +29,7 @@ use crate::{
|
|||
/// connection.send(command).expect("send failed");
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct BitmapLinearWin {
|
||||
pub struct BitmapCommand {
|
||||
/// where to start drawing the pixels
|
||||
pub origin: Origin<Pixels>,
|
||||
/// the pixels to send
|
||||
|
|
@ -38,8 +38,8 @@ pub struct BitmapLinearWin {
|
|||
pub compression: CompressionCode,
|
||||
}
|
||||
|
||||
impl From<BitmapLinearWin> for Packet {
|
||||
fn from(value: BitmapLinearWin) -> Self {
|
||||
impl From<BitmapCommand> for Packet {
|
||||
fn from(value: BitmapCommand) -> Self {
|
||||
assert_eq!(value.origin.x % 8, 0);
|
||||
assert_eq!(value.bitmap.width() % 8, 0);
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ impl From<BitmapLinearWin> for Packet {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BitmapLinearWin {
|
||||
impl TryFrom<Packet> for BitmapCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -113,13 +113,13 @@ impl TryFrom<Packet> for BitmapLinearWin {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinearWin> for TypedCommand {
|
||||
fn from(command: BitmapLinearWin) -> Self {
|
||||
Self::BitmapLinearWin(command)
|
||||
impl From<BitmapCommand> for TypedCommand {
|
||||
fn from(command: BitmapCommand) -> Self {
|
||||
Self::Bitmap(command)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitmapLinearWin {
|
||||
impl BitmapCommand {
|
||||
fn packet_into_bitmap_win(
|
||||
packet: Packet,
|
||||
compression: CompressionCode,
|
||||
|
|
@ -12,17 +12,17 @@ use std::fmt::Debug;
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// # let connection = FakeConnection;
|
||||
/// // this sends a packet that does nothing
|
||||
/// # #[allow(deprecated)]
|
||||
/// connection.send(commands::BitmapLegacy).unwrap();
|
||||
/// connection.send(BitmapLegacyCommand).unwrap();
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[deprecated]
|
||||
pub struct BitmapLegacy;
|
||||
pub struct BitmapLegacyCommand;
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl TryFrom<Packet> for BitmapLegacy {
|
||||
impl TryFrom<Packet> for BitmapLegacyCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(value: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -37,15 +37,15 @@ impl TryFrom<Packet> for BitmapLegacy {
|
|||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl From<BitmapLegacy> for Packet {
|
||||
fn from(_: BitmapLegacy) -> Self {
|
||||
impl From<BitmapLegacyCommand> for Packet {
|
||||
fn from(_: BitmapLegacyCommand) -> Self {
|
||||
Packet::command_code_only(CommandCode::BitmapLegacy)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl From<BitmapLegacy> for TypedCommand {
|
||||
fn from(command: BitmapLegacy) -> Self {
|
||||
impl From<BitmapLegacyCommand> for TypedCommand {
|
||||
fn from(command: BitmapLegacyCommand) -> Self {
|
||||
Self::BitmapLegacy(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
Packet, TypedCommand,
|
||||
};
|
||||
|
||||
/// Binary operations for use with the [BitmapLinear] command.
|
||||
/// Binary operations for use with the [BitVecCommand] command.
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Default)]
|
||||
pub enum BinaryOperation {
|
||||
#[default]
|
||||
|
|
@ -28,7 +28,7 @@ pub enum BinaryOperation {
|
|||
///
|
||||
/// The contained [BitVec] is always uncompressed.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct BitmapLinear {
|
||||
pub struct BitVecCommand {
|
||||
/// where to start overwriting pixel data
|
||||
pub offset: Offset,
|
||||
/// the pixels to send to the display as one long row
|
||||
|
|
@ -39,8 +39,8 @@ pub struct BitmapLinear {
|
|||
pub compression: CompressionCode,
|
||||
}
|
||||
|
||||
impl From<BitmapLinear> for Packet {
|
||||
fn from(command: BitmapLinear) -> Self {
|
||||
impl From<BitVecCommand> for Packet {
|
||||
fn from(command: BitVecCommand) -> Self {
|
||||
let command_code = match command.operation {
|
||||
BinaryOperation::Overwrite => CommandCode::BitmapLinear,
|
||||
BinaryOperation::And => CommandCode::BitmapLinearAnd,
|
||||
|
|
@ -64,7 +64,7 @@ impl From<BitmapLinear> for Packet {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for BitmapLinear {
|
||||
impl TryFrom<Packet> for BitVecCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -122,8 +122,8 @@ impl TryFrom<Packet> for BitmapLinear {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BitmapLinear> for TypedCommand {
|
||||
fn from(command: BitmapLinear) -> Self {
|
||||
Self::BitmapLinear(command)
|
||||
impl From<BitVecCommand> for TypedCommand {
|
||||
fn from(command: BitVecCommand) -> Self {
|
||||
Self::BitVec(command)
|
||||
}
|
||||
}
|
||||
|
|
@ -5,15 +5,15 @@ use crate::{
|
|||
|
||||
/// Set the brightness of individual tiles in a rectangular area of the display.
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct CharBrightness {
|
||||
pub struct BrightnessGridCommand {
|
||||
/// 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 {
|
||||
impl From<BrightnessGridCommand> for Packet {
|
||||
fn from(value: BrightnessGridCommand) -> Self {
|
||||
Packet::origin_grid_to_packet(
|
||||
value.origin,
|
||||
value.grid,
|
||||
|
|
@ -22,7 +22,7 @@ impl From<CharBrightness> for Packet {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for CharBrightness {
|
||||
impl TryFrom<Packet> for BrightnessGridCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -51,8 +51,8 @@ impl TryFrom<Packet> for CharBrightness {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<CharBrightness> for TypedCommand {
|
||||
fn from(command: CharBrightness) -> Self {
|
||||
Self::CharBrightness(command)
|
||||
impl From<BrightnessGridCommand> for TypedCommand {
|
||||
fn from(command: BrightnessGridCommand) -> Self {
|
||||
Self::BrightnessGrid(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ use std::fmt::Debug;
|
|||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{connections, Command, Connection, commands};
|
||||
/// # let connection = connections::Fake;
|
||||
/// connection.send(commands::Clear).unwrap();
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = FakeConnection;
|
||||
/// connection.send(ClearCommand).unwrap();
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
/// ```
|
||||
pub struct Clear;
|
||||
pub struct ClearCommand;
|
||||
|
||||
impl TryFrom<Packet> for Clear {
|
||||
impl TryFrom<Packet> for ClearCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(value: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -28,14 +28,14 @@ impl TryFrom<Packet> for Clear {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Clear> for Packet {
|
||||
fn from(_: Clear) -> Self {
|
||||
impl From<ClearCommand> for Packet {
|
||||
fn from(_: ClearCommand) -> Self {
|
||||
Packet::command_code_only(CommandCode::Clear)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Clear> for TypedCommand {
|
||||
fn from(command: Clear) -> Self {
|
||||
impl From<ClearCommand> for TypedCommand {
|
||||
fn from(command: ClearCommand) -> Self {
|
||||
Self::Clear(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,29 +13,29 @@ use crate::{
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// # let connection = FakeConnection;
|
||||
/// let grid = CharGrid::from("Hello,\nWorld!");
|
||||
/// let grid = Cp437Grid::from(&grid);
|
||||
/// connection.send(commands::Cp437Data{ origin: Origin::ZERO, grid }).expect("send failed");
|
||||
/// connection.send(Cp437GridCommand{ origin: Origin::ZERO, grid }).expect("send failed");
|
||||
/// ```
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// # let connection = FakeConnection;
|
||||
/// let grid = Cp437Grid::load_ascii("Hello\nWorld", 5, false).unwrap();
|
||||
/// connection.send(commands::Cp437Data{ origin: Origin::new(2, 2), grid }).unwrap();
|
||||
/// connection.send(Cp437GridCommand{ origin: Origin::new(2, 2), grid }).unwrap();
|
||||
/// ```
|
||||
/// [CP-437]: https://en.wikipedia.org/wiki/Code_page_437
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Cp437Data {
|
||||
pub struct Cp437GridCommand {
|
||||
/// 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 {
|
||||
impl From<Cp437GridCommand> for Packet {
|
||||
fn from(value: Cp437GridCommand) -> Self {
|
||||
Packet::origin_grid_to_packet(
|
||||
value.origin,
|
||||
value.grid,
|
||||
|
|
@ -44,7 +44,7 @@ impl From<Cp437Data> for Packet {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for Cp437Data {
|
||||
impl TryFrom<Packet> for Cp437GridCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -66,8 +66,8 @@ impl TryFrom<Packet> for Cp437Data {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Cp437Data> for TypedCommand {
|
||||
fn from(command: Cp437Data) -> Self {
|
||||
Self::Cp437Data(command)
|
||||
impl From<Cp437GridCommand> for TypedCommand {
|
||||
fn from(command: Cp437GridCommand) -> Self {
|
||||
Self::Cp437Grid(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ use std::fmt::Debug;
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// connection.send(commands::FadeOut).unwrap();
|
||||
/// # let connection = FakeConnection;
|
||||
/// connection.send(FadeOutCommand).unwrap();
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
/// ```
|
||||
pub struct FadeOut;
|
||||
pub struct FadeOutCommand;
|
||||
|
||||
impl TryFrom<Packet> for FadeOut {
|
||||
impl TryFrom<Packet> for FadeOutCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(value: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -31,14 +31,14 @@ impl TryFrom<Packet> for FadeOut {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<FadeOut> for Packet {
|
||||
fn from(_: FadeOut) -> Self {
|
||||
impl From<FadeOutCommand> for Packet {
|
||||
fn from(_: FadeOutCommand) -> Self {
|
||||
Packet::command_code_only(CommandCode::FadeOut)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FadeOut> for TypedCommand {
|
||||
fn from(command: FadeOut) -> Self {
|
||||
impl From<FadeOutCommand> for TypedCommand {
|
||||
fn from(command: FadeOutCommand) -> Self {
|
||||
Self::FadeOut(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,18 +9,18 @@ use crate::{
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// let command = commands::GlobalBrightness { brightness: Brightness::MAX };
|
||||
/// # let connection = FakeConnection;
|
||||
/// let command = BrightnessCommand { brightness: Brightness::MAX };
|
||||
/// connection.send(command).unwrap();
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct GlobalBrightness {
|
||||
pub struct BrightnessCommand {
|
||||
/// the brightness to set all pixels to
|
||||
pub brightness: Brightness,
|
||||
}
|
||||
|
||||
impl From<GlobalBrightness> for Packet {
|
||||
fn from(command: GlobalBrightness) -> Self {
|
||||
impl From<BrightnessCommand> for Packet {
|
||||
fn from(command: BrightnessCommand) -> Self {
|
||||
Self {
|
||||
header: Header {
|
||||
command_code: CommandCode::Brightness.into(),
|
||||
|
|
@ -34,7 +34,7 @@ impl From<GlobalBrightness> for Packet {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for GlobalBrightness {
|
||||
impl TryFrom<Packet> for BrightnessCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -67,14 +67,14 @@ impl TryFrom<Packet> for GlobalBrightness {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<GlobalBrightness> for TypedCommand {
|
||||
fn from(command: GlobalBrightness) -> Self {
|
||||
Self::GlobalBrightness(command)
|
||||
impl From<BrightnessCommand> for TypedCommand {
|
||||
fn from(command: BrightnessCommand) -> Self {
|
||||
Self::Brightness(command)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Brightness> for Packet {
|
||||
fn from(brightness: Brightness) -> Self {
|
||||
Packet::from(GlobalBrightness { brightness })
|
||||
Packet::from(BrightnessCommand { brightness })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ use std::fmt::Debug;
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// connection.send(commands::HardReset).unwrap();
|
||||
/// # let connection = FakeConnection;
|
||||
/// connection.send(HardResetCommand).unwrap();
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
/// ```
|
||||
pub struct HardReset;
|
||||
pub struct HardResetCommand;
|
||||
|
||||
impl TryFrom<Packet> for HardReset {
|
||||
impl TryFrom<Packet> for HardResetCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(value: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -32,14 +32,14 @@ impl TryFrom<Packet> for HardReset {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<HardReset> for Packet {
|
||||
fn from(_: HardReset) -> Self {
|
||||
impl From<HardResetCommand> for Packet {
|
||||
fn from(_: HardResetCommand) -> Self {
|
||||
Packet::command_code_only(CommandCode::HardReset)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HardReset> for TypedCommand {
|
||||
fn from(command: HardReset) -> Self {
|
||||
impl From<HardResetCommand> for TypedCommand {
|
||||
fn from(command: HardResetCommand) -> Self {
|
||||
Self::HardReset(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
//!
|
||||
//! # Available commands
|
||||
//!
|
||||
//! To send text, take a look at [Cp437Data].
|
||||
//! To send text, take a look at [Cp437GridCommand].
|
||||
//!
|
||||
//! To draw pixels, the easiest command to use is [BitmapLinearWin].
|
||||
//! To draw pixels, the easiest command to use is [BitmapCommand].
|
||||
//!
|
||||
//! The other BitmapLinear-Commands operate on a region of pixel memory directly.
|
||||
//! [BitmapLinear] overwrites a region.
|
||||
//! [BitVecCommand] overwrites a region.
|
||||
//! [BitmapLinearOr], [BitmapLinearAnd] and [BitmapLinearXor] apply logical operations per pixel.
|
||||
//!
|
||||
//! Out of bounds operations may be truncated or ignored by the display.
|
||||
|
|
@ -31,25 +31,25 @@
|
|||
//! use servicepoint::*;
|
||||
//!
|
||||
//! // create command
|
||||
//! let command = commands::GlobalBrightness{ brightness: Brightness::MAX };
|
||||
//! let command = BrightnessCommand{ brightness: Brightness::MAX };
|
||||
//!
|
||||
//! // turn command into Packet
|
||||
//! let packet: Packet = command.clone().into();
|
||||
//!
|
||||
//! // read command from packet
|
||||
//! let round_tripped = commands::TypedCommand::try_from(packet).unwrap();
|
||||
//! let round_tripped = TypedCommand::try_from(packet).unwrap();
|
||||
//!
|
||||
//! // round tripping produces exact copy
|
||||
//! assert_eq!(round_tripped, TypedCommand::from(command.clone()));
|
||||
//!
|
||||
//! // send command
|
||||
//! # let connection = connections::Fake;
|
||||
//! # let connection = FakeConnection;
|
||||
//! connection.send(command).unwrap();
|
||||
//! ```
|
||||
|
||||
mod bitmap;
|
||||
mod bitmap_legacy;
|
||||
mod bitmap_linear;
|
||||
mod bitmap_linear_win;
|
||||
mod bitvec;
|
||||
mod char_brightness;
|
||||
mod clear;
|
||||
mod cp437_data;
|
||||
|
|
@ -62,9 +62,9 @@ use crate::command_code::CommandCode;
|
|||
use crate::*;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub use bitmap::*;
|
||||
pub use bitmap_legacy::*;
|
||||
pub use bitmap_linear::*;
|
||||
pub use bitmap_linear_win::*;
|
||||
pub use bitvec::*;
|
||||
pub use char_brightness::*;
|
||||
pub use clear::*;
|
||||
pub use cp437_data::*;
|
||||
|
|
@ -85,27 +85,27 @@ impl<T: Debug + Clone + PartialEq + Into<Packet>> Command for T {}
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum TypedCommand {
|
||||
Clear(Clear),
|
||||
Clear(ClearCommand),
|
||||
|
||||
Utf8Data(Utf8Data),
|
||||
CharGrid(CharGridCommand),
|
||||
|
||||
Cp437Data(Cp437Data),
|
||||
Cp437Grid(Cp437GridCommand),
|
||||
|
||||
BitmapLinearWin(BitmapLinearWin),
|
||||
Bitmap(BitmapCommand),
|
||||
|
||||
GlobalBrightness(GlobalBrightness),
|
||||
Brightness(BrightnessCommand),
|
||||
|
||||
CharBrightness(CharBrightness),
|
||||
BrightnessGrid(BrightnessGridCommand),
|
||||
|
||||
BitmapLinear(BitmapLinear),
|
||||
BitVec(BitVecCommand),
|
||||
|
||||
HardReset(HardReset),
|
||||
HardReset(HardResetCommand),
|
||||
|
||||
FadeOut(FadeOut),
|
||||
FadeOut(FadeOutCommand),
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[deprecated]
|
||||
BitmapLegacy(BitmapLegacy),
|
||||
BitmapLegacy(BitmapLegacyCommand),
|
||||
}
|
||||
|
||||
/// Err values for [Command::try_from].
|
||||
|
|
@ -138,7 +138,7 @@ pub enum TryFromPacketError {
|
|||
|
||||
macro_rules! packet_to_command_case {
|
||||
($T:tt, $packet:ident) => {
|
||||
TypedCommand::$T($T::try_from($packet)?)
|
||||
paste! {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -159,53 +159,55 @@ impl TryFrom<Packet> for TypedCommand {
|
|||
};
|
||||
|
||||
Ok(match command_code {
|
||||
CommandCode::Clear => packet_to_command_case!(Clear, packet),
|
||||
CommandCode::Brightness => {
|
||||
packet_to_command_case!(GlobalBrightness, packet)
|
||||
CommandCode::Clear => {
|
||||
TypedCommand::Clear(commands::ClearCommand::try_from(packet)?)
|
||||
}
|
||||
CommandCode::Brightness => TypedCommand::Brightness(
|
||||
commands::BrightnessCommand::try_from(packet)?,
|
||||
),
|
||||
CommandCode::HardReset => {
|
||||
packet_to_command_case!(HardReset, packet)
|
||||
TypedCommand::HardReset(commands::HardResetCommand::try_from(packet)?)
|
||||
}
|
||||
CommandCode::FadeOut => {
|
||||
packet_to_command_case!(FadeOut, packet)
|
||||
TypedCommand::FadeOut(commands::FadeOutCommand::try_from(packet)?)
|
||||
}
|
||||
CommandCode::Cp437Data => {
|
||||
packet_to_command_case!(Cp437Data, packet)
|
||||
TypedCommand::Cp437Grid(commands::Cp437GridCommand::try_from(packet)?)
|
||||
}
|
||||
CommandCode::CharBrightness => {
|
||||
packet_to_command_case!(CharBrightness, packet)
|
||||
TypedCommand::BrightnessGrid(commands::BrightnessGridCommand::try_from(packet)?)
|
||||
}
|
||||
CommandCode::Utf8Data => {
|
||||
packet_to_command_case!(Utf8Data, packet)
|
||||
TypedCommand::CharGrid(commands::CharGridCommand::try_from(packet)?)
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
CommandCode::BitmapLegacy => {
|
||||
packet_to_command_case!(BitmapLegacy, packet)
|
||||
TypedCommand::BitmapLegacy(commands::BitmapLegacyCommand::try_from(packet)?)
|
||||
}
|
||||
CommandCode::BitmapLinear
|
||||
| CommandCode::BitmapLinearOr
|
||||
| CommandCode::BitmapLinearAnd
|
||||
| CommandCode::BitmapLinearXor => {
|
||||
packet_to_command_case!(BitmapLinear, packet)
|
||||
TypedCommand::BitVec(commands::BitVecCommand::try_from(packet)?)
|
||||
}
|
||||
CommandCode::BitmapLinearWinUncompressed => {
|
||||
packet_to_command_case!(BitmapLinearWin, packet)
|
||||
TypedCommand::Bitmap(commands::BitmapCommand::try_from(packet)?)
|
||||
}
|
||||
#[cfg(feature = "compression_zlib")]
|
||||
CommandCode::BitmapLinearWinZlib => {
|
||||
packet_to_command_case!(BitmapLinearWin, packet)
|
||||
TypedCommand::Bitmap(commands::BitmapCommand::try_from(packet)?)
|
||||
}
|
||||
#[cfg(feature = "compression_bzip2")]
|
||||
CommandCode::BitmapLinearWinBzip2 => {
|
||||
packet_to_command_case!(BitmapLinearWin, packet)
|
||||
TypedCommand::Bitmap(commands::BitmapCommand::try_from(packet)?)
|
||||
}
|
||||
#[cfg(feature = "compression_lzma")]
|
||||
CommandCode::BitmapLinearWinLzma => {
|
||||
packet_to_command_case!(BitmapLinearWin, packet)
|
||||
TypedCommand::Bitmap(commands::BitmapCommand::try_from(packet)?)
|
||||
}
|
||||
#[cfg(feature = "compression_zstd")]
|
||||
CommandCode::BitmapLinearWinZstd => {
|
||||
packet_to_command_case!(BitmapLinearWin, packet)
|
||||
TypedCommand::Bitmap(commands::BitmapCommand::try_from(packet)?)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -215,12 +217,12 @@ impl From<TypedCommand> for Packet {
|
|||
fn from(command: TypedCommand) -> Self {
|
||||
match command {
|
||||
TypedCommand::Clear(c) => c.into(),
|
||||
TypedCommand::Utf8Data(c) => c.into(),
|
||||
TypedCommand::Cp437Data(c) => c.into(),
|
||||
TypedCommand::BitmapLinearWin(c) => c.into(),
|
||||
TypedCommand::GlobalBrightness(c) => c.into(),
|
||||
TypedCommand::CharBrightness(c) => c.into(),
|
||||
TypedCommand::BitmapLinear(c) => c.into(),
|
||||
TypedCommand::CharGrid(c) => c.into(),
|
||||
TypedCommand::Cp437Grid(c) => c.into(),
|
||||
TypedCommand::Bitmap(c) => c.into(),
|
||||
TypedCommand::Brightness(c) => c.into(),
|
||||
TypedCommand::BrightnessGrid(c) => c.into(),
|
||||
TypedCommand::BitVec(c) => c.into(),
|
||||
TypedCommand::HardReset(c) => c.into(),
|
||||
TypedCommand::FadeOut(c) => c.into(),
|
||||
#[allow(deprecated)]
|
||||
|
|
@ -288,45 +290,45 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn round_trip_clear() {
|
||||
round_trip(TypedCommand::Clear(commands::Clear));
|
||||
round_trip(TypedCommand::Clear(commands::ClearCommand));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_hard_reset() {
|
||||
round_trip(TypedCommand::HardReset(commands::HardReset));
|
||||
round_trip(TypedCommand::HardReset(commands::HardResetCommand));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_fade_out() {
|
||||
round_trip(TypedCommand::FadeOut(commands::FadeOut));
|
||||
round_trip(TypedCommand::FadeOut(commands::FadeOutCommand));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_brightness() {
|
||||
round_trip(TypedCommand::GlobalBrightness(
|
||||
commands::GlobalBrightness {
|
||||
brightness: Brightness::try_from(6).unwrap(),
|
||||
},
|
||||
));
|
||||
round_trip(TypedCommand::Brightness(commands::BrightnessCommand {
|
||||
brightness: Brightness::try_from(6).unwrap(),
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn round_trip_bitmap_legacy() {
|
||||
round_trip(TypedCommand::BitmapLegacy(commands::BitmapLegacy));
|
||||
round_trip(TypedCommand::BitmapLegacy(commands::BitmapLegacyCommand));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_char_brightness() {
|
||||
round_trip(TypedCommand::CharBrightness(commands::CharBrightness {
|
||||
origin: Origin::new(5, 2),
|
||||
grid: BrightnessGrid::new(7, 5),
|
||||
}));
|
||||
round_trip(TypedCommand::BrightnessGrid(
|
||||
commands::BrightnessGridCommand {
|
||||
origin: Origin::new(5, 2),
|
||||
grid: BrightnessGrid::new(7, 5),
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trip_cp437_data() {
|
||||
round_trip(TypedCommand::Cp437Data(commands::Cp437Data {
|
||||
round_trip(TypedCommand::Cp437Grid(commands::Cp437GridCommand {
|
||||
origin: Origin::new(5, 2),
|
||||
grid: Cp437Grid::new(7, 5),
|
||||
}));
|
||||
|
|
@ -334,7 +336,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn round_trip_utf8_data() {
|
||||
round_trip(TypedCommand::Utf8Data(commands::Utf8Data {
|
||||
round_trip(TypedCommand::CharGrid(commands::CharGridCommand {
|
||||
origin: Origin::new(5, 2),
|
||||
grid: CharGrid::new(7, 5),
|
||||
}));
|
||||
|
|
@ -349,22 +351,18 @@ mod tests {
|
|||
BinaryOperation::Or,
|
||||
BinaryOperation::Xor,
|
||||
] {
|
||||
round_trip(TypedCommand::BitmapLinear(
|
||||
commands::BitmapLinear {
|
||||
offset: 23,
|
||||
bitvec: BitVec::repeat(false, 40),
|
||||
compression,
|
||||
operation,
|
||||
},
|
||||
));
|
||||
}
|
||||
round_trip(TypedCommand::BitmapLinearWin(
|
||||
commands::BitmapLinearWin {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: Bitmap::max_sized(),
|
||||
round_trip(TypedCommand::BitVec(commands::BitVecCommand {
|
||||
offset: 23,
|
||||
bitvec: BitVec::repeat(false, 40),
|
||||
compression,
|
||||
},
|
||||
));
|
||||
operation,
|
||||
}));
|
||||
}
|
||||
round_trip(TypedCommand::Bitmap(commands::BitmapCommand {
|
||||
origin: Origin::ZERO,
|
||||
bitmap: Bitmap::max_sized(),
|
||||
compression,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -485,7 +483,7 @@ mod tests {
|
|||
#[test]
|
||||
fn error_decompression_failed_win() {
|
||||
for compression in all_compressions().iter().copied() {
|
||||
let p: Packet = commands::BitmapLinearWin {
|
||||
let p: Packet = commands::BitmapCommand {
|
||||
origin: Origin::new(16, 8),
|
||||
bitmap: Bitmap::new(8, 8).unwrap(),
|
||||
compression,
|
||||
|
|
@ -515,7 +513,7 @@ mod tests {
|
|||
#[test]
|
||||
fn error_decompression_failed_and() {
|
||||
for compression in all_compressions().iter().copied() {
|
||||
let p: Packet = commands::BitmapLinear {
|
||||
let p: Packet = commands::BitVecCommand {
|
||||
offset: 0,
|
||||
bitvec: BitVec::repeat(false, 8),
|
||||
compression,
|
||||
|
|
@ -576,7 +574,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn error_reserved_used() {
|
||||
let Packet { header, payload } = commands::BitmapLinear {
|
||||
let Packet { header, payload } = commands::BitVecCommand {
|
||||
offset: 0,
|
||||
bitvec: BitVec::repeat(false, 8),
|
||||
compression: CompressionCode::Uncompressed,
|
||||
|
|
@ -608,7 +606,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn error_invalid_compression() {
|
||||
let Packet { header, payload } = commands::BitmapLinear {
|
||||
let Packet { header, payload } = commands::BitVecCommand {
|
||||
offset: 0,
|
||||
bitvec: BitVec::repeat(false, 8),
|
||||
compression: CompressionCode::Uncompressed,
|
||||
|
|
@ -640,7 +638,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn error_unexpected_size() {
|
||||
let Packet { header, payload } = commands::BitmapLinear {
|
||||
let Packet { header, payload } = commands::BitVecCommand {
|
||||
offset: 0,
|
||||
bitvec: BitVec::repeat(false, 8),
|
||||
compression: CompressionCode::Uncompressed,
|
||||
|
|
@ -684,7 +682,7 @@ mod tests {
|
|||
#[test]
|
||||
fn packet_into_char_brightness_invalid() {
|
||||
let grid = BrightnessGrid::new(2, 2);
|
||||
let command = commands::CharBrightness {
|
||||
let command = commands::BrightnessGridCommand {
|
||||
origin: Origin::ZERO,
|
||||
grid,
|
||||
};
|
||||
|
|
@ -699,7 +697,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn packet_into_brightness_invalid() {
|
||||
let mut packet: Packet = commands::GlobalBrightness {
|
||||
let mut packet: Packet = commands::BrightnessCommand {
|
||||
brightness: Brightness::MAX,
|
||||
}
|
||||
.into();
|
||||
|
|
|
|||
|
|
@ -11,20 +11,20 @@ use crate::{
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// # let connection = FakeConnection;
|
||||
/// let grid = CharGrid::from("Hello,\nWorld!");
|
||||
/// connection.send(commands::Utf8Data { origin: Origin::ZERO, grid }).expect("send failed");
|
||||
/// connection.send(CharGridCommand { origin: Origin::ZERO, grid }).expect("send failed");
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Utf8Data {
|
||||
pub struct CharGridCommand {
|
||||
/// which tile the text should start
|
||||
pub origin: Origin<Tiles>,
|
||||
/// the text to send to the display
|
||||
pub grid: CharGrid,
|
||||
}
|
||||
|
||||
impl From<Utf8Data> for Packet {
|
||||
fn from(value: Utf8Data) -> Self {
|
||||
impl From<CharGridCommand> for Packet {
|
||||
fn from(value: CharGridCommand) -> Self {
|
||||
Packet::origin_grid_to_packet(
|
||||
value.origin,
|
||||
value.grid,
|
||||
|
|
@ -33,7 +33,7 @@ impl From<Utf8Data> for Packet {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Packet> for Utf8Data {
|
||||
impl TryFrom<Packet> for CharGridCommand {
|
||||
type Error = TryFromPacketError;
|
||||
|
||||
fn try_from(packet: Packet) -> Result<Self, Self::Error> {
|
||||
|
|
@ -57,8 +57,8 @@ impl TryFrom<Packet> for Utf8Data {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Utf8Data> for TypedCommand {
|
||||
fn from(command: Utf8Data) -> Self {
|
||||
Self::Utf8Data(command)
|
||||
impl From<CharGridCommand> for TypedCommand {
|
||||
fn from(command: CharGridCommand) -> Self {
|
||||
Self::CharGrid(command)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/// # use servicepoint::*;
|
||||
/// // create command without payload compression
|
||||
/// # let pixels = Bitmap::max_sized();
|
||||
/// _ = commands::BitmapLinearWin {
|
||||
/// _ = BitmapCommand {
|
||||
/// origin: Origin::ZERO,
|
||||
/// bitmap: pixels,
|
||||
/// compression: CompressionCode::Uncompressed
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
///
|
||||
/// // create command with payload compressed with lzma and appropriate header flags
|
||||
/// # let pixels = Bitmap::max_sized();
|
||||
/// _ = commands::BitmapLinearWin {
|
||||
/// _ = BitmapCommand {
|
||||
/// origin: Origin::ZERO,
|
||||
/// bitmap: pixels,
|
||||
/// compression: CompressionCode::Lzma
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ use log::debug;
|
|||
|
||||
#[derive(Debug)]
|
||||
/// A fake connection for testing that does not actually send anything.
|
||||
pub struct Fake;
|
||||
pub struct FakeConnection;
|
||||
|
||||
impl Connection for Fake {
|
||||
impl Connection for FakeConnection {
|
||||
// TODO: () does not implement Error+Debug, some placeholder is needed
|
||||
type Error = std::io::Error;
|
||||
|
||||
|
|
@ -25,6 +25,6 @@ mod tests {
|
|||
fn send_fake() {
|
||||
let data: &[u8] = &[0u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
let packet = Packet::try_from(data).unwrap();
|
||||
Fake.send(packet).unwrap()
|
||||
FakeConnection.send(packet).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ pub use websocket::*;
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// use servicepoint::{commands, connections, Connection};
|
||||
/// let connection = connections::Udp::open("127.0.0.1:2342")
|
||||
/// use servicepoint::{ClearCommand, Connection, UdpConnection};
|
||||
/// let connection = UdpConnection::open("127.0.0.1:2342")
|
||||
/// .expect("connection failed");
|
||||
/// connection.send(commands::Clear)
|
||||
/// connection.send(ClearCommand)
|
||||
/// .expect("send failed");
|
||||
/// ```
|
||||
pub trait Connection: Debug {
|
||||
|
|
@ -43,10 +43,10 @@ pub trait Connection: Debug {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::connections::Connection;
|
||||
/// let connection = servicepoint::connections::Fake;
|
||||
/// # use servicepoint::Connection;
|
||||
/// let connection = servicepoint::FakeConnection;
|
||||
/// // turn off all pixels on display
|
||||
/// connection.send(servicepoint::commands::Clear)
|
||||
/// connection.send(servicepoint::ClearCommand)
|
||||
/// .expect("send failed");
|
||||
/// ```
|
||||
fn send(&self, packet: impl Into<Packet>) -> Result<(), Self::Error>;
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ use std::net::UdpSocket;
|
|||
///
|
||||
/// Requires the feature "protocol_udp" which is enabled by default.
|
||||
#[derive(Debug)]
|
||||
pub struct Udp {
|
||||
pub struct UdpConnection {
|
||||
socket: UdpSocket,
|
||||
}
|
||||
|
||||
impl Udp {
|
||||
impl UdpConnection {
|
||||
/// Open a new UDP socket and connect to the provided host.
|
||||
///
|
||||
/// Note that this is UDP, which means that the open call can succeed even if the display is unreachable.
|
||||
|
|
@ -25,7 +25,7 @@ impl Udp {
|
|||
///
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// let connection = servicepoint::connections::Udp::open("127.0.0.1:2342")
|
||||
/// let connection = servicepoint::UdpConnection::open("127.0.0.1:2342")
|
||||
/// .expect("connection failed");
|
||||
/// ```
|
||||
pub fn open(
|
||||
|
|
@ -38,7 +38,7 @@ impl Udp {
|
|||
}
|
||||
}
|
||||
|
||||
impl Connection for Udp {
|
||||
impl Connection for UdpConnection {
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn send(&self, packet: impl Into<Packet>) -> Result<(), Self::Error> {
|
||||
|
|
@ -47,7 +47,7 @@ impl Connection for Udp {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<UdpSocket> for Udp {
|
||||
impl From<UdpSocket> for UdpConnection {
|
||||
fn from(socket: UdpSocket) -> Self {
|
||||
Self { socket }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::{Connection, Packet};
|
|||
///
|
||||
/// [servicepoint-websocket-relay]: https://github.com/kaesaecracker/servicepoint-websocket-relay
|
||||
#[derive(Debug)]
|
||||
pub struct Websocket(
|
||||
pub struct WebsocketConnection(
|
||||
std::sync::Mutex<
|
||||
tungstenite::WebSocket<
|
||||
tungstenite::stream::MaybeTlsStream<std::net::TcpStream>,
|
||||
|
|
@ -19,7 +19,7 @@ pub struct Websocket(
|
|||
>,
|
||||
);
|
||||
|
||||
impl Connection for Websocket {
|
||||
impl Connection for WebsocketConnection {
|
||||
type Error = tungstenite::Error;
|
||||
|
||||
fn send(&self, packet: impl Into<Packet>) -> Result<(), Self::Error> {
|
||||
|
|
@ -29,7 +29,7 @@ impl Connection for Websocket {
|
|||
}
|
||||
}
|
||||
|
||||
impl Websocket {
|
||||
impl WebsocketConnection {
|
||||
/// Open a new WebSocket and connect to the provided host.
|
||||
///
|
||||
/// Requires the feature "protocol_websocket" which is disabled by default.
|
||||
|
|
@ -40,7 +40,7 @@ impl Websocket {
|
|||
/// use tungstenite::http::Uri;
|
||||
/// use servicepoint::{
|
||||
/// Command,
|
||||
/// connections::{Websocket as WebsocketConnection, Connection}
|
||||
/// connections::{WebsocketConnection as WebsocketConnection, Connection}
|
||||
/// };
|
||||
/// let uri = "ws://localhost:8080".parse().unwrap();
|
||||
/// let mut connection = WebsocketConnection::open(uri)
|
||||
|
|
@ -61,7 +61,7 @@ impl Websocket {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for Websocket {
|
||||
impl Drop for WebsocketConnection {
|
||||
fn drop(&mut self) {
|
||||
_ = self.0.try_lock().map(move |mut sock| sock.close(None));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,14 +53,14 @@ pub const PIXEL_COUNT: usize = PIXEL_WIDTH * PIXEL_HEIGHT;
|
|||
/// ```rust
|
||||
/// # use std::time::Instant;
|
||||
/// # use servicepoint::*;
|
||||
/// # let connection = connections::Fake;
|
||||
/// # let connection = FakeConnection;
|
||||
/// # let pixels = Bitmap::max_sized();
|
||||
/// loop {
|
||||
/// let start = Instant::now();
|
||||
///
|
||||
/// // Change pixels here
|
||||
///
|
||||
/// connection.send(commands::BitmapLinearWin {
|
||||
/// connection.send(BitmapCommand {
|
||||
/// origin: Origin::new(0,0),
|
||||
/// bitmap: pixels,
|
||||
/// compression: CompressionCode::default()
|
||||
|
|
|
|||
20
src/lib.rs
20
src/lib.rs
|
|
@ -12,11 +12,11 @@
|
|||
//! use servicepoint::*;
|
||||
//!
|
||||
//! // establish a connection
|
||||
//! let connection = connections::Udp::open("127.0.0.1:2342")
|
||||
//! let connection = UdpConnection::open("127.0.0.1:2342")
|
||||
//! .expect("connection failed");
|
||||
//!
|
||||
//! // turn off all pixels on display
|
||||
//! connection.send(commands::Clear)
|
||||
//! connection.send(ClearCommand)
|
||||
//! .expect("send failed");
|
||||
//! ```
|
||||
//!
|
||||
|
|
@ -24,13 +24,13 @@
|
|||
//!
|
||||
//! ```rust
|
||||
//! # use servicepoint::*;
|
||||
//! # let connection = connections::Udp::open("127.0.0.1:2342").expect("connection failed");
|
||||
//! # let connection = UdpConnection::open("127.0.0.1:2342").expect("connection failed");
|
||||
//! // turn on all pixels in a grid
|
||||
//! let mut pixels = Bitmap::max_sized();
|
||||
//! pixels.fill(true);
|
||||
//!
|
||||
//! // create command to send pixels
|
||||
//! let command = commands::BitmapLinearWin {
|
||||
//! let command = BitmapCommand {
|
||||
//! origin: Origin::ZERO,
|
||||
//! bitmap: pixels,
|
||||
//! compression: CompressionCode::default()
|
||||
|
|
@ -44,13 +44,13 @@
|
|||
//!
|
||||
//! ```rust
|
||||
//! # use servicepoint::*;
|
||||
//! # let connection = connections::Udp::open("127.0.0.1:2342").expect("connection failed");
|
||||
//! # let connection = UdpConnection::open("127.0.0.1:2342").expect("connection failed");
|
||||
//! // create a text grid
|
||||
//! let mut grid = CharGrid::from("Hello\nCCCB?");
|
||||
//! // modify the grid
|
||||
//! grid.set(grid.width() - 1, 1, '!');
|
||||
//! // create the command to send the data
|
||||
//! let command = commands::Utf8Data { origin: Origin::ZERO, grid };
|
||||
//! let command = CharGridCommand { origin: Origin::ZERO, grid };
|
||||
//! // send command to display
|
||||
//! connection.send(command).expect("send failed");
|
||||
//! ```
|
||||
|
|
@ -61,9 +61,9 @@ pub use crate::brightness::Brightness;
|
|||
pub use crate::brightness_grid::BrightnessGrid;
|
||||
pub use crate::byte_grid::ByteGrid;
|
||||
pub use crate::char_grid::CharGrid;
|
||||
pub use crate::commands::{Command, TypedCommand};
|
||||
pub use crate::commands::*;
|
||||
pub use crate::compression_code::CompressionCode;
|
||||
pub use crate::connections::Connection;
|
||||
pub use crate::connections::*;
|
||||
pub use crate::constants::*;
|
||||
pub use crate::cp437_grid::Cp437Grid;
|
||||
pub use crate::data_ref::DataRef;
|
||||
|
|
@ -80,11 +80,11 @@ mod brightness;
|
|||
mod brightness_grid;
|
||||
mod byte_grid;
|
||||
mod char_grid;
|
||||
pub mod commands;
|
||||
mod commands;
|
||||
mod command_code;
|
||||
mod compression;
|
||||
mod compression_code;
|
||||
pub mod connections;
|
||||
mod connections;
|
||||
mod constants;
|
||||
mod cp437_grid;
|
||||
mod data_ref;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
//!
|
||||
//! ```rust
|
||||
//! use servicepoint::{Command, Packet, TypedCommand};
|
||||
//! # let command = servicepoint::commands::Clear;
|
||||
//! # let command = servicepoint::ClearCommand;
|
||||
//! let packet: Packet = command.into();
|
||||
//! let command = TypedCommand::try_from(packet).expect("could not read command from packet");
|
||||
//! ```
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
//!
|
||||
//! ```rust
|
||||
//! use servicepoint::{Command, Packet};
|
||||
//! # let command = servicepoint::commands::Clear;
|
||||
//! # let command = servicepoint::ClearCommand;
|
||||
//! # let packet: Packet = command.into();
|
||||
//! let bytes: Vec<u8> = packet.into();
|
||||
//! let packet = Packet::try_from(bytes).expect("could not read packet from bytes");
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ impl<T: Value> ValueGrid<T> {
|
|||
/// let mut grid: ByteGrid = ByteGrid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||
/// foo(&mut grid);
|
||||
/// let grid: BrightnessGrid = grid.map(Brightness::saturating_from);
|
||||
/// let command = commands::CharBrightness { origin: Origin::ZERO, grid };
|
||||
/// let command = BrightnessGridCommand { origin: Origin::ZERO, grid };
|
||||
/// ```
|
||||
/// [Brightness]: [crate::Brightness]
|
||||
/// [Command]: [crate::Command]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue