Crate servicepoint

Source
Expand description

Abstractions for the UDP protocol of the CCCB servicepoint display.

Your starting point is a std::net::UdpSocket connected to the display. With a socket, you can send Commands. When received, the display will update the state of its pixels.

§Examples

§Clear display

use std::net::UdpSocket;
use servicepoint::*;

// establish a connection
let connection = UdpSocket::bind_connect("127.0.0.1:2342")
    .expect("connection failed");

 // turn off all pixels on display
 connection.send_command(ClearCommand)
    .expect("send failed");

§Set all pixels to on

 // turn on all pixels in a grid
 let mut pixels = Bitmap::max_sized();
 pixels.fill(true);

 // create command to send pixels
 let command = BitmapCommand {
    origin: Origin::ZERO,
    bitmap: pixels,
    compression: CompressionCode::default()
 };

 // send command to display
 connection.send_command(command).expect("send failed");

§Send text

// 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 = CharGridCommand { origin: Origin::ZERO, grid };
// send command to display
connection.send_command(command).expect("send failed");

§Convert a packet to a command and back

use servicepoint::{Command, Packet, TypedCommand};
let packet: Packet = command.into();
let command = TypedCommand::try_from(packet).expect("could not read command from packet");

§Convert a packet to bytes and back

use servicepoint::{Command, Packet};
let bytes: Vec<u8> = packet.into();
let packet = Packet::try_from(bytes).expect("could not read packet from bytes");

Modules§

bitvec
Re-export of the used library ::bitvec.
cp437
Contains functions to convert between UTF-8 and Codepage 437.

Structs§

BitVecCommand
Set pixel data starting at the pixel offset on screen.
Bitmap
A fixed-size 2D grid of booleans.
BitmapCommand
Overwrites a rectangular region of pixels.
BitmapLegacyCommandDeprecated
Legacy command code, gets ignored by the real display.
Brightness
A display brightness value, checked for correct value range
BrightnessGridCommand
Set the brightness of individual tiles in a rectangular area of the display.
CharGridCommand
Show text on the screen.
ClearCommand
Set all pixels to the off state. Does not affect brightness.
Cp437GridCommand
Show text on the screen.
FadeOutCommand
Untested
FakeConnection
A fake connection for testing that does not actually send anything.
GlobalBrightnessCommand
Set the brightness of all tiles to the same value.
HardResetCommand
Kills the udp daemon on the display, which usually results in a restart.
Header
A raw header.
InvalidCharError
The error occurring when loading an invalid character
Origin
An origin marks the top left position of a window sent to the display.
Packet
The raw packet.
Pixels
Marks something to be measured in number of pixels.
Tiles
Marks something to be measured in number of iles.
ValueGrid
A 2D grid of values.
Window
A window into a 2D grid.
WindowMut
A window into a 2D grid.

Enums§

BinaryOperation
Binary operations for use with the BitVecCommand command.
CommandCode
The u16 command codes used for the crate::Commands.
CompressionCode
Specifies the kind of compression to use. Availability depends on features.
LoadBitmapError
Errors that can happen when loading a bitmap.
SetValueSeriesError
Error type for methods that change a whole column or row at once
TryFromPacketError
Err values for crate::TypedCommand::try_from.
TryIntoPacketError
An error that can occur when parsing a raw packet as a command
TryLoadValueGridError
Errors that can occur when loading a grid
TypedCommand
This enum contains all commands provided by the library. This is useful in case you want one data type for all kinds of commands without using dyn.

Constants§

FRAME_PACING
Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
PIXEL_COUNT
pixel count on whole screen
PIXEL_HEIGHT
Display height in pixels
PIXEL_WIDTH
Display width in pixels
TILE_HEIGHT
Display tile count in the y-direction
TILE_SIZE
size of a single tile in one dimension
TILE_WIDTH
Display tile count in the x-direction

Traits§

CharGridExt
Extension methods for any Grid<char>
CharGridMutExt
Extension methods for any GridMut<char>.
Command
This trait represents a command that can be sent to the display.
DataRef
A trait for getting the underlying raw byte slices of data containers.
Grid
A two-dimensional readonly grid of T
GridMut
A two-dimensional mutable grid of T
UdpSocketExt
Provides servicepoint specific extensions for UdpSocket
Value
A type that can be stored in a ValueGrid, e.g. char, u8.

Type Aliases§

BrightnessGrid
A grid containing brightness values.
ByteGrid
A 2d grid of bytes - see ValueGrid.
CharGrid
A grid containing UTF-8 characters.
Cp437Grid
A grid containing codepage 437 characters.
DisplayBitVec
A byte-packed vector of booleans.
Offset
Type alias for documenting the meaning of the u16 in enum values
Payload
The raw payload.