Skip to content

Commit

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

Related #2273
  • Loading branch information
MattHag committed Nov 4, 2024
1 parent 9f86411 commit 7973857
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
31 changes: 25 additions & 6 deletions lib/logitech_receiver/hidpp20.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 @@ -79,6 +80,24 @@ def _profiles(self) -> Any:
...


# 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
Expand Down Expand Up @@ -217,7 +236,7 @@ def default_task(self) -> NamedInt:

@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):
Expand Down Expand Up @@ -354,11 +373,11 @@ def _setCidReporting(self, flags: Dict[NamedInt, bool] = None, remap: int = 0):

# 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
Expand Down
16 changes: 0 additions & 16 deletions lib/logitech_receiver/special_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,22 +580,6 @@ def __str__(self):
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(
Expand Down

0 comments on commit 7973857

Please sign in to comment.