"""Catalog of the hardware lighting effects the K65 PLUS renders on its own.""" from __future__ import annotations from dataclasses import dataclass from . import bragi @dataclass(frozen=True) class Effect: key: str label: str fx: int max_colors: int = 0 # how many user colors the effect takes random_colors: bool = False # supports "random colors" instead of user colors speed: bool = True direction: int = 0 fixed_color_mode: int | None = None fixed_colors: tuple[bragi.Rgb, ...] = () SPEEDS = {"slow": bragi.SPEED_SLOW, "medium": bragi.SPEED_MEDIUM, "fast": bragi.SPEED_FAST} SPEED_LABELS = {"slow": "Langsam", "medium": "Mittel", "fast": "Schnell"} _WHITE = bragi.Rgb(255, 255, 255) _BLACK = bragi.Rgb(0, 0, 0) EFFECTS: dict[str, Effect] = {e.key: e for e in ( Effect("static", "Statische Farbe", bragi.FX_STATIC, max_colors=1, speed=False), Effect("rainbow_wave", "Regenbogenwelle", bragi.FX_RAINBOW_WAVE, direction=0x04), Effect("spiral_rainbow", "Spiralregenbogen", bragi.FX_SPIRAL_RAINBOW, direction=0x06), Effect("color_wave", "Farbwelle", bragi.FX_COLOR_WAVE, max_colors=2, random_colors=True, direction=0x04), Effect("color_shift", "Farbwechsel", bragi.FX_COLOR_SHIFT, max_colors=2, random_colors=True), Effect("color_pulse", "Farbpuls", bragi.FX_COLOR_PULSE, max_colors=2, random_colors=True), Effect("rain", "Regen", bragi.FX_RAIN, max_colors=2, random_colors=True, direction=0x01), Effect("watercolor", "Aquarell", bragi.FX_WATERCOLOR, fixed_color_mode=bragi.COLORS_ALT, fixed_colors=(_WHITE,)), Effect("type_key", "Tippen: Taste", bragi.FX_TYPE_KEY, max_colors=2, random_colors=True), Effect("type_ripple", "Tippen: Welle", bragi.FX_TYPE_RIPPLE, max_colors=2, random_colors=True), Effect("visor", "Visier", bragi.FX_VISOR, max_colors=2, random_colors=True), Effect("off", "Aus", bragi.FX_STATIC, speed=False, fixed_color_mode=bragi.COLORS_SPECIFIC, fixed_colors=(_BLACK,)), )} def encode(target: int, effect_key: str, colors: list[str], random: bool, speed: str) -> list[bytes]: effect = EFFECTS.get(effect_key, EFFECTS["static"]) if effect.fixed_color_mode is not None: mode, rgb = effect.fixed_color_mode, list(effect.fixed_colors) elif effect.max_colors and not (random and effect.random_colors): mode = bragi.COLORS_SPECIFIC rgb = [bragi.Rgb.from_hex(c) for c in colors[:effect.max_colors]] or [_WHITE] elif effect.random_colors: mode, rgb = bragi.COLORS_RANDOM, [] else: mode, rgb = bragi.COLORS_NONE, [] return bragi.lighting_packets( target, effect.fx, mode, SPEEDS.get(speed, bragi.SPEED_MEDIUM) if effect.speed else 0, effect.direction, rgb, )