From 267b0a723d0fbf78d195079123a56b0724b7d29c Mon Sep 17 00:00:00 2001 From: MattHag <16444067+MattHag@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:31:36 +0100 Subject: [PATCH] key flags: Move to module of use The key flags are solely used in hiddpp20 module, thus put them into the module. Related #2273 --- lib/logitech_receiver/hidpp20.py | 31 +++++++++++++++++++++------ lib/logitech_receiver/special_keys.py | 16 -------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 3f142927..8298acdb 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -42,6 +42,7 @@ from .common import BatteryLevelApproximation from .common import BatteryStatus from .common import FirmwareKind from .common import NamedInt +from .common import NamedInts from .hidpp20_constants import CHARGE_STATUS from .hidpp20_constants import DEVICE_KIND from .hidpp20_constants import ChargeLevel @@ -79,6 +80,24 @@ class Device(Protocol): ... +# Capabilities and desired software handling for a control +# Ref: https://drive.google.com/file/d/10imcbmoxTJ1N510poGdsviEhoFfB_Ua4/view +# We treat bytes 4 and 8 of `getCidInfo` as a single bitfield +KEY_FLAG = NamedInts( + analytics_key_events=0x400, + force_raw_XY=0x200, + raw_XY=0x100, + virtual=0x80, + persistently_divertable=0x40, + divertable=0x20, + reprogrammable=0x10, + FN_sensitive=0x08, + nonstandard=0x04, + is_FN=0x02, + mse=0x01, +) + + class FeaturesArray(dict): def __init__(self, device): assert device is not None @@ -217,7 +236,7 @@ class ReprogrammableKey: @property def flags(self) -> List[str]: - return special_keys.KEY_FLAG.flag_names(self._flags) + return KEY_FLAG.flag_names(self._flags) class ReprogrammableKeyV4(ReprogrammableKey): @@ -354,11 +373,11 @@ class ReprogrammableKeyV4(ReprogrammableKey): # The capability required to set a given reporting flag. FLAG_TO_CAPABILITY = { - special_keys.MAPPING_FLAG.diverted: special_keys.KEY_FLAG.divertable, - special_keys.MAPPING_FLAG.persistently_diverted: special_keys.KEY_FLAG.persistently_divertable, - special_keys.MAPPING_FLAG.analytics_key_events_reporting: special_keys.KEY_FLAG.analytics_key_events, - special_keys.MAPPING_FLAG.force_raw_XY_diverted: special_keys.KEY_FLAG.force_raw_XY, - special_keys.MAPPING_FLAG.raw_XY_diverted: special_keys.KEY_FLAG.raw_XY, + special_keys.MAPPING_FLAG.diverted: KEY_FLAG.divertable, + special_keys.MAPPING_FLAG.persistently_diverted: KEY_FLAG.persistently_divertable, + special_keys.MAPPING_FLAG.analytics_key_events_reporting: KEY_FLAG.analytics_key_events, + special_keys.MAPPING_FLAG.force_raw_XY_diverted: KEY_FLAG.force_raw_XY, + special_keys.MAPPING_FLAG.raw_XY_diverted: KEY_FLAG.raw_XY, } bfield = 0 diff --git a/lib/logitech_receiver/special_keys.py b/lib/logitech_receiver/special_keys.py index 9547ec34..8daa5790 100644 --- a/lib/logitech_receiver/special_keys.py +++ b/lib/logitech_receiver/special_keys.py @@ -580,22 +580,6 @@ class Task(IntEnum): return self.name.replace("_", " ").title() -# Capabilities and desired software handling for a control -# Ref: https://drive.google.com/file/d/10imcbmoxTJ1N510poGdsviEhoFfB_Ua4/view -# We treat bytes 4 and 8 of `getCidInfo` as a single bitfield -KEY_FLAG = NamedInts( - analytics_key_events=0x400, - force_raw_XY=0x200, - raw_XY=0x100, - virtual=0x80, - persistently_divertable=0x40, - divertable=0x20, - reprogrammable=0x10, - FN_sensitive=0x08, - nonstandard=0x04, - is_FN=0x02, - mse=0x01, -) # Flags describing the reporting method of a control # We treat bytes 2 and 5 of `get/setCidReporting` as a single bitfield MAPPING_FLAG = NamedInts(