From 79606c530bab21beed27c3ee724e8f4cfba6de0d Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sat, 15 May 2021 10:16:17 -0400 Subject: [PATCH] receiver: use feature numbers for reprogrammable key versions --- lib/logitech_receiver/hidpp20.py | 18 +++++++++--------- lib/solaar/cli/show.py | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 45531aa3..a689402c 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -586,10 +586,10 @@ class KeysArray: def __init__(self, device, count): assert device is not None self.device = device - if FEATURE.REPROG_CONTROLS in self.device.features: - self.keyversion = 1 - elif FEATURE.REPROG_CONTROLS_V4 in self.device.features: - self.keyversion = 4 + if FEATURE.REPROG_CONTROLS_V4 in self.device.features: + self.keyversion = FEATURE.REPROG_CONTROLS_V4 + elif FEATURE.REPROG_CONTROLS_V2 in self.device.features: + self.keyversion = FEATURE.REPROG_CONTROLS_V2 else: if _log.isEnabledFor(_ERROR): _log.error(f'Trying to read keys on device {device} which has no REPROG_CONTROLS(_VX) support.') @@ -613,13 +613,13 @@ class KeysArray: raise IndexError(index) # TODO: add here additional variants for other REPROG_CONTROLS - if self.keyversion == 1: - keydata = feature_request(self.device, FEATURE.REPROG_CONTROLS, 0x10, index) + if self.keyversion == FEATURE.REPROG_CONTROLS_V2: + keydata = feature_request(self.device, FEATURE.REPROG_CONTROLS_V2, 0x10, index) if keydata: cid, tid, flags = _unpack('!HHB', keydata[:5]) self.keys[index] = ReprogrammableKey(self.device, index, cid, tid, flags) self.cid_to_tid[cid] = tid - elif self.keyversion == 4: + elif self.keyversion == FEATURE.REPROG_CONTROLS_V4: keydata = feature_request(self.device, FEATURE.REPROG_CONTROLS_V4, 0x10, index) if keydata: cid, tid, flags1, pos, group, gmask, flags2 = _unpack('!HHBBBBB', keydata[:9]) @@ -1230,8 +1230,8 @@ def decipher_voltage(voltage_report): def get_keys(device): # TODO: add here additional variants for other REPROG_CONTROLS count = None - if FEATURE.REPROG_CONTROLS in device.features: - count = feature_request(device, FEATURE.REPROG_CONTROLS) + if FEATURE.REPROG_CONTROLS_V2 in device.features: + count = feature_request(device, FEATURE.REPROG_CONTROLS_V2) elif FEATURE.REPROG_CONTROLS_V4 in device.features: count = feature_request(device, FEATURE.REPROG_CONTROLS_V4) if count: diff --git a/lib/solaar/cli/show.py b/lib/solaar/cli/show.py index 071a3681..3bb29bbf 100644 --- a/lib/solaar/cli/show.py +++ b/lib/solaar/cli/show.py @@ -241,9 +241,9 @@ def _print_device(dev, num=None): print(' Has %d reprogrammable keys:' % len(dev.keys)) for k in dev.keys: # TODO: add here additional variants for other REPROG_CONTROLS - if dev.keys.keyversion == 1: + if dev.keys.keyversion == _hidpp20.FEATURE.REPROG_CONTROLS_V2: print(' %2d: %-26s => %-27s %s' % (k.index, k.key, k.default_task, ', '.join(k.flags))) - if dev.keys.keyversion == 4: + if dev.keys.keyversion == _hidpp20.FEATURE.REPROG_CONTROLS_V4: print(' %2d: %-26s, default: %-27s => %-26s' % (k.index, k.key, k.default_task, k.mapped_to)) gmask_fmt = ','.join(k.group_mask) gmask_fmt = gmask_fmt if gmask_fmt else 'empty'