diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 89904480d..796e79092 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -44,6 +44,7 @@ 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 @@ -104,6 +105,17 @@ def __str__(self): return self.name.replace("_", " ") +# Flags describing the reporting method of a control +# We treat bytes 2 and 5 of `get/setCidReporting` as a single bitfield +MAPPING_FLAG = NamedInts( + analytics_key_events_reporting=0x100, + force_raw_XY_diverted=0x40, + raw_XY_diverted=0x10, + persistently_diverted=0x04, + diverted=0x01, +) + + class FeaturesArray(dict): def __init__(self, device): assert device is not None @@ -305,21 +317,21 @@ def remappable_to(self) -> common.NamedInts: def mapping_flags(self) -> List[str]: if self._mapping_flags is None: self._getCidReporting() - return special_keys.MAPPING_FLAG.flag_names(self._mapping_flags) + return MAPPING_FLAG.flag_names(self._mapping_flags) def set_diverted(self, value: bool): """If set, the control is diverted temporarily and reports presses as HID++ events.""" - flags = {special_keys.MAPPING_FLAG.diverted: value} + flags = {MAPPING_FLAG.diverted: value} self._setCidReporting(flags=flags) def set_persistently_diverted(self, value: bool): """If set, the control is diverted permanently and reports presses as HID++ events.""" - flags = {special_keys.MAPPING_FLAG.persistently_diverted: value} + flags = {MAPPING_FLAG.persistently_diverted: value} self._setCidReporting(flags=flags) def set_rawXY_reporting(self, value: bool): """If set, the mouse temporarily reports all its raw XY events while this control is pressed as HID++ events.""" - flags = {special_keys.MAPPING_FLAG.raw_XY_diverted: value} + flags = {MAPPING_FLAG.raw_XY_diverted: value} self._setCidReporting(flags=flags) def remap(self, to: NamedInt): @@ -371,19 +383,19 @@ def _setCidReporting(self, flags: Dict[NamedInt, bool] = None, remap: int = 0): """ flags = flags if flags else {} # See flake8 B006 - # if special_keys.MAPPING_FLAG.raw_XY_diverted in flags and flags[special_keys.MAPPING_FLAG.raw_XY_diverted]: + # if MAPPING_FLAG.raw_XY_diverted in flags and flags[MAPPING_FLAG.raw_XY_diverted]: # We need diversion to report raw XY, so divert temporarily (since XY reporting is also temporary) - # flags[special_keys.MAPPING_FLAG.diverted] = True - # if special_keys.MAPPING_FLAG.diverted in flags and not flags[special_keys.MAPPING_FLAG.diverted]: - # flags[special_keys.MAPPING_FLAG.raw_XY_diverted] = False + # flags[MAPPING_FLAG.diverted] = True + # if MAPPING_FLAG.diverted in flags and not flags[MAPPING_FLAG.diverted]: + # flags[MAPPING_FLAG.raw_XY_diverted] = False # The capability required to set a given reporting flag. FLAG_TO_CAPABILITY = { - special_keys.MAPPING_FLAG.diverted: KeyFlag.DIVERTABLE, - special_keys.MAPPING_FLAG.persistently_diverted: KeyFlag.PERSISTENTLY_DIVERTABLE, - special_keys.MAPPING_FLAG.analytics_key_events_reporting: KeyFlag.ANALYTICS_KEY_EVENTS, - special_keys.MAPPING_FLAG.force_raw_XY_diverted: KeyFlag.FORCE_RAW_XY, - special_keys.MAPPING_FLAG.raw_XY_diverted: KeyFlag.RAW_XY, + MAPPING_FLAG.diverted: KeyFlag.DIVERTABLE, + MAPPING_FLAG.persistently_diverted: KeyFlag.PERSISTENTLY_DIVERTABLE, + MAPPING_FLAG.analytics_key_events_reporting: KeyFlag.ANALYTICS_KEY_EVENTS, + MAPPING_FLAG.force_raw_XY_diverted: KeyFlag.FORCE_RAW_XY, + MAPPING_FLAG.raw_XY_diverted: KeyFlag.RAW_XY, } bfield = 0 diff --git a/lib/logitech_receiver/special_keys.py b/lib/logitech_receiver/special_keys.py index 8daa5790f..b8be4a22d 100644 --- a/lib/logitech_receiver/special_keys.py +++ b/lib/logitech_receiver/special_keys.py @@ -580,17 +580,6 @@ def __str__(self): return self.name.replace("_", " ").title() -# Flags describing the reporting method of a control -# We treat bytes 2 and 5 of `get/setCidReporting` as a single bitfield -MAPPING_FLAG = NamedInts( - analytics_key_events_reporting=0x100, - force_raw_XY_diverted=0x40, - raw_XY_diverted=0x10, - persistently_diverted=0x04, - diverted=0x01, -) - - class CIDGroupBit(IntEnum): g1 = 0x01 g2 = 0x02