julianschill / klipper-led_effect

LED effects plugin for klipper
GNU General Public License v3.0
645 stars 117 forks source link

Allow layer definitions to be processed as templates #173

Closed voidtrance closed 4 months ago

voidtrance commented 4 months ago

This PR includes two commits that:

  1. add the ability to process the layer definitions as Jinja2 templates just like any other Klipper macro. All of the normal objects available to macros are also available to layers.
  2. allow passing of parameters to the layer templates through the SET_LED_EFFECT command.

As an example, the following layer definition:

[led_effect test1]
autostart: false
heater: extruder
leds:
  neopixel:case_lights
layers:
  {% set min_temp = printer.configfile.settings.extruder.min_extrude_temp %}
  heater {min_temp} 0 add (1,0,0)

will result in the following layer being defined:

heater 170.0 0 add (1,0,0)

Layers are then processed as normal.

It is also possible to have layers be re-evaluated when an effect is enabled (this is required for layer parameters to be processed). This has the benefit of using the current printer state. However, it will use CPU cycles to re-compute the layers.