Enum flipdot_core::SignType
source · #[non_exhaustive]pub enum SignType {
Max3000Front112x16,
Max3000Front98x16,
Max3000Side90x7,
Max3000Rear30x10,
Max3000Rear23x10,
Max3000Dash30x7,
HorizonFront160x16,
HorizonFront140x16,
HorizonSide96x8,
HorizonRear48x16,
HorizonDash40x12,
}
Expand description
The configuration information for a particular model of sign.
In order to communicate with a sign, we need to send the proper configuration data, which includes an ID, size information, and a few other things. This enum represents the signs for which that data is known, and thus we are able to communicate with.
§Examples
use flipdot_core::SignType;
let sign_type = SignType::Max3000Front112x16;
assert_eq!((112, 16), sign_type.dimensions());
let config = sign_type.to_bytes();
let parsed_type = SignType::from_bytes(config)?;
assert_eq!(sign_type, parsed_type);
§Format Details
The first byte indicates the type of sign, and different types have different formats for the rest of the configuration block.
§Max3000
┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
│0x04│ ID │0x00│ ?? │ H │ W1 │ W2 │ W3 │ W4 │ B │0x00│0x00│0x00│0x00│0x00│0x00│
└────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘
Byte 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Max3000 signs have an initial byte of 0x04
. ID
is a unique ID for the particular sign type
within the family, e.g. the 90 × 7 side sign has ID 0x20
. Byte 2 seems to always be zero,
and byte 3 is unknown. H
is the height in pixels, and W1 + W2 + W3 + W4
is the
total width. B
indicates the number of bits per column (either 8 or 16). The remaining
bytes appear unused and are always zero.
§Horizon
┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
│0x08│ ID │0x00│ ?? │ ?? │ H │0x00│ W │ A1 │ A2 │ B1 │ B2 │ ?? │0x00│0x00│0x00│
└────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘
Byte 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Horizon signs have an initial byte of 0x08
. ID
is a unique ID for the particular sign type
within the family, e.g. the 96 × 8 side sign has ID 0xB4
. Byte 2 seems to always be zero,
and bytes 3 and 4 are unknown. H
is the height in pixels, and W
is the width. The next
four bytes seem to indicate the arrangement of sub-panels to create the final width:
W = A1 × B1 + A2 × B2
. Byte 12 is unknown (generally zero but 0x04
for the 40 × 12 dash sign).
The remaining bytes appear unused and are always zero.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Max3000Front112x16
Max3000 flip-dot sign, front, 112 × 16 pixels
Max3000Front98x16
Max3000 flip-dot sign, front, 98 × 16 pixels
Max3000Side90x7
Max3000 flip-dot sign, side, 90 × 7 pixels
Max3000Rear30x10
Max3000 flip-dot sign, rear, 30 × 10 pixels
Max3000Rear23x10
Max3000 flip-dot sign, rear, 23 × 10 pixels
Max3000Dash30x7
Max3000 flip-dot sign, dash, 30 × 7 pixels
HorizonFront160x16
Horizon LED sign, front, 160 × 16 pixels
HorizonFront140x16
Horizon LED sign, front, 140 × 16 pixels
HorizonSide96x8
Horizon LED sign, side, 96 × 8 pixels
HorizonRear48x16
Horizon LED sign, rear, 48 × 16 pixels
HorizonDash40x12
Horizon LED sign, dash, 40 × 12 pixels
Implementations§
source§impl SignType
impl SignType
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, SignTypeError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, SignTypeError>
Converts a slice representing configuration data into a SignType
.
§Errors
Returns:
SignTypeError::WrongConfigLength
if the data is not 16 bytes long.SignTypeError::UnknownConfig
if the data does not correspond to a known sign type.
§Examples
let bytes = vec![0x04, 0x62, 0x00, 0x04, 0x0A, 0x1E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
let sign_type = SignType::from_bytes(&bytes)?;
assert_eq!(SignType::Max3000Rear30x10, sign_type);
sourcepub fn dimensions(self) -> (u32, u32)
pub fn dimensions(self) -> (u32, u32)
Gets the dimensions (width, height), in pixels, of this sign type.
§Examples
let sign_type = SignType::HorizonFront140x16;
assert_eq!((140, 16), sign_type.dimensions());
sourcepub fn to_bytes(self) -> &'static [u8] ⓘ
pub fn to_bytes(self) -> &'static [u8] ⓘ
Gets the 16-byte configuration data for this sign type.
§Examples
let sign_type = SignType::Max3000Rear30x10;
let expected = vec![0x04, 0x62, 0x00, 0x04, 0x0A, 0x1E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
assert_eq!(expected, sign_type.to_bytes());