I’d like to run gcode when the idle_timeout state goes from Idle
to Ready
or Idle
to Printing
. I could do with this with delayed gcode, but that feels sloppy and I hate to keep polling for a status change when I could simply react to an event in Python.
I’d happily modify idle_timeout.py
to add something like on_ready_gcode:
, etc., as this extra already has all of the state information and hooking into the other events would be simple. Assuming all of contributor requirements are met, is this a PR that would likely be accepted?
Alternately, I could simply write a new onready.py
extra (for example), and essentially duplicate idle_timeout.py
, but this seems highly redundant. I could submit it for a PR if this seems like a desired function, or simply maintain it separately like a lot of the other extras, with the upside being that klippy updates wouldn’t wipe it out.
An obvious use case affecting more than 100 users would be, for example, to enable LEDs as soon as the printer leaves the idle state (“as soon as” meaning after finishing any gcode that un-idled the printer, that is).
What’s the preferred path here?
I’ve decided to with a new host module.
If you want it for LED or fan control it’s accually already possible by using templates. It’s seems to be not well known, I havn’t seen much discussion about templates.
This example will turn off a chamber light when the printer is idle and turn it on when any other state (Printing, Ready)
Lets say you have a chamber LED connected to a pin, a white LED strip to PD15:
[led chamber]
white_pin: PD15
You then need to define a LED template using the display template configuration:
[display_template chamber_dynamic]
text:
{% if printer.idle_timeout.state == "Idle" %} # check if printer state is idle
0.0 0.0 0.0 0.0 # RGBW values when idle, all 0 = off
{% else %}
0.0 0.0 0.0 1.0 # RGBW values when not idle, white at full brightness
{% endif %}
At last you need to activate the template for your LED, this can be done automatically at startup with delayed_gcode:
[delayed_gcode set_chamber_template]
initial_duration: 1 #set template 1 second after startup
gcode:
SET_LED_TEMPLATE LED=chamber TEMPLATE=chamber_dynamic
The only downside of using led templates is that once a template is set, it’s not possible to manually adjust the LED from a UI as Mainsail, the template will overide any user setting each 0.5 second. You first need to un-set the template to be able to control it manually if needed:
SET_LED_TEMPLATE LED=chamber TEMPLATE=