From c11d585578754fdac22b2f5c9cbc0b221edd376a Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Tue, 30 Jan 2024 00:06:41 -0500 Subject: [PATCH] device: support backlight levels and duration --- lib/logitech_receiver/device.py | 8 ++ lib/logitech_receiver/hidpp20.py | 29 ++++ lib/logitech_receiver/settings.py | 1 + lib/logitech_receiver/settings_templates.py | 141 +++++++++++++++++++- 4 files changed, 178 insertions(+), 1 deletion(-) diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py index dc21c1781..cb029c596 100644 --- a/lib/logitech_receiver/device.py +++ b/lib/logitech_receiver/device.py @@ -79,6 +79,7 @@ def __init__( self._remap_keys = None self._gestures = None self._gestures_lock = _threading.Lock() + self._backlight = None self._registers = None self._settings = None self._feature_settings_checked = False @@ -315,6 +316,13 @@ def gestures(self): self._gestures = _hidpp20.get_gestures(self) or () return self._gestures + @property + def backlight(self): + if self._backlight is None: + if self.online and self.protocol >= 2.0: + self._backlight = _hidpp20.get_backlight(self) + return self._backlight + @property def registers(self): if not self._registers: diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 076dbc4d4..ed47fdb74 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -1117,6 +1117,28 @@ def set_param(self, param, value): return g.set(self.device, value) if g else None +class Backlight: + """Information about the current settings of x1982 Backlight2 v3, but also works for previous versions""" + + def __init__(self, device): + response = device.feature_request(FEATURE.BACKLIGHT2, 0x00) + if not response: + raise FeatureCallError(msg='No reply from device.') + self.device = device + self.enabled, self.options, supported, self.effects, self.level, self.dho, self.dhi, self.dpow = _unpack( + '> 3) & 0x03 + + def write(self): + self.options = (self.options & 0x03) | (self.mode << 3) + data_bytes = _pack(' device.features.get_feature_version(sclass.feature): + return try: detected = sclass.build(device) if _log.isEnabledFor(_DEBUG):