Complete DEVICE_FEATURES to DeviceFeature transition for hidpp10 devices
Fixes solaar show.
Fixes: 378175f9
Remove NamedInts: Convert DeviceFeature to flag
This commit is contained in:
parent
ed596666ee
commit
41ba24eee2
|
@ -220,6 +220,25 @@ class DeviceFeature(Flag):
|
|||
https://drive.google.com/file/d/0BxbRzx7vEV7eNDBheWY0UHM5dEU/view?usp=sharing
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def flag_names(cls, flag_bits: int) -> List[str]:
|
||||
"""Extract the names of the flags from the integer."""
|
||||
indexed = {item.value: item.name for item in cls}
|
||||
|
||||
flag_names = []
|
||||
unknown_bits = flag_bits
|
||||
for k in indexed:
|
||||
# Ensure that the key (flag value) is a power of 2 (a single bit flag)
|
||||
assert bin(k).count("1") == 1
|
||||
if k & flag_bits == k:
|
||||
unknown_bits &= ~k
|
||||
flag_names.append(indexed[k].replace("_", " ").lower())
|
||||
|
||||
# Yield any remaining unknown bits
|
||||
if unknown_bits != 0:
|
||||
flag_names.append(f"unknown:{unknown_bits:06X}")
|
||||
return flag_names
|
||||
|
||||
RESERVED1 = 0x010000
|
||||
SPECIAL_BUTTONS = 0x020000
|
||||
ENHANCED_KEY_USAGE = 0x040000
|
||||
|
|
|
@ -138,7 +138,7 @@ def _print_device(dev, num=None):
|
|||
device_features = _hidpp10.get_device_features(dev)
|
||||
if device_features is not None:
|
||||
if device_features:
|
||||
device_features_names = hidpp10_constants.DEVICE_FEATURES.flag_names(device_features)
|
||||
device_features_names = hidpp10_constants.DeviceFeature.flag_names(device_features)
|
||||
print(f" Features: {', '.join(device_features_names)} (0x{device_features:06X})")
|
||||
else:
|
||||
print(" Features: (none)")
|
||||
|
|
Loading…
Reference in New Issue