-
Notifications
You must be signed in to change notification settings - Fork 0
/
heatsoak.cfg
119 lines (94 loc) · 4.27 KB
/
heatsoak.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
##############
# Macro by Brian Lalor, see: https://klipper.discourse.group/t/interruptible-heat-soak/1552
##############
[gcode_macro HEAT_SOAK]
description: heats the bed for a while
variable_target_temp: 0
variable_stage: None ## heating -> soaking -> done -> None
## in seconds
variable_check_interval: 10
variable_soak_time_remaining: 0
variable_total_time_elapsed: 0
gcode:
{% set Xmid = printer.toolhead.axis_maximum.x / 2 %}
{% set Ymid = printer.toolhead.axis_maximum.y / 2 %}
{% set Zfan = printer.toolhead.axis_maximum.z / 2 %}
{% set TARGET = params.TARGET | default(115) | float %}
{% set DURATION = (params.DURATION | default(60) | int) * 60 %} ## minutes to seconds
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=target_temp VALUE={ TARGET }
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'heating'"
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ DURATION }
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE=0
;; fire up the heater
SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ TARGET }
;; run the fan to circulate air
#_SET_FAN_SPEED PERCENT=50
;; put the bed and nozzle where they're a safe distance apart
SET_IDLE_TIMEOUT TIMEOUT=3600
G28
G1 Z{Zfan} ;;move bed close to nozzle fan
M109 S0
G1 X{Xmid} Y{Ymid}
M106 S100 ;; turn on FAN
M84 ;; turn off steppers
STATUS_HEATING
nevermore_on #Turn ON venermore filter
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ check_interval }
[gcode_macro CANCEL_HEAT_SOAK]
description: cancels an in-progress HEAT_SOAK cycle
gcode:
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'cancel'"
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION=1
SET_IDLE_TIMEOUT TIMEOUT=600
M118 ‘Stop Heat Soak’
nevermore_off #Turn OFF venermore filter
M107
[delayed_gcode heat_soaker]
; ## debug
; { action_respond_info( printer['gcode_macro HEAT_SOAK'] | tojson )}
gcode:
{% set heat_soak = printer['gcode_macro HEAT_SOAK'] %}
## update total time elapsed
{% set total_time_elapsed = heat_soak.total_time_elapsed + heat_soak.check_interval %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE={ total_time_elapsed }
{% set stage = heat_soak.stage %}
{% if stage == "heating" and printer.heater_bed.temperature >= heat_soak.target_temp %}
{% set stage = "soaking" %}
{% endif %}
{% if stage == "soaking" %}
## update soak countdown
{% set soak_time_remaining = [heat_soak.soak_time_remaining - heat_soak.check_interval, 0] | max %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ soak_time_remaining }
{% if soak_time_remaining == 0 %}
{% set stage = "done" %}
{% endif %}
{% endif %}
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'{ stage }'"
{% if stage in ("done", "cancel") %}
{% if stage == "cancel" %}
{% set stage = "done" %}
TURN_OFF_HEATERS
nevermore_off #Turn OFF venermore filter
M107 ; turn off fan
M117 { "soak cancelled after ~%.1fm" | format(total_time_elapsed / 60.0) }
{% else %}
M117 { "soak complete after %.1fm" | format(total_time_elapsed / 60.0) }
{% endif %}
## reset all state vars, except stage, which may be queried via the api
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=target_temp VALUE=0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE=0
SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE=0
{% else %}
{% if total_time_elapsed % 90 == 0 %}
## output status periodically
{% if stage == "heating" %}
M117 { "heating -- %.1fm elapsed" | format(total_time_elapsed / 60.0) }
{% elif stage == "soaking" %}
M117 { "soaking -- %.1fm remaining" | format(soak_time_remaining / 60.0) }
{% endif %}
{% endif %}
## trigger ourselves again
UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ heat_soak.check_interval }
## dwell for 1ms to prevent from going idle
G4 P1
{% endif %}