From 0548bde44fb5e19045708cca5990b37b3e332355 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sun, 4 Feb 2024 20:51:42 -0500 Subject: [PATCH] ui: handle onboard profiles notifications --- lib/logitech_receiver/notifications.py | 34 +++++++++++++++++++++ lib/logitech_receiver/settings_templates.py | 2 ++ 2 files changed, 36 insertions(+) diff --git a/lib/logitech_receiver/notifications.py b/lib/logitech_receiver/notifications.py index 77c7f95e..eaca1a7c 100644 --- a/lib/logitech_receiver/notifications.py +++ b/lib/logitech_receiver/notifications.py @@ -453,5 +453,39 @@ def _process_feature_notification(device, status, n, feature): if _log.isEnabledFor(_INFO): _log.info('%s: unknown WHEEL %s', device, n) + elif feature == _F.ONBOARD_PROFILES: + if (n.address > 0x10): + if _log.isEnabledFor(_INFO): + _log.info('%s: unknown ONBOARD PROFILES %s', device, n) + else: + if (n.address == 0x00): + resolution_index = None + profile_sector = _unpack('!H', n.data[:2])[0] + elif (n.address == 0x10): + resolution_index = _unpack('!B', n.data[:1])[0] + profile_sector = _unpack('!H', device.feature_request(_F.ONBOARD_PROFILES, 0x40)[:2])[0] + if profile_sector: + profile_change(device, profile_sector, resolution_index) + _diversion.process_notification(device, status, n, feature) return True + + +# change UI to show result of onboard profile change +def profile_change(device, profile_sector, resolution_index=None): + from solaar.ui.config_panel import record_setting # prevent circular import + setting = next((s for s in device.settings if s.name == _st.OnboardProfiles.name), None) + if setting: + record_setting(device, setting, [profile_sector]) + from solaar.ui.config_panel import record_setting # prevent circular import + for profile in device.profiles.profiles.values() if device.profiles else []: + if profile.sector == profile_sector: + if resolution_index is None: + resolution_index = profile.resolution_default_index + setting = next((s for s in device.settings if s.name == _st.AdjustableDpi.name), None) + if setting: + record_setting(device, setting, [profile.resolutions[resolution_index]]) + setting = next((s for s in device.settings if s.name == _st.ReportRate.name), None) + if setting: + record_setting(device, setting, [profile.report_rate]) + break diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py index 0ac0002d..74fe87d3 100644 --- a/lib/logitech_receiver/settings_templates.py +++ b/lib/logitech_receiver/settings_templates.py @@ -466,11 +466,13 @@ class OnboardProfiles(_Setting): return b'\x00\x00' def write(self, device, data_bytes): + from . import notifications as _notifications # prevent circular import if data_bytes == b'\x00\x00': result = device.feature_request(_F.ONBOARD_PROFILES, 0x10, b'\x02') else: device.feature_request(_F.ONBOARD_PROFILES, 0x10, b'\x01') result = device.feature_request(_F.ONBOARD_PROFILES, 0x30, data_bytes) + _notifications.profile_change(device, _bytes2int(data_bytes)) return result class validator_class(_ChoicesV):