Skip to content

Commit

Permalink
mapping flag: Move to module of use
Browse files Browse the repository at this point in the history
The mapping flags are solely used in hiddpp20 module, thus put them into
this module.

Related pwr-Solaar#2273
  • Loading branch information
MattHag committed Dec 1, 2024
1 parent 06c205b commit ce701cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
38 changes: 25 additions & 13 deletions lib/logitech_receiver/hidpp20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions lib/logitech_receiver/special_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce701cf

Please sign in to comment.