diff --git a/docs/LED_Effect.md b/docs/LED_Effect.md index 62796ef..7c736bb 100644 --- a/docs/LED_Effect.md +++ b/docs/LED_Effect.md @@ -126,6 +126,11 @@ below): `STOP_LED_EFFECTS LEDS="neopixel:panel_ring (1-7)"`. Only one LED parameter can be specified at a time. To stop the effects for multiple LEDs we have to run the command multiple times. +Currently active effects can be listed with the GCode command `QUERY_LED_EFFECTS`. +To only show effects for certain LEDs we can specify the LEDS parameter: +`QUERY_LED_EFFECTS LEDS="neopixel:panel_ring"`. You can also specify indeces +here just like with the `STOP_LED_EFFECTS` command. + #### Fading in and out Effects can be faded in and out by specifying the `FADETIME` parameter: `SET_LED_EFFECT EFFECT=panel_idle FADETIME=1.0` fades the effect in during one diff --git a/src/led_effect.py b/src/led_effect.py index 949764e..0ebdbba 100644 --- a/src/led_effect.py +++ b/src/led_effect.py @@ -85,9 +85,13 @@ def __init__(self, config): self.gcode.register_command('STOP_LED_EFFECTS', self.cmd_STOP_LED_EFFECTS, desc=self.cmd_STOP_LED_EFFECTS_help) + self.gcode.register_command('QUERY_LED_EFFECTS', + self.cmd_QUERY_LED_EFFECTS, + desc=self.cmd_QUERY_LED_EFFECTS_help) self.shutdown = False cmd_STOP_LED_EFFECTS_help = 'Stops all led_effects' + cmd_QUERY_LED_EFFECTS_help = 'List active led_effects' def _handle_ready(self): self.shutdown = False @@ -295,6 +299,31 @@ def cmd_STOP_LED_EFFECTS(self, gcmd): effect.set_fade_time(gcmd.get_float('FADETIME', 0.0)) effect.set_enabled(False) + def cmd_QUERY_LED_EFFECTS(self, gcmd): + ledParam = gcmd.get('LEDS', "") + listAll = (ledParam == "") + + for effect in self.effects: + listEffect = listAll + if not listAll: + try: + chainName, ledIndices = self.parse_chain(ledParam) + chain = self.printer.lookup_object(chainName) + except Exception as e: + raise gcmd.error("Unknown LED '%s'" % (ledParam,)) + + if ledIndices == [] and chain in effect.ledChains: + listEffect = True + else: + for index in ledIndices: + if (chain,index) in effect.leds: + listEffect=True + + if listEffect: + if effect.enabled: + chainName, _ = self.parse_chain(ledParam) + self.gcode.respond_info("Active effect: %s" % effect.name) + def load_config(config): return ledFrameHandler(config)