From e202e904b4472585a51326549cbc28baf860dced Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sat, 23 Mar 2024 20:16:44 -0400 Subject: [PATCH] settings: add settings for RGB EFFECTS feature --- lib/logitech_receiver/hidpp20.py | 3 ++ lib/logitech_receiver/settings_templates.py | 52 +++++++++++++++------ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 566f8fdd..b19d3196 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -980,6 +980,9 @@ class LEDEffectSetting: # an effect plus its parameters def to_yaml(cls, dumper, data): return dumper.represent_mapping("!LEDEffectSetting", data.__dict__, flow_style=True) + def __eq__(self, other): + return type(self) == type(other) and self.to_bytes() == other.to_bytes() + def __str__(self): return _yaml.dump(self, width=float("inf")).rstrip("\n") diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py index c1dbb9cc..d6a4d6c4 100644 --- a/lib/logitech_receiver/settings_templates.py +++ b/lib/logitech_receiver/settings_templates.py @@ -1455,17 +1455,6 @@ class ADCPower(_Setting): validator_options = {"byte_count": 1} -class LEDControl(_Setting): - name = "led_control" - label = _("LED Control") - description = _("Switch control of LEDs between device and Solaar") - feature = _F.COLOR_LED_EFFECTS - rw_options = {"read_fnid": 0x70, "write_fnid": 0x80} - choices_universe = _NamedInts(Device=0, Solaar=1) - validator_class = _ChoicesV - validator_options = {"choices": choices_universe} - - class BrightnessControl(_Setting): name = "brightness_control" label = _("Brightness Control") @@ -1510,6 +1499,17 @@ class BrightnessControl(_Setting): return validator +class LEDControl(_Setting): + name = "led_control" + label = _("LED Control") + description = _("Switch control of LEDs between device and Solaar") + feature = _F.COLOR_LED_EFFECTS + rw_options = {"read_fnid": 0x70, "write_fnid": 0x80} + choices_universe = _NamedInts(Device=0, Solaar=1) + validator_class = _ChoicesV + validator_options = {"choices": choices_universe} + + colors = _special_keys.COLORS _LEDP = hidpp20.LEDParam @@ -1529,12 +1529,12 @@ class LEDZoneSetting(_Setting): possible_fields = [color_field, speed_field, period_field, intensity_field, ramp_field] @classmethod - def build(cls, device): + def setup(cls, device, read_fnid, write_fnid): infos = device.led_effects settings = [] for zone in infos.zones: prefix = _int2bytes(zone.index, 1) - rw = _FeatureRW(_F.COLOR_LED_EFFECTS, read_fnid=0xE0, write_fnid=0x30, prefix=prefix) + rw = _FeatureRW(cls.feature, read_fnid, write_fnid, prefix=prefix) validator = _HeteroV(data_class=hidpp20.LEDEffectSetting, options=zone.effects, readable=infos.readable) setting = cls(device, rw, validator) setting.name = cls.name + str(int(zone.location)) @@ -1546,6 +1546,32 @@ class LEDZoneSetting(_Setting): settings.append(setting) return settings + @classmethod + def build(cls, device): + return cls.setup(device, 0xE0, 0x30) + + +class RGBControl(_Setting): + name = "rgb_control" + label = _("RGB Control") + description = _("Switch control of RGB zones between device and Solaar") + feature = _F.RGB_EFFECTS + rw_options = {"read_fnid": 0x50, "write_fnid": 0x50} + choices_universe = _NamedInts(Device=0, Solaar=1) + validator_class = _ChoicesV + validator_options = {"choices": choices_universe, "write_prefix_bytes": b"\x01", "read_skip_byte_count": 1} + + +class RGBEffectSetting(LEDZoneSetting): + name = "rgb_zone_" + label = _("RGB Zone Effects") + description = _("Set effect for RGB Zone") + feature = _F.RGB_EFFECTS + + @classmethod + def build(cls, device): + return cls.setup(device, 0xE0, 0x10) + SETTINGS = [ RegisterHandDetection, # simple