servicepoint-binding-ruby/servicepoint2/src/command_code.rs

70 lines
2.4 KiB
Rust
Raw Normal View History

/// The u16 command codes used for the `Commands`.
2024-05-12 13:11:42 +02:00
#[repr(u16)]
#[derive(Debug, Copy, Clone)]
pub(crate) enum CommandCode {
2024-05-12 13:11:42 +02:00
Clear = 0x0002,
Cp437Data = 0x0003,
CharBrightness = 0x0005,
Brightness = 0x0007,
HardReset = 0x000b,
FadeOut = 0x000d,
#[deprecated]
BitmapLegacy = 0x0010,
BitmapLinear = 0x0012,
BitmapLinearWinUncompressed = 0x0013,
2024-05-12 13:11:42 +02:00
BitmapLinearAnd = 0x0014,
BitmapLinearOr = 0x0015,
BitmapLinearXor = 0x0016,
BitmapLinearWinZlib = 0x0017,
BitmapLinearWinBzip2 = 0x0018,
BitmapLinearWinLzma = 0x0019,
BitmapLinearWinZstd = 0x001A,
2024-05-12 13:11:42 +02:00
}
impl From<CommandCode> for u16 {
/// returns the u16 command code corresponding to the enum value
fn from(value: CommandCode) -> Self {
value as u16
2024-05-12 13:11:42 +02:00
}
}
impl TryFrom<u16> for CommandCode {
type Error = ();
/// Returns the enum value for the specified `u16` or `Error` if the code is unknown.
2024-05-12 13:11:42 +02:00
fn try_from(value: u16) -> Result<Self, Self::Error> {
use CommandCode::*;
2024-05-12 13:11:42 +02:00
match value {
value if value == Clear as u16 => Ok(Clear),
value if value == Cp437Data as u16 => Ok(Cp437Data),
value if value == CharBrightness as u16 => Ok(CharBrightness),
value if value == Brightness as u16 => Ok(Brightness),
value if value == HardReset as u16 => Ok(HardReset),
value if value == FadeOut as u16 => Ok(FadeOut),
#[allow(deprecated)]
value if value == BitmapLegacy as u16 => Ok(BitmapLegacy),
value if value == BitmapLinear as u16 => Ok(BitmapLinear),
2024-05-16 23:18:43 +02:00
value if value == BitmapLinearWinUncompressed as u16 => {
Ok(BitmapLinearWinUncompressed)
}
2024-05-12 13:11:42 +02:00
value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd),
value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr),
value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor),
2024-05-17 18:44:31 +02:00
value if value == BitmapLinearWinZstd as u16 => {
Ok(BitmapLinearWinZstd)
}
value if value == BitmapLinearWinLzma as u16 => {
Ok(BitmapLinearWinLzma)
}
value if value == BitmapLinearWinZlib as u16 => {
Ok(BitmapLinearWinZlib)
}
value if value == BitmapLinearWinBzip2 as u16 => {
Ok(BitmapLinearWinBzip2)
}
2024-05-12 13:14:33 +02:00
_ => Err(()),
2024-05-12 13:11:42 +02:00
}
}
}