From 8292a8612d1c4b5185df299317700109b4cd51f4 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Wed, 7 Feb 2024 11:33:36 -0500 Subject: [PATCH] device: handle v4 of profiles data --- lib/logitech_receiver/hidpp20.py | 25 +++++++++++++++------ lib/logitech_receiver/settings_templates.py | 4 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 97141b229..20f0d80fe 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -1254,7 +1254,12 @@ def to_yaml(cls, dumper, data): Previous_Profile=0x9, Cycle_Profile=0xA, G_Shift=0xB, - Battery_Status=0xC + Battery_Status=0xC, + Profile_Select=0xD, + Mode_Switch=0xE, + Host_Button=0xF, + Scroll_Down=0x10, + Scroll_Up=0x11 ) ButtonButtons = special_keys.MOUSE_BUTTONS ButtonModifiers = special_keys.modifiers @@ -1300,7 +1305,8 @@ def from_bytes(cls, bytes): result = cls(behavior=behavior, type=mapping_type, value=value) elif behavior == ButtonBehaviors.Function: value = ButtonFunctions[bytes[1]] if ButtonFunctions[bytes[1]] is not None else bytes[1] - result = cls(behavior=behavior, value=value) + data = bytes[3] + result = cls(behavior=behavior, value=value, data=data) else: result = cls(behavior=bytes[0] >> 4, bytes=bytes) return result @@ -1320,7 +1326,7 @@ def to_bytes(self): elif self.type == ButtonMappingTypes.Consumer_Key: bytes += _int2bytes(self.value, 2) elif self.behavior == ButtonBehaviors.Function: - bytes += _int2bytes(self.value, 1) + b'\xff\x00' + bytes += _int2bytes(self.value, 1) + b'\xff' + (_int2bytes(self.data, 1) if self.data else b'\x00') else: bytes = self.bytes if self.bytes else b'\xff\xff\xff\xff' return bytes @@ -1365,7 +1371,10 @@ def from_bytes(cls, sector, enabled, buttons, gbuttons, bytes): blue=bytes[15], power_mode=bytes[16], angle_snap=bytes[17], - reserved=bytes[18:32], + write_count=_unpack(' 0x03: + if memory != 0x01 or profile > 0x04: return count, oob, buttons, sectors, size, shift = _unpack('!BBBBHB', response[3:10]) gbuttons = buttons if (shift & 0x3 == 0x2) else 0 diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py index 74fe87d36..85d071055 100644 --- a/lib/logitech_receiver/settings_templates.py +++ b/lib/logitech_receiver/settings_templates.py @@ -459,8 +459,8 @@ def __init__(self, feature): def read(self, device): enabled = device.feature_request(_F.ONBOARD_PROFILES, 0x20)[0] - if enabled: - active = _unpack('!H', device.feature_request(_F.ONBOARD_PROFILES, 0x40))[0] + if enabled == 0x01: + active = device.feature_request(_F.ONBOARD_PROFILES, 0x40) return active[:2] else: return b'\x00\x00'