From 1499d8cda831341c900f7d9ca41ca0a6b0dba2ae Mon Sep 17 00:00:00 2001 From: Fernando Chorney Date: Sun, 17 Mar 2024 14:18:58 -0500 Subject: [PATCH] Moved config flags to a class --- pysmx/sdk/config.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/pysmx/sdk/config.py b/pysmx/sdk/config.py index 42cdf51..72a03e6 100644 --- a/pysmx/sdk/config.py +++ b/pysmx/sdk/config.py @@ -73,6 +73,26 @@ def from_unpacked_values(cls, data: list[int]) -> "PackedSensorSettings": ) +@dataclass +class SMXConfigFlags(object): + # If set, the panels will use the pressed animation when pressed, and step_color is ignored. + # If unset, panels will be lit solid using step_color. + # master_version >= 4. Previous versions always use step_color. + auto_lighting_use_pressed_animations: bool = True + + # If set, panels are using FSRs, otherwise use load cells. + fsr: bool = True + + STRUCT_FMT: ClassVar[str] = " "SMXConfigFlags": + return SMXConfigFlags(bool(data & (1 << 0)), bool(data & (1 << 1))) + + def to_packed_int(self) -> int: + return (self.fsr << 0) + (self.auto_lighting_use_pressed_animations << 1) + + @dataclass class SMXStageConfig(object): # The firmware version of the master controller. Where supported (version 2 and up), @@ -98,9 +118,8 @@ class SMXStageConfig(object): # - 0x03: debounceDelayMs added config_version: int = 0x05 - # TODO: Make the flags enum or whatever, this is a packed byte # Packed flags (master_version >= 4) - flags: int = 0 + flags: SMXConfigFlags = SMXConfigFlags(True, True) # Panel thresholds are labelled by their numpad position. Eg: Panel8 is up. # If SMXDeviceInfo.firmware_version is 1, Panel7 corresponds to all of Up, Down, @@ -165,7 +184,9 @@ class SMXStageConfig(object): "<" # Little Endian "B" # masterVersion "B" # configVersion - "B" # flags + ) + + SMXConfigFlags.STRUCT_FMT[1:] # flags + + ( "H" # debounceNodelayMilliseconds "H" # debounceDelayMilliseconds "H" # panelDebounceMicroseconds @@ -202,7 +223,7 @@ def to_packed_bytes(self) -> bytes: struct.calcsize(self.STRUCT_FMT), self.master_version, self.config_version, - self.flags, + self.flags.to_packed_int(), self.debounce_no_delay_milliseconds, self.debounce_delay_milliseconds, self.panel_debounce_microseconds, @@ -273,7 +294,7 @@ def from_packed_bytes(cls, data: bytes) -> "SMXStageConfig": return SMXStageConfig( master_version, config_version, - flags, + SMXConfigFlags.from_unpacked_value(flags), debounce_no_delay_milliseconds, debounce_delay_milliseconds, panel_debounce_microseconds,