docs, formatting

This commit is contained in:
Vinzenz Schroeter 2024-06-23 13:00:13 +02:00
parent c4c6708533
commit 672b5e0581
5 changed files with 89 additions and 37 deletions

View file

@ -1,9 +1,7 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = [ members = [
"crates/servicepoint", "crates/*",
"crates/servicepoint_binding_c",
"crates/servicepoint_binding_cs",
"crates/servicepoint_binding_c/examples/lang_c" "crates/servicepoint_binding_c/examples/lang_c"
] ]

View file

@ -26,7 +26,9 @@ fn main() {
.expect("could not connect to display"); .expect("could not connect to display");
if cli.clear { if cli.clear {
connection.send(Command::Clear).expect("sending clear failed"); connection
.send(Command::Clear)
.expect("sending clear failed");
} }
let max_width = cli.text.iter().map(|t| t.len()).max().unwrap(); let max_width = cli.text.iter().map(|t| t.len()).max().unwrap();

View file

@ -1,8 +1,8 @@
use rand::distributions::Standard;
#[cfg(feature = "rand")] #[cfg(feature = "rand")]
use rand::prelude::Distribution; use rand::{
#[cfg(feature = "rand")] distributions::{Distribution, Standard},
use rand::Rng; Rng,
};
/// A display brightness value, checked for correct value range /// A display brightness value, checked for correct value range
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]

View file

@ -27,35 +27,77 @@ pub type Offset = usize;
/// A command to send to the display. /// A command to send to the display.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum Command { pub enum Command {
/// Set all pixels to the off state /// Set all pixels to the off state. Does not affect brightness.
Clear, Clear,
/// Kills the udp daemon, usually results in a reboot of the display.
HardReset, /// Show text on the screen.
/// Slowly decrease brightness until off? Untested. ///
FadeOut, /// The origin is in tiles.
/// Set the brightness of tiles ///
CharBrightness(Origin, ByteGrid), /// <div class="warning">
/// Set the brightness of all tiles /// The library does not currently convert between UTF-8 and CP-437.
Brightness(Brightness), /// Because Rust expects UTF-8 strings, it might be necessary to only send ASCII for now.
#[deprecated] /// </div>
/// Legacy command code, gets ignored by the real display.
BitmapLegacy,
/// Set pixel data starting at the offset.
/// The contained `BitVec` is always uncompressed.
BitmapLinear(Offset, SpBitVec, CompressionCode),
/// Set pixel data according to an and-mask starting at the offset.
/// The contained `BitVec` is always uncompressed.
BitmapLinearAnd(Offset, SpBitVec, CompressionCode),
/// Set pixel data according to an or-mask starting at the offset.
/// The contained `BitVec` is always uncompressed.
BitmapLinearOr(Offset, SpBitVec, CompressionCode),
/// Set pixel data according to a xor-mask starting at the offset.
/// The contained `BitVec` is always uncompressed.
BitmapLinearXor(Offset, SpBitVec, CompressionCode),
/// Show text on the screen. Note that the byte data has to be CP437 encoded.
Cp437Data(Origin, ByteGrid), Cp437Data(Origin, ByteGrid),
/// Sets a window of pixels to the specified values /// Sets a window of pixels to the specified values
BitmapLinearWin(Origin, PixelGrid, CompressionCode), BitmapLinearWin(Origin, PixelGrid, CompressionCode),
/// Set the brightness of all tiles to the same value.
Brightness(Brightness),
/// Set the brightness of individual tiles in a rectangular area of the display.
///
/// The origin is in tiles.
CharBrightness(Origin, ByteGrid),
/// 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.
BitmapLinear(Offset, SpBitVec, CompressionCode),
/// 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.
BitmapLinearAnd(Offset, SpBitVec, CompressionCode),
/// 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.
BitmapLinearOr(Offset, SpBitVec, CompressionCode),
/// 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.
BitmapLinearXor(Offset, SpBitVec, CompressionCode),
/// Kills the udp daemon on the display, which usually results in a restart.
///
/// Please do not send this in your normal program flow.
HardReset,
/// <div class="warning">Untested</div>
///
/// Slowly decrease brightness until off or something like that?
FadeOut,
#[deprecated]
/// Legacy command code, gets ignored by the real display.
///
/// Might be useful as a noop package.
BitmapLegacy,
} }
impl From<Command> for Packet { impl From<Command> for Packet {
@ -226,12 +268,14 @@ impl TryFrom<Packet> for Command {
let Header(_, a, b, c, d) = header; let Header(_, a, b, c, d) = header;
if a != 0 || b != 0 || c != 0 || d != 0 { if a != 0 || b != 0 || c != 0 || d != 0 {
return Err(TryFromPacketError::ExtraneousHeaderValues) return Err(TryFromPacketError::ExtraneousHeaderValues);
} }
match Brightness::try_from(payload[0]) { match Brightness::try_from(payload[0]) {
Ok(b) => Ok(Command::Brightness(b)), Ok(b) => Ok(Command::Brightness(b)),
Err(_) => Err(TryFromPacketError::InvalidBrightness(payload[0])) Err(_) => {
Err(TryFromPacketError::InvalidBrightness(payload[0]))
}
} }
} }
CommandCode::HardReset => match Self::check_command_only(packet) { CommandCode::HardReset => match Self::check_command_only(packet) {
@ -401,7 +445,10 @@ mod tests {
use crate::command::TryFromPacketError; use crate::command::TryFromPacketError;
use crate::command_code::CommandCode; use crate::command_code::CommandCode;
use crate::{Brightness, ByteGrid, Command, CompressionCode, Header, Origin, Packet, PixelGrid}; use crate::{
Brightness, ByteGrid, Command, CompressionCode, Header, Origin, Packet,
PixelGrid,
};
fn round_trip(original: Command) { fn round_trip(original: Command) {
let packet: Packet = original.clone().into(); let packet: Packet = original.clone().into();

View file

@ -91,7 +91,12 @@ pub unsafe extern "C" fn sp_command_fade_out() -> *mut Command {
Box::into_raw(Box::new(Command::FadeOut)) Box::into_raw(Box::new(Command::FadeOut))
} }
/// Allocates a new `Command::Brightness` instance. /// Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the
/// same value.
///
/// # Panics
///
/// - When the provided brightness value is out of range (0-11).
/// ///
/// # Safety /// # Safety
/// ///