-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbed_cooldown.cfg
167 lines (134 loc) · 6.85 KB
/
bed_cooldown.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
[gcode_macro KILL_DELAYED_BED_COOLDOWN]
gcode:
UPDATE_DELAYED_GCODE ID=_DELAYED_BED_COOLDOWN DURATION=0
[delayed_gcode _DELAYED_BED_COOLDOWN]
gcode:
# Get global parameter
{% set slicer_time_estimated = printer["gcode_macro ENABLE_BED_COOLDOWN"].slicer_time_estimated %}
{% set elapsed_time_threshold = printer["gcode_macro ENABLE_BED_COOLDOWN"].elapsed_time_threshold %}
{% set remain_time_threshold = printer["gcode_macro ENABLE_BED_COOLDOWN"].remain_time_threshold %}
{% set progress_threshold = printer["gcode_macro ENABLE_BED_COOLDOWN"].progress_threshold %}
{% set progress_type = printer["gcode_macro ENABLE_BED_COOLDOWN"].progress_type %}
{% set target_temp = printer["gcode_macro ENABLE_BED_COOLDOWN"].target_temp %}
{% set debug = printer["gcode_macro ENABLE_BED_COOLDOWN"].debug|lower %}
# Set elapsed time
{% set elapsed_time = printer.print_stats.print_duration %}
# Calculate remain time
{% set remain_time = slicer_time_estimated - elapsed_time %}
# Set/Calculate progress
{% if progress_type|lower == "virtual_sdcard" %}
{% set progress = printer.virtual_sdcard.progress * 100 %}
{% elif progress_type|lower == "display_status" %}
{% set progress = printer.display_status.progress * 100 %}
{% elif progress_type|lower == "time" %}
{% set progress = elapsed_time / slicer_time_estimated * 100 %}
{% else %}
{% set progress = elapsed_time / slicer_time_estimated * 100%}
{% endif %}
# Check if thresholds are reached or reschedule
{% if progress >= progress_threshold and elapsed_time > elapsed_time_threshold and remain_time < remain_time_threshold %}
# Print user info
M117 Reached bed cooldown limits (see console log). Set bed temperature to: {target_temp}°C
M118
M118 Reached bed cooldown limits:
M118 Elapsed time: {elapsed_time|round(0)|int}s (threshold: >{elapsed_time_threshold}s)
M118 Remain time: {remain_time|round(0)|int}s (threshold: <{remain_time_threshold}s)
M118 Progress: {progress|round(0)|int}% (threshold: >{progress_threshold}%)
M118 Setting bed temperature to: {target_temp}°C
M118
# Set bed temperature without wait
M140 S{target_temp}
# Cancel delayed gcode
UPDATE_DELAYED_GCODE ID=_DELAYED_BED_COOLDOWN DURATION=0
{% else %}
# Print data on debug
{% if debug == "true" %}
M118
M118 slicer_time_estimated: {slicer_time_estimated}
M118 elapsed_time_threshold: {elapsed_time_threshold}
M118 remain_time_threshold: {remain_time_threshold}
M118 progress_threshold: {progress_threshold}
M118 progress_type: {progress_type}
M118 progress_virtual_sd: {(printer.virtual_sdcard.progress * 100)|round(0)|int}
M118 progress_display_stats: {(printer.display_status.progress * 100)|round(0)|int}
M118 progress_time: {(elapsed_time / slicer_time_estimated * 100)|round(0)|int}
M118 target_temp: {target_temp}
M118 elapsed_time: {elapsed_time}
M118 remain_time: {remain_time}
{% if progress >= progress_threshold %}
M118 progress >= progress_threshold : TRUE
{% else %}
M118 progress >= progress_threshold : FALSE
{% endif %}
{% if elapsed_time > elapsed_time_threshold %}
M118 elapsed_time > elapsed_time_threshold : TRUE
{% else %}
M118 elapsed_time > elapsed_time_threshold : FALSE
{% endif %}
{% if remain_time < remain_time_threshold %}
M118 remain_time < remain_time_threshold : TRUE
{% else %}
M118 remain_time < remain_time_threshold : FALSE
{% endif %}
M118
{% endif %}
# Criteria was not met. Reschedule delayed gcode
UPDATE_DELAYED_GCODE ID=_DELAYED_BED_COOLDOWN DURATION=15
{% endif %}
[gcode_macro ENABLE_BED_COOLDOWN]
description: Initialize Bed Cooldown towards end of the print
variable_slicer_time_estimated: 0
variable_elapsed_time_threshold: 900
variable_remain_time_threshold: 900
variable_progress_threshold: 90
variable_progress_type: "time" # One of ["virtual_sdcard", "display_status", "time"]
# virtual_sdcard = The progress value of the last M73 G-Code command (or virtual_sdcard.progress if no recent M73 received).
# display_status = An estimate of the current print progress (based of file size and file position).
# time = Elapsed time / Slicer Estimated Time * 100
variable_target_temp: 0
variable_debug: "false"
gcode:
# Check if SLICER_TIME_ESTIMATED was passed (only metric, which has no default and is dependent from the model)
{% if not params.SLICER_TIME_ESTIMATED %}
M118 SLICER_TIME_ESTIMATED *NOT* passed. No delayed bed cooldown ...
{% else %}
# Get passed parameter
{% set slicer_time_estimated = params.SLICER_TIME_ESTIMATED|int %}
{% set elapsed_time_threshold = params.ELAPSED_TIME_THRESHOLD|default(900)|int %}
{% set remain_time_threshold = params.REMAIN_TIME_THRESHOLD|default(900)|int %}
{% set progress_threshold = params.PROGRESS_THRESHOLD|default(90)|int %}
{% set progress_type = params.PROGRESS_TYPE|default("time") %}
{% set target_temp = params.TARGET_TEMP|default(0)|int %}
{% set debug = params.DEBUG|default("false") %}
# Validate passed parameter
{% if target_temp < 0 %}
{% set target_temp = 0 %}
{% elif target_temp > 230 %}
{% set target_temp = 230 %}
{% endif %}
{% if progress_threshold < 0 %}
{% set progress_threshold = 0 %}
{% elif progress_threshold > 100 %}
{% set progress_threshold = 100 %}
{% endif %}
{% if remain_time_threshold < 0 %}
{% set remain_time_threshold = 0 %}
{% endif %}
{% if elapsed_time_threshold < 0 %}
{% set elapsed_time_threshold = 0 %}
{% endif %}
# Reset current delayed gcode (if one is already running)
UPDATE_DELAYED_GCODE ID=_DELAYED_BED_COOLDOWN DURATION=0
# Update variables
SET_GCODE_VARIABLE MACRO=ENABLE_BED_COOLDOWN VARIABLE=slicer_time_estimated VALUE={slicer_time_estimated}
SET_GCODE_VARIABLE MACRO=ENABLE_BED_COOLDOWN VARIABLE=elapsed_time_threshold VALUE={elapsed_time_threshold}
SET_GCODE_VARIABLE MACRO=ENABLE_BED_COOLDOWN VARIABLE=remain_time_threshold VALUE={remain_time_threshold}
SET_GCODE_VARIABLE MACRO=ENABLE_BED_COOLDOWN VARIABLE=progress_threshold VALUE={progress_threshold}
SET_GCODE_VARIABLE MACRO=ENABLE_BED_COOLDOWN VARIABLE=progress_type VALUE='"{progress_type}"'
SET_GCODE_VARIABLE MACRO=ENABLE_BED_COOLDOWN VARIABLE=target_temp VALUE={target_temp}
SET_GCODE_VARIABLE MACRO=ENABLE_BED_COOLDOWN VARIABLE=debug VALUE='"{debug}"'
# Start delayed Bed Cooldown
UPDATE_DELAYED_GCODE ID=_DELAYED_BED_COOLDOWN DURATION=15
M117 Kicked _DELAYED_BED_COOLDOWN (Cancel with 'UPDATE_DELAYED_GCODE ID=_DELAYED_BED_COOLDOWN DURATION=0')
M118 Kicked _DELAYED_BED_COOLDOWN (Cancel with 'UPDATE_DELAYED_GCODE ID=_DELAYED_BED_COOLDOWN DURATION=0')
{% endif %}