impl Default for CompressionCode
also more feature-agnostic examples
This commit is contained in:
parent
c534929089
commit
a1316b0271
12 changed files with 41 additions and 18 deletions
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
let command = Command::BitmapLinearWin(
|
||||
Origin::ZERO,
|
||||
pixels,
|
||||
CompressionCode::Uncompressed,
|
||||
CompressionCode::default(),
|
||||
);
|
||||
connection.send(command).expect("send failed");
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ fn main() {
|
|||
let command = Command::BitmapLinearWin(
|
||||
Origin::ZERO,
|
||||
field.clone(),
|
||||
CompressionCode::Lzma,
|
||||
CompressionCode::default(),
|
||||
);
|
||||
connection.send(command).expect("could not send");
|
||||
thread::sleep(FRAME_PACING);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ fn main() {
|
|||
let command = Command::BitmapLinearWin(
|
||||
Origin::ZERO,
|
||||
pixels.clone(),
|
||||
CompressionCode::Lzma,
|
||||
CompressionCode::default(),
|
||||
);
|
||||
connection.send(command).expect("send failed");
|
||||
thread::sleep(FRAME_PACING);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ fn main() {
|
|||
let command = Command::BitmapLinearWin(
|
||||
Origin::ZERO,
|
||||
filled_grid,
|
||||
CompressionCode::Lzma,
|
||||
CompressionCode::default(),
|
||||
);
|
||||
connection.send(command).expect("send failed");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ fn main() {
|
|||
.send(Command::BitmapLinearWin(
|
||||
Origin::ZERO,
|
||||
pixels,
|
||||
CompressionCode::Lzma,
|
||||
CompressionCode::default(),
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ fn main() {
|
|||
.send(Command::BitmapLinearWin(
|
||||
Origin::ZERO,
|
||||
enabled_pixels.clone(),
|
||||
CompressionCode::Lzma,
|
||||
CompressionCode::default(),
|
||||
))
|
||||
.expect("could not send command to display");
|
||||
thread::sleep(sleep_duration);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use rand::{
|
|||
/// let val: u8 = b.into();
|
||||
///
|
||||
/// let b = Brightness::try_from(7).unwrap();
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// let result = connection.send(Command::Brightness(b));
|
||||
/// ```
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use crate::ByteGrid;
|
|||
/// grid.set(0, 0, Brightness::MIN);
|
||||
/// grid.set(1, 1, Brightness::MIN);
|
||||
///
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// connection.send(Command::CharBrightness(Origin::new(3, 7), grid)).unwrap()
|
||||
/// ```
|
||||
pub type BrightnessGrid = ValueGrid<Brightness>;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub type Offset = usize;
|
|||
/// # Compression
|
||||
///
|
||||
/// Some commands can contain compressed payloads.
|
||||
/// To get started, use [CompressionCode::Uncompressed].
|
||||
/// To get started, use [CompressionCode::default].
|
||||
///
|
||||
/// If you want to archive the best performance (e.g. latency),
|
||||
/// you can try the different compression algorithms for your hardware and use case.
|
||||
|
|
@ -52,7 +52,7 @@ pub type Offset = usize;
|
|||
/// assert_eq!(command, round_tripped);
|
||||
///
|
||||
/// // send command
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// connection.send(command).unwrap();
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
@ -63,7 +63,7 @@ pub enum Command {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{Command, Connection};
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// connection.send(Command::Clear).unwrap();
|
||||
/// ```
|
||||
Clear,
|
||||
|
|
@ -125,7 +125,7 @@ pub enum Command {
|
|||
/// let command = Command::BitmapLinearWin(
|
||||
/// servicepoint::Origin::ZERO,
|
||||
/// pixels,
|
||||
/// CompressionCode::Uncompressed
|
||||
/// CompressionCode::default()
|
||||
/// );
|
||||
///
|
||||
/// connection.send(command).expect("send failed");
|
||||
|
|
@ -138,7 +138,7 @@ pub enum Command {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{Brightness, Command, Connection};
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// let command = Command::Brightness(Brightness::MAX);
|
||||
/// connection.send(command).unwrap();
|
||||
/// ```
|
||||
|
|
@ -187,7 +187,7 @@ pub enum Command {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{Command, Connection};
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// connection.send(Command::HardReset).unwrap();
|
||||
/// ```
|
||||
HardReset,
|
||||
|
|
@ -200,7 +200,7 @@ pub enum Command {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{Command, Connection};
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// connection.send(Command::FadeOut).unwrap();
|
||||
/// ```
|
||||
FadeOut,
|
||||
|
|
@ -213,7 +213,7 @@ pub enum Command {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use servicepoint::{Command, Connection};
|
||||
/// # let connection = Connection::open("127.0.0.1:2342").unwrap();
|
||||
/// # let connection = Connection::Fake;
|
||||
/// // this sends a packet that does nothing
|
||||
/// # #[allow(deprecated)]
|
||||
/// connection.send(Command::BitmapLegacy).unwrap();
|
||||
|
|
|
|||
|
|
@ -66,6 +66,17 @@ impl TryFrom<u16> for CompressionCode {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for CompressionCode {
|
||||
#[cfg(feature = "compression_lzma")]
|
||||
fn default() -> Self {
|
||||
CompressionCode::Lzma
|
||||
}
|
||||
#[cfg(not(feature = "compression_lzma"))]
|
||||
fn default() -> Self {
|
||||
CompressionCode::Uncompressed
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
@ -117,4 +128,16 @@ mod test {
|
|||
);
|
||||
assert_eq!(u16::from(CompressionCode::Zstd), 0x7a73);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "compression_lzma")]
|
||||
fn default_lzma() {
|
||||
assert_eq!(CompressionCode::default(), CompressionCode::Lzma);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "compression_lzma"))]
|
||||
fn default_uncompressed() {
|
||||
assert_eq!(CompressionCode::default(), CompressionCode::Uncompressed);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ pub const PIXEL_COUNT: usize = PIXEL_WIDTH * PIXEL_HEIGHT;
|
|||
/// connection.send(Command::BitmapLinearWin(
|
||||
/// Origin::new(0,0),
|
||||
/// pixels,
|
||||
/// CompressionCode::Lzma
|
||||
/// CompressionCode::default()
|
||||
/// ))
|
||||
/// .expect("send failed");
|
||||
///
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
//! let command = Command::BitmapLinearWin(
|
||||
//! servicepoint::Origin::ZERO,
|
||||
//! pixels,
|
||||
//! CompressionCode::Uncompressed
|
||||
//! CompressionCode::default()
|
||||
//! );
|
||||
//!
|
||||
//! // send command to display
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue