Skip to content

Commit fcbccdb

Browse files
committed
feat(extras): extras from master
Implement fan and stepper extra macros from the master branch.
1 parent 8659df6 commit fcbccdb

File tree

1 file changed

+120
-24
lines changed

1 file changed

+120
-24
lines changed

klipper/klippy/extras/print_extras.cfg

Lines changed: 120 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,71 @@ gcode:
151151
SET_VELOCITY_LIMIT
152152
{% endif %}
153153

154+
################################
155+
######## FAN OVERRIDES #########
156+
################################
157+
# Allow SET_FAN_SPEED to be used for part-cooling fan
158+
# If the FAN parameter is not provided or set to 'fan', use part-cooling fan
159+
[gcode_macro SET_FAN_SPEED]
160+
rename_existing: BASE_SET_FAN_SPEED
161+
gcode:
162+
{% if 'FAN' in params %} ; FAN is specified
163+
{% if params.FAN|upper == 'FAN' %} ; If FAN is part-cooling fan
164+
{% if 'SPEED' in params %} ; SPEED parameter specified
165+
{% set S = params.SPEED|float * 255 %} ; Convert 0-1.0 to 0-255
166+
M106 S{S} ; Set part-cooling fan speed
167+
{% else %} ; SPEED not provided, turn off fan
168+
M106 S0 ; Turn off part-cooling fan
169+
{% endif %}
170+
{% endif %}
171+
{% else %} ; FAN parameter not provided
172+
{% if 'SPEED' in params %} ; Assume part-cooling fan
173+
{% set S = params.SPEED|float * 255 %} ; Convert 0-1.0 to 0-255
174+
M106 S{S} ; Set part-cooling fan speed
175+
{% elif rawparams == '' %} ; No parameters provided
176+
M106 S0 ; Turn off part-cooling fan
177+
{% else %} ; Assume pin/template format
178+
BASE_SET_FAN_SPEED {rawparams} ; Use original command
179+
{% endif %}
180+
{% endif %}
181+
182+
################################
183+
##### Extended Fan Control #####
184+
################################
185+
#[gcode_macro M106]
186+
#description: Set fan speed
187+
#rename_existing: M106.0
188+
#gcode:
189+
# {% set fans = printer['gcode_macro _setup_extra_fans'].fans %}
190+
# {% set fan_idx = params.P|default(0)|int %}
191+
# {% if fan_idx == 0 %}
192+
# M106.0 {rawparams}
193+
# {% else %}
194+
# {% set fan_idx = fan_idx - 1 %}
195+
# {% set array_len = fans|length %}
196+
# {% if fan_idx < array_len %}
197+
# {% set fan_name = fans[fan_idx] %}
198+
# SET_FAN_SPEED FAN={fan_name} SPEED={ ((params.S|int)/255)|default(0) }
199+
# {% endif %}
200+
# {% endif %}
201+
154202
################################
155203
####### HEATER_OVERIDES ########
156204
################################
157-
## Replaces M109/M190 with TEMPERATURE_WAIT commands
205+
206+
## Replace M104 with SET_HEATER_TEMP command
207+
[gcode_macro M104]
208+
rename_existing: M99104
209+
gcode:
210+
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
211+
{% set config = printer.configfile.settings %} ; get realtime configfile settings
212+
#Parameters
213+
{% set s = params.S|float %}
214+
#Active extruder
215+
{% set t = printer.toolhead.extruder %}
216+
SET_HEATER_TEMPERATURE HEATER={t} TARGET={s}
217+
218+
## Replaces M109 with TEMPERATURE_WAIT command
158219
## This will result in less time spent stabilizing the temps
159220
[gcode_macro M109]
160221
rename_existing: M99109
@@ -164,6 +225,9 @@ gcode:
164225
{% if s != 0 %}
165226
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={s} MAXIMUM={s+1} ; Wait for hotend temp (within 1 degree)
166227
{% endif %}
228+
229+
## Replaces M190 with TEMPERATURE_WAIT command
230+
## This will result in less time spent stabilizing the temps
167231
#[gcode_macro M190]
168232
#rename_existing: M99190
169233
#gcode:
@@ -181,11 +245,17 @@ description: PID Tune for the Extruder
181245
gcode:
182246
{% set e = printer.toolhead.extruder %} ; get current extruder
183247
{% set T = params.TEMPERATURE|default(210)|float %} ; get target temperature
184-
{% set S = params.FAN_IN_PERCENT|default(0)|float *2.55 %} ; get fan speed
248+
{% if 'FAN_IN_PERCENT' in params %}
249+
{% set S = params.FAN_IN_PERCENT|float * 2.55 %} ; get 0-100% fan speed
250+
{% elif 'FAN' in params %}
251+
{% set S = params.FAN|float * 255 %} ; get 0-1.0 fan speed
252+
{% else %}
253+
{$ set S = printer.fan.speed * 255 %} ; get current fan speed (0-1.0)
254+
{% endif %}
185255
{% set P = printer.configfile.config[e].pid_kp|float %} ; get PID parameters
186256
{% set I = printer.configfile.config[e].pid_ki|float %} ; get PID parameters
187257
{% set D = printer.configfile.config[e].pid_kd|float %} ; get PID parameters
188-
M106 S{S} ; Turn on fan
258+
M106 S{S|int} ; Turn on fan
189259
M118 // PID parameters: pid_Kp={P} pid_Ki={I} pid_Kd={D} (old) ; Display old PID parameters
190260
PID_CALIBRATE HEATER={e} TARGET={T} ; PID Tune the extruder
191261
TURN_OFF_HEATERS ; Turn off heaters
@@ -196,11 +266,17 @@ description: Hotend PID Tune
196266
gcode:
197267
{% set e = params.E|default(0)|int %} ; get extruder
198268
{% set t = params.T|default(210)|float %} ; get target temperature
199-
{% set S = params.FAN_IN_PERCENT|default(0)|float *2.55 %} ; get fan speed
269+
{% if 'FAN_IN_PERCENT' in params %}
270+
{% set S = params.FAN_IN_PERCENT|float * 2.55 %} ; get 0-100% fan speed
271+
{% elif 'FAN' in params %}
272+
{% set S = params.FAN|float * 255 %} ; get 0-1.0 fan speed
273+
{% else %}
274+
{$ set S = printer.fan.speed * 255 %} ; get current fan speed (0-1.0)
275+
{% endif %}
200276
{% set P = printer.configfile.config[e].pid_kp|float %} ; get PID parameters
201277
{% set I = printer.configfile.config[e].pid_ki|float %} ; get PID parameters
202278
{% set D = printer.configfile.config[e].pid_kd|float %} ; get PID parameters
203-
M106 S{S} ; Turn on fan
279+
M106 S{S|int} ; Turn on fan
204280
M118 // PID parameters: pid_Kp={P} pid_Ki={I} pid_Kd={D} (old) ; Display old PID parameters
205281
{% if e == 0 %}
206282
{% set e = printer.toolhead.extruder %} ; get current extruder
@@ -234,6 +310,45 @@ gcode:
234310
M118 // Previous PID parameters: pid_Kp={P} pid_Ki={I} pid_Kd={D} ; Display old PID parameters
235311
PID_CALIBRATE HEATER=heater_bed TARGET={t} ; PID Tune the bed
236312

313+
[gcode_macro M84]
314+
description: Disable steppers
315+
variable_timer_params: ""
316+
rename_existing: M84.1
317+
gcode:
318+
{% set timer_params = rawparams %}
319+
SET_GCODE_VARIABLE MACRO=M84 VARIABLE=timer_params VALUE="'{timer_params}'" ; Set timer params
320+
{ action_respond_info("rawparams: %s" % (timer_params)) }
321+
{% set step_delay = params.S|default(0)|int %}
322+
{% if step_delay > 0 %}
323+
UPDATE_DELAYED_GCODE ID=stepper_timer DURATION={step_delay}
324+
{ action_respond_info("timer started: %d" % (step_delay)) }
325+
{% else %}
326+
{% if "X" in rawparams%} SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=0 {% endif %}
327+
{% if "Y" in rawparams%} SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=0 {% endif %}
328+
{% if "Z" in rawparams%} SET_STEPPER_ENABLE STEPPER=stepper_z ENABLE=0 {% endif %}
329+
{% if "E" in rawparams%} SET_STEPPER_ENABLE STEPPER=extruder ENABLE=0 {% endif %}
330+
{% if rawparams == "" %} M84.1 {% endif %}
331+
{% endif %}
332+
333+
[gcode_macro M18]
334+
description: Disable steppers
335+
rename_existing: M18.1
336+
gcode:
337+
M84 {rawparams}
338+
339+
[delayed_gcode stepper_timer]
340+
initial_duration: 0.0
341+
gcode:
342+
{% set timer_params = printer['gcode_macro M84'].timer_params %}
343+
{ action_respond_info("Stepper timer expired.") }
344+
{ action_respond_info("params: %s" % (timer_params)) }
345+
{% if "X" in timer_params%} SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=0 {% endif %}
346+
{% if "Y" in timer_params%} SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=0 {% endif %}
347+
{% if "Z" in timer_params%} SET_STEPPER_ENABLE STEPPER=stepper_z ENABLE=0 {% endif %}
348+
{% if "E" in timer_params%} SET_STEPPER_ENABLE STEPPER=extruder ENABLE=0 {% endif %}
349+
UPDATE_DELAYED_GCODE ID=stepper_timer DURATION=0
350+
351+
237352
[gcode_macro M104]
238353
rename_existing: M99104
239354
gcode:
@@ -245,22 +360,3 @@ gcode:
245360
{% set t = printer.toolhead.extruder %}
246361
SET_HEATER_TEMPERATURE HEATER={t} TARGET={s}
247362

248-
################################
249-
##### Extended Fan Control #####
250-
################################
251-
[gcode_macro M106]
252-
description: Set fan speed
253-
rename_existing: M106.0
254-
gcode:
255-
{% set fans = printer['gcode_macro _setup_extra_fans'].fans %}
256-
{% set fan_idx = params.P|default(0)|int %}
257-
{% if fan_idx == 0 %}
258-
M106.0 {rawparams}
259-
{% else %}
260-
{% set fan_idx = fan_idx - 1 %}
261-
{% set array_len = fans|length %}
262-
{% if fan_idx < array_len %}
263-
{% set fan_name = fans[fan_idx] %}
264-
SET_FAN_SPEED FAN={fan_name} SPEED={ ((params.S|int)/255)|default(0) }
265-
{% endif %}
266-
{% endif %}

0 commit comments

Comments
 (0)