Skip to content

Commit

Permalink
Add ability to query active effects
Browse files Browse the repository at this point in the history
  • Loading branch information
fattredd committed Nov 12, 2024
1 parent 121c9bb commit 8967af1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/LED_Effect.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/led_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8967af1

Please sign in to comment.