I’d like to create a gcode macro that repeats some code based on time.
Time would be a passed parameter S3 = 3 seconds.
Is this possible without using a delayed gcode macro, which auto-starts?
Thanks!
I’d like to create a gcode macro that repeats some code based on time.
Time would be a passed parameter S3 = 3 seconds.
Is this possible without using a delayed gcode macro, which auto-starts?
Thanks!
If you set initial_duration to 0 in your [delayed_gcode] config, than this gcode will not automatically start.
Now you can use UPDATE_DELAYED_GCODE from another macro to start/stop the repeated execution and change the delay of your delayed_gcode macro.
Is that what you are looking for?
Simon
Thank you @simonkuehling that is getting me moving in the proper direction.
Here is what I have now:
[gcode_macro M155]
description: Mimics Marlin code to output temp's on a 'S'chedule.
gcode:
{% if 'S' in params %}
{% set seconds = params.S|float %}
UPDATE_DELAYED_GCODE ID=respond_temp_timer DURATION={seconds} S={seconds}
{% endif %}
[delayed_gcode respond_temp_timer]
initial_duration: 0
gcode:
SET_LED LED=grandcentral_neopixel RED=1.00 GREEN=1.00 BLUE=0.00 INDEX=1
G4 P100
SET_LED LED=grandcentral_neopixel RED=0.00 GREEN=1.00 BLUE=0.00 INDEX=1
G4 P100
UPDATE_DELAYED_GCODE ID=respond_temp_timer DURATION=2
When I send a M155 S5
to the console, the delayed g-code executes 5 seconds later and ever 2 seconds thereafter. I want to pass the {seconds}
value up to the delayed g-code DURATION
so the repeat will be valid there as well.
Any suggestions on how to do that?
Sure, that ist possible as well - you can use SET_GCODE_VARIABLE
to change a variable inside of another macro like this:
[gcode_macro M155]
description: Mimics Marlin code to output temp's on a 'S'chedule.
gcode:
{% if 'S' in params %}
{% set seconds = params.S|float %}
SET_GCODE_VARIABLE MACRO=respond_temp_timer VARIABLE=delay VALUE={seconds}
UPDATE_DELAYED_GCODE ID=respond_temp_timer DURATION={seconds}
{% endif %}
[delayed_gcode respond_temp_timer]
initial_duration: 0
variable_delay: 0
gcode:
SET_LED LED=grandcentral_neopixel RED=1.00 GREEN=1.00 BLUE=0.00 INDEX=1
G4 P100
SET_LED LED=grandcentral_neopixel RED=0.00 GREEN=1.00 BLUE=0.00 INDEX=1
G4 P100
UPDATE_DELAYED_GCODE ID=respond_temp_timer DURATION={delay}
Great! I was just looking at that myself… I did the same, but put the variable in the M155 gcode_macro:
[gcode_macro M155]
description: Mimics Marlin code to output temp's on a 'S'chedule.
variable_repeat_timer: 0
gcode:
{% if 'S' in params %}
{% set seconds = params.S|int %}
#RESPOND MSG="time in seconds:"{seconds}
SET_GCODE_VARIABLE MACRO=M155 VARIABLE=repeat_timer VALUE={seconds}
UPDATE_DELAYED_GCODE ID=respond_temp_timer DURATION={seconds}
{% endif %}
[delayed_gcode respond_temp_timer]
initial_duration: 0
gcode:
# {% set time = params.VALUE|int %}
# RESPOND MSG="time2 in seconds:"{params.REPEAT}%
SET_LED LED=grandcentral_neopixel RED=1.00 GREEN=1.00 BLUE=0.00 INDEX=1
G4 P100
SET_LED LED=grandcentral_neopixel RED=0.00 GREEN=1.00 BLUE=0.00 INDEX=1
G4 P100
UPDATE_DELAYED_GCODE ID=respond_temp_timer DURATION={printer['gcode_macro M155'].repeat_timer}
Now when I pass M155 S5
, the neopixel blinks yellow then green every 5 seconds until I send a M155 S0
, which stops it.
Now time to apply it to some real-world situations, like adjusting neopixel’s to the temp of a heater until printing starts/stops, then make it white.
Was actually looking to do this so that the developer of OctoPod can trigger it in Klipper and pull additional temps into the iPhone app.
Thanks for your help @simonkuehling