mapping flag: Move to module of use

The mapping flags are solely used in hiddpp20 module, thus put them into
this module.

Related #2273
This commit is contained in:
MattHag 2024-11-05 02:37:58 +01:00 committed by Peter F. Patel-Schneider
parent 7c91d0b2db
commit 5c736e9154
2 changed files with 25 additions and 24 deletions

View File

@ -44,6 +44,7 @@ from .common import BatteryLevelApproximation
from .common import BatteryStatus from .common import BatteryStatus
from .common import FirmwareKind from .common import FirmwareKind
from .common import NamedInt from .common import NamedInt
from .common import NamedInts
from .hidpp20_constants import CHARGE_STATUS from .hidpp20_constants import CHARGE_STATUS
from .hidpp20_constants import DEVICE_KIND from .hidpp20_constants import DEVICE_KIND
from .hidpp20_constants import ChargeLevel from .hidpp20_constants import ChargeLevel
@ -104,6 +105,17 @@ class KeyFlag(Flag):
return self.name.replace("_", " ") 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): class FeaturesArray(dict):
def __init__(self, device): def __init__(self, device):
assert device is not None assert device is not None
@ -305,21 +317,21 @@ class ReprogrammableKeyV4(ReprogrammableKey):
def mapping_flags(self) -> List[str]: def mapping_flags(self) -> List[str]:
if self._mapping_flags is None: if self._mapping_flags is None:
self._getCidReporting() 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): def set_diverted(self, value: bool):
"""If set, the control is diverted temporarily and reports presses as HID++ events.""" """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) self._setCidReporting(flags=flags)
def set_persistently_diverted(self, value: bool): def set_persistently_diverted(self, value: bool):
"""If set, the control is diverted permanently and reports presses as HID++ events.""" """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) self._setCidReporting(flags=flags)
def set_rawXY_reporting(self, value: bool): 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.""" """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) self._setCidReporting(flags=flags)
def remap(self, to: NamedInt): def remap(self, to: NamedInt):
@ -371,19 +383,19 @@ class ReprogrammableKeyV4(ReprogrammableKey):
""" """
flags = flags if flags else {} # See flake8 B006 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) # We need diversion to report raw XY, so divert temporarily (since XY reporting is also temporary)
# flags[special_keys.MAPPING_FLAG.diverted] = True # flags[MAPPING_FLAG.diverted] = True
# if special_keys.MAPPING_FLAG.diverted in flags and not flags[special_keys.MAPPING_FLAG.diverted]: # if MAPPING_FLAG.diverted in flags and not flags[MAPPING_FLAG.diverted]:
# flags[special_keys.MAPPING_FLAG.raw_XY_diverted] = False # flags[MAPPING_FLAG.raw_XY_diverted] = False
# The capability required to set a given reporting flag. # The capability required to set a given reporting flag.
FLAG_TO_CAPABILITY = { FLAG_TO_CAPABILITY = {
special_keys.MAPPING_FLAG.diverted: KeyFlag.DIVERTABLE, MAPPING_FLAG.diverted: KeyFlag.DIVERTABLE,
special_keys.MAPPING_FLAG.persistently_diverted: KeyFlag.PERSISTENTLY_DIVERTABLE, MAPPING_FLAG.persistently_diverted: KeyFlag.PERSISTENTLY_DIVERTABLE,
special_keys.MAPPING_FLAG.analytics_key_events_reporting: KeyFlag.ANALYTICS_KEY_EVENTS, MAPPING_FLAG.analytics_key_events_reporting: KeyFlag.ANALYTICS_KEY_EVENTS,
special_keys.MAPPING_FLAG.force_raw_XY_diverted: KeyFlag.FORCE_RAW_XY, MAPPING_FLAG.force_raw_XY_diverted: KeyFlag.FORCE_RAW_XY,
special_keys.MAPPING_FLAG.raw_XY_diverted: KeyFlag.RAW_XY, MAPPING_FLAG.raw_XY_diverted: KeyFlag.RAW_XY,
} }
bfield = 0 bfield = 0

View File

@ -580,17 +580,6 @@ class Task(IntEnum):
return self.name.replace("_", " ").title() 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): class CIDGroupBit(IntEnum):
g1 = 0x01 g1 = 0x01
g2 = 0x02 g2 = 0x02