-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprint_macros.cfg
2556 lines (2470 loc) · 124 KB
/
print_macros.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## Copyright (C) 2023 Chris Laprade ([email protected])
##
## This file is part of printcfg.
##
## printcfg is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## printcfg is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with printcfg. If not, see <http://www.gnu.org/licenses/>.
#####################################
## Print Macros ##
## Version 4.1.0 2023-7-3 ##
#####################################
[include logging.cfg]
################################
######### START_PRINT ##########
################################
[gcode_macro START_PRINT]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=starting_print VALUE=1 ; begin print_start process
## Preprint status
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_preprint} ; LED feedback
{% endif %}
## Clear paused state
CLEAR_PAUSE
## Define positioning system
G90 ; use absolute coordinates
M83 ; extruder relative mode
SET_DEFAULTS MODE=START; reset to default settings
## Preheat bed surface
HEAT_SURFACE
## Preheat/soak chamber
PREP_CHAMBER
## Prepapre fans
PREP_FANS
## Prepare bed suface
PREP_SURFACE
{% if printcfg.heat_soak_complete == 0 %}
## Pause without parking
{printcfg.pause_no_park}
{% else %}
## Wait for chamber preheat to finalize
FINALIZE_ENVIRO
{% endif %}
################################
####### SET_START_PRINT ########
################################
[gcode_macro SET_START_PRINT]
description: Set up print start variables
gcode:
################## Get PrintCFG ##################
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
################## Get Parameters ##################
## Start Temps
{% set bed_temp = params.BED_TEMP | default(printcfg.bed_temp) | float %}
{% set extruder_temp = params.EXTRUDER_TEMP | default(printcfg.extruder_temp) | float %}
{% set extruder_pre_temp = params.EXTRUDER_PRE_TEMP | default(printcfg.extruder_pre_temp) | float %}
{% set chamber_temp = params.CHAMBER_TEMP | default(printcfg.chamber_temp) | float %}
## Start Steps
{% set heat_soak = params.HEAT_SOAK | default(printcfg.heat_soak) | int %}
{% set auto_z = params.AUTO_Z | default(printcfg.auto_z_calibrate) | int %}
{% set z_tilt = params.Z_TILT | default(printcfg.z_tilt) | int %}
{% set qgl = params.QUAD_GANTRY_LEVEL | default(printcfg.qgl) | int %}
## Bed Meshing
{% set mesh = params.BED_MESH | default(printcfg.bed_mesh) | int %}
{% set adaptive_mesh = params.ADAPTIVE_MESH | default (printcfg.mesh_adaptive) | int %}
{% set load_mesh = params.LOAD_MESH | default(printcfg.load_mesh) | int %}
{% set mesh_profile = params.MESH_PROFILE | default(printcfg.mesh_profile) | string %}
## Cleaning and Purging
{% set cleaning = params.NOZZLE_BRUSH | default(printcfg.cleaning) | int %}
{% set purging = params.NOZZLE_PURGE | default(printcfg.purging) | int %}
{% set adaptive_purge = params.ADAPTIVE_PURGE | default(printcfg.adaptive_purge) | int %}
{% set nevermore = params.USE_NEVERMORE | default(printcfg.nevermore) | int %}
############## Make Strings Booleans ##############%}
{% if params.HEAT_SOAK is defined and params.HEAT_SOAK | lower == 'true' %}
{% set heat_soak = 1 %}
{% elif params.HEAT_SOAK is defined and params.HEAT_SOAK | lower == 'false' %}
{% set heat_soak = 0 %}
{% endif %}
{% if params.AUTO_Z is defined and params.AUTO_Z | lower == ' true' %}
{% set auto_z = 1 %}
{% elif params.AUTO_Z is defined params.AUTO_Z | lower == 'false' %}
{% set auto_z = 0 %}
{% endif %}
{% if params.Z_TILT is defined and params.Z_TILT | lower == 'true' %}
{% set auto_z = 1 %}
{% elif params.Z_TILT is defined and params.Z_TILT | lower == 'false' %}
{% set auto_z = 0 %}
{% endif %}
{% if params.QUAD_GANTRY_LEVEL is defined and params.QUAD_GANTRY_LEVEL | lower == 'true' %}
{% set qgl = 1 %}
{% elif params.QUAD_GANTRY_LEVEL is defined and params.QUAD_GANTRY_LEVEL | lower == 'false' %}
{% set qgl = 0 %}
{% endif %}
{% if params.BED_MESH is defined and params.BED_MESH | lower == 'true' %}
{% set mesh = 1 %}
{% elif params.BED_MESH is defined and params.BED_MESH | lower == 'false' %}
{% set mesh = 0 %}
{% endif %}
{% if params.ADAPTIVE_MESH is defined and params.ADAPTIVE_MESH | lower == 'true' %}
{% set adaptive_mesh = 1 %}
{% elif params.ADAPTIVE_MESH is defined and params.ADAPTIVE_MESH | lower == 'false' %}
{% set adaptive_mesh = 0 %}
{% endif %}
{% if params.LOAD_MESH is defined and params.LOAD_MESH | lower == 'true' %}
{% set load_mesh = 1 %}
{% elif params.LOAD_MESH is defined and params.LOAD_MESH | lower == 'false' %}
{% set load_mesh = 0 %}
{% endif %}
{% if params.NOZZLE_BRUSH is defined and params.NOZZLE_BRUSH | lower == 'true' %}
{% set cleaning = 1 %}
{% elif params.NOZZLE_BRUSH is defined and params.NOZZLE_BRUSH | lower == 'false' %}
{% set cleaning = 0 %}
{% endif %}
{% if params.NOZZLE_PURGE is defined and params.NOZZLE_PURGE | lower == 'true' %}
{% set purging = 1 %}
{% elif params.NOZZLE_PURGE is defined and params.NOZZLE_PURGE | lower == 'false' %}
{% set purging = 0 %}
{% endif %}
{% if params.ADAPTIVE_PURGE is defined and params.ADAPTIVE_PURGE | lower == 'true' %}
{% set adaptive_purge = 1 %}
{% elif params.ADAPTIVE_PURGE is defined and params.ADAPTIVE_PURGE | lower == 'false' %}
{% set adaptive_purge = 0 %}
{% endif %}
{% if params.USE_NEVERMORE is defined and params.USE_NEVERMORE | lower == 'true' %}
{% set nevermore = 1 %}
{% elif params.USE_NEVERMORE is defined and params.USE_NEVERMORE | lower == 'false' %}
{% set nevermore = 0 %}
{% endif %}
################## Set Variables ##################
## Start Temps
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=bed_temp VALUE={ bed_temp } ; set bed temp
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=extruder_temp VALUE={ extruder_temp } ; set extruder temp
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=extruder_pre_temp VALUE={ extruder_pre_temp } ; set extruder pre-heat temp
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_temp VALUE={ chamber_temp } ; set chamber temp
## Start Steps
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak VALUE={ heat_soak } ; set heat soak time
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=auto_z_calibrate VALUE={ auto_z } ; set auto z calibrate
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=z_tilt VALUE={ z_tilt } ; set z tilt
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=qgl VALUE={ qgl } ; set qgl
## Bed Meshing
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=bed_mesh VALUE={ mesh } ; set bed mesh
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=mesh_adaptive VALUE={ adaptive_mesh } ; set adaptive mesh
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=load_mesh VALUE={ load_mesh } ; set load mesh
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=mesh_profile VALUE={ mesh_profile } ; set mesh profile
## Cleaning and Purging
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=cleaning VALUE={ cleaning } ; set nozzle cleaning
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=purging VALUE={ purging } ; set nozzle purging
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=adaptive_purge VALUE={ adaptive_purge } ; set adaptive purging
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore VALUE={ nevermore } ; set nevermore
################################
######### HEAT_SURFACE #########
################################
[gcode_macro HEAT_SURFACE]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
## Preheat bed
{% if printcfg.bed_temp > 0 %} ; if bed temp is set
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_heat} ; LED feedback
{% endif %}
{% if printcfg.extruder_pretemp > 0 %} ; if extruder preheat is set
M{printcfg.output} {"Warming extruder to " + printcfg.extruder_pretemp|int|string + "°C"} ; status feedback
SET_HEATER_TEMPERATURE HEATER=extruder TARGET={printcfg.extruder_pretemp} ; allow partial nozzle warmup
{% endif %}
M{printcfg.output} {"Preheating bed to " + printcfg.bed_temp|int|string + "°C"} ; status feedback
SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={printcfg.bed_temp} ; set bed temp
{% if printcfg.bed_fans == True %} ; if using bed fans
{printcfg.bed_fan_slow} ; slow speed bed fans
{% endif %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={printcfg.bed_temp-1} MAXIMUM={printcfg.bed_temp+5} ; wait for bed temp
{% if printcfg.bed_fans == True %} ; if using bed fans
{printcfg.bed_fan_fast} ; fast speed bed fans
{% endif %}
{% endif %}
################################
######### PREP_CHAMBER #########
################################
[gcode_macro PREP_CHAMBER]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% if printcfg.chamber == True %} ; if using a chamber
{% if printcfg.chamber_temp != 0 %} ; if chamber temp is set
M{printcfg.output} Preheating chamber ; status feedback
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_heat} ; LED feedback
{% endif %}
{% if printcfg.chamber_type == 'temperature_fan' %} ; if using a temperature_fan chamber sensor
SET_TEMPERATURE_FAN_TARGET temperature_fan={printcfg.chamber_name} target={printcfg.chamber_temp} ; set chamber temp
{% elif printcfg.chamber_type == 'heater_generic' %} ; if using a heater_generic chamber sensor
SET_HEATER_TEMPERATURE HEATER={printcfg.chamber_name} TARGET={printcfg.chamber_temp} ; set chamber temp
{% endif %}
{% if printcfg.heat_soak == True %} ; if heat soak is enabled
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak_complete VALUE=0 ; set heat soak incomplete
HEAT_SOAK ; start heat soak
{% endif %}
{% endif %}
{% endif %}
################################
########### HEAT_SOAK ##########
################################
[gcode_macro HEAT_SOAK]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
## Handle Parameters
{% if params.SENSOR is defined %}
{% set sensor = params.SENSOR | default(printcfg.chamber_name) | lower %}
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_name VALUE={ sensor } ; set chamber sensor
{% endif %}
{% if params.SENSOR_TYPE is defined %}
{% set sensor_type = params.SENSOR_TYPE | default(printcfg.chamber_type) | lower %}
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_type VALUE={ sensor_type } ; set chamber sensor type
{% endif %}
{% if params.EXTRUDER is defined %} ; if extruder temp is set
{% set pre_temp = params.EXTRUDER | default(printcfg.extruder_pretemp) | float %} ; get extruder preheat temp
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=extruder_pretemp VALUE={ pre_temp } ; set extruder preheat temp
{% endif %}
{% if params.TIME is defined %} ; if time is set
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=time_soak VALUE=1 ; set time soak to true
{% set time = params.TIME | default(printcfg.chamber_time) | float %} ; get time soak value
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_time VALUE={ time } ; set time soak value
{% else %} ; if time is not set
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=time_soak VALUE=0 ; set time soak to false
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=temp_soak VALUE=1 ; set temp soak to true
{% endif %}
{% set temp = params.TEMP | default(printcfg.chamber_temp) | float %} ; get chamber temp
{% set bed = params.BED | default(printcfg.bed_temp) | float %} ; get bed temp
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_temp VALUE={ temp } ; set chamber temp
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=bed_temp VALUE={ bed } ; set bed temp
## Check print mode
{% if printcfg.starting_print|int == 0 %} ; if not starting a print
## Not in a print
HEAT_SURFACE ; heat bed
{% endif %}
# Execute heat soak
_DO_SOAK {rawparams} ; do soak
[gcode_macro _DO_SOAK]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_heat} ; LED feedback
{% endif %}
{% if printcfg.time_soak == True %} ; if using a time soak
M{printcfg.output} "Soaking {printcfg.chamber_time} minutes" ; status feedback
## Start timer
UPDATE_DELAYED_GCODE ID=heat_soak_timer DURATION={printcfg.chamber_time*60} ; start soak timer
SET_IDLE_TIMEOUT TIMEOUT={printcfg.soak_idle_time} ; set idle timeout to soak time
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak_complete VALUE=0
{% endif %}
{% if printcfg.temp_soak == True %} ; if using a temperature soak
{% if printcfg.bed_fans == True %} ; if using bed fans
{printcfg.bed_fan_fast} ; fast speed bed fans
{% endif %}
M{printcfg.output} {"Soaking until " + printcfg.chamber_temp|int|string + "°C"} ; status feedback
_set_chamber TEMP={printcfg.chamber_temp} WAIT=true ; set chamber temp
M{printcfg.output} {"Soaking completed at " + printcfg.chamber_temp|int|string + "°C"} ; status feedback
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak_complete VALUE=1 ; set heat soak completed
{% endif %}
{% if printcfg.heat_soak_complete == 1 %} ; if heat soak complete
{printcfg.bed_fan_off} ; turn off bed fans
{% endif %}
################################
######## Heat Soak Timer #######
################################
[delayed_gcode heat_soak_timer]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
M{printcfg.output} "Soaking completed after {printcfg.chamber_time} minutes" ; status feedback
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak_complete VALUE=1 ; set heat soak completed
{printcfg.bed_fan_off} ; turn off bed fans
{% if printcfg.starting_print|int == 1 %}
## Soak complete, resume starting print
RESUME_BASE
{% endif %}
################################
###### CHAMBER CONTROL #########
################################
[gcode_macro _set_chamber]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% set config = printer.configfile.settings %} ; get realtime configfile settings
## Parameters
{% set TEMP = params.TEMP|default(0)|float %} ; chamber temperature
{% set WAIT = params.WAIT|default('false')|lower %} ; wait for temperature
{% set SPEED = params.SPEED|default(0)|float %} ; chamber fan speed
{% set chamber = printcfg.chamber_type + ' ' + printcfg.chamber_name %} ; chamber sensor
## Determine chamber type
{% if printcfg.chamber_type == 'generic_fan' %} ; if using a generic_fan chamnber sensor type
## Set chamber fan speed
SET_FAN_SPEED FAN={printcfg.chamber_name} SPEED={SPEED} ; set chamber fan speed
{% elif printcfg.chamber_type == 'temperature_fan' %}
## Set chamber temperature
SET_TEMPERATURE_FAN_TARGET temperature_fan={printcfg.chamber_name} TARGET={TEMP} ; set chamber temperature
{% if WAIT == 'true' %} ; if waiting for temperature
## Wait for chamber temperature
TEMPERATURE_WAIT SENSOR='{chamber}' MINIMUM={TEMP} MAXIMUM={TEMP+25} ; wait for chamber temperature
{% endif %}
## Set chamber fan speed
SET_FAN_SPEED FAN={printcfg.chamber_name} SPEED={SPEED} ; set chamber fan speed
{% elif printcfg.chamber_type == 'heater' %} ; if using a heater chamber sensor type
## Set chamber temperature
SET_HEATER_TEMPERATURE HEATER={printcfg.chamber_name} TARGET={TEMP} ; set chamber temperature
{% if WAIT == 'true' %} ; if waiting for temperature
## Wait for chamber temperature
TEMPERATURE_WAIT SENSOR='{chamber}' MINIMUM={TEMP} MAXIMUM={TEMP+25} ; wait for chamber temperature
{% endif %}
{% elif printcfg.chamber_type == 'temperature_sensor' %} ; if using a temperature_sensor chamber sensor type
{% if WAIT == 'true' %} ; if waiting for temperature
## Wait for chamber temperature
TEMPERATURE_WAIT SENSOR='{chamber}' MINIMUM={TEMP} MAXIMUM={TEMP+25} ; wait for chamber temperature
{% endif %}
{% elif printcfg.chamber_type == 'z_thermal_adjust' %}
{% set chamber = printcfg.chamber_type %} ; chamber sensor
{% if WAIT == 'true' %} ; if waiting for temperature
## Wait for chamber temperature
TEMPERATURE_WAIT SENSOR='{chamber}' MINIMUM={TEMP} MAXIMUM={TEMP+25} ; wait for chamber temperature
{% endif %}
{% endif %}
{% if printcfg.debugging == True %}
{action_respond_info("Chamber: " + chamber + " | Temperature: " + TEMP|string + " | Wait: " + WAIT|string + " | Speed: " + SPEED|string)}
{% endif %}
################################
######### SET_CHAMBER ##########
################################
[gcode_macro SET_CHAMBER]
description: Set up enclosure control variables
gcode:
################## Get PrintCFG ##################
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
################## Get Parameters ##################
## Use Chamber
{% set chamber = params.USE_CHAMBER | default(printcfg.chamber) | int %}
## Start Temps and Times
{% set chamber_temp = params.CHAMBER_TEMP | default(printcfg.chamber_temp) | float %}
{% set chamber_time = params.CHAMBER_TIME | default(printcfg.chamber_time) | int %}
{% set bed_temp = params.BED_TEMP | default(printcfg.bed_temp) | float %}
## Chamber Sensor
{% set chamber_type = params.CHAMBER_TYPE | default(printcfg.chamber_type) | string %}
{% set chamber_name = params.CHAMBER_NAME | default(printcfg.chamber_name) | string %}
## Soaking
{% set heat_soak = params.HEAT_SOAK | default(printcfg.heat_soak) | int %}
{% set time_soak = params.TIME_SOAK | default(printcfg.time_soak) | int %}
{% set temp_soak = params.TEMP_SOAK | default(printcfg.temp_soak) | int %}
############## Make Strings Booleans ##############%}
{% if params.USE_CHAMBER is defined and params.USE_CHAMBER | lower == 'true' %}
{% set chamber = 1 %}
{% elif params.USE_CHAMBER is defined and params.USE_CHAMBER | lower == 'false' %}
{% set chamber = 0 %}
{% endif %}
{% if params.TIME_SOAK is defined and params.TIME_SOAK | lower == ' true' %}
{% set time_soak = 1 %}
{% elif params.TIME_SOAK is defined params.TIME_SOAK | lower == 'false' %}
{% set time_soak = 0 %}
{% endif %}
{% if params.HEAT_SOAK is defined and params.HEAT_SOAK | lower == 'true' %}
{% set heat_soak = 1 %}
{% elif params.HEAT_SOAK is defined and params.HEAT_SOAK | lower == 'false' %}
{% set heat_soak = 0 %}
{% endif %}
{% if params.TEMP_SOAK is defined and params.TEMP_SOAK | lower == 'true' %}
{% set temp_soak = 1 %}
{% elif params.TEMP_SOAK is defined and params.TEMP_SOAK | lower == 'false' %}
{% set temp_soak = 0 %}
{% endif %}
################## Set Variables ##################
## Use Chamber
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber VALUE={ chamber } ; set bed temp
## Start Temps and Times
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_temp VALUE={ chamber_temp } ; set chamber temp
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_time VALUE={ chamber_time } ; set chamber time
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=bed_temp VALUE={ bed_temp } ; set bed temp
## Chamber Sensor
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_type VALUE={ chamber_type } ; set chamber type
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=chamber_name VALUE={ chamber_name } ; set chamber name
## Soaking
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak VALUE={ heat_soak } ; set qgl
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=time_soak VALUE={ time_soak } ; set bed mesh
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=temp_soak VALUE={ temp_soak } ; set adaptive mesh
################################
########## PREP_FANS ###########
################################
[gcode_macro PREP_FANS]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
## Set controller fan
{% if printcfg.controller_fan == True %} ; if using a controller fan
{printcfg.controller_fan_start} ; start controller fan
{% endif %}
## Set part-cooling fan (off)
M107 ; turn off part cooling fan
## Set nevermore/filter fan
{% if printcfg.nevermore_speed > 0 %} ; if using a nevermore/filter fan
SET_FAN_SPEED FAN={printcfg.nevermore_name} SPEED={printcfg.nevermore_speed} ; set nevermore/filter fan speed
{% endif %}
################################
######### PREP_SURFACE #########
################################
[gcode_macro PREP_SURFACE]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% set config = printer.configfile.settings %} ; get realtime configfile settings
## Homing/undock probe
{% if printcfg.docking_probe == True %} ; if using a docking probe
## Collect probe
M{printcfg.output} Collecting probe ; status feedback
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_homing} ; LED feedback
{% endif %}
{% if printer.toolhead.homed_axes != "xyz" %} ; if not homed
M{printcfg.output} Homing XY ; status feedback
G28 Y X ; home XY axis
{% endif %}
{printcfg.attach_macro} ; attach probe
M{printcfg.output} Homing Z ; status feedback
G28 Z ; home Z axis
{% else %} ; if not using a docking probe
G28 ; home XYZ axis
{% endif %}
{% if printcfg.clean_probe == True %} ; if cleaning before probing
{printcfg.clean_macro} ; clean nozzle
{% endif %}
M400 ;
## Z Calibration Functions
{% if printcfg.auto_z_calibrate == True %} ; if using auto z-calibration
{% if config.z_calibration is defined %} ; if z-calibration is configured
M{printcfg.output} Calibrating Z ; status feedback
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_calibrating_z} ; LED feedback
{% endif %}
CALIBRATE_Z ; adjust z-calibration
{% else %} ; if z-calibration not configured
M{printcfg.error_output} Z_calibration not configured!
{% endif %}
{% endif %}
{% if printcfg.z_tilt == True %} ; if using z-tilt
{% if config.z_tilt is defined %} ; if z-tilt is configured
M{printcfg.output} Calibrating Z ; status feedback
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_calibrating_z} ; LED feedback
{% endif %}
Z_TILT_ADJUST ; adjust z-tilt
{% else %} ; if z-tilt not configured
M{printcfg.error_output} Z_tilt not configured!
{% endif %}
{% elif printcfg.qgl == True %} ; if using QGL
{% if config.quad_gantry_level is defined %} ; if QGL is configured
M{printcfg.output} Calibrating Z ; status feedback
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_calibrating_z} ; LED feedback
{% endif %}
QUAD_GANTRY_LEVEL ; adjust QGL
G28 Z ; home Z axis
{% else %} ; if QGL not configured
M{printcfg.error_output} QGL not configured!
{% endif %}
{% endif %}
## Bed mesh
{% if printcfg.bed_mesh == True %} ; if using bed mesh
{% if config.bed_mesh is defined %} ; if bed mesh is configured
M{printcfg.output} Mesh print area ; status feedback
{% if printcfg.load_mesh == True %} ; if loading mesh
BED_MESH_PROFILE LOAD={printcfg.mesh_profile} ; load mesh profile
{% else %} ; if not loading mesh
{% if printcfg.mesh_adaptive == True %} ; if using adaptive mesh}
BED_MESH_CALIBRATE ; generate new mesh
{% else %} ; if not using adaptive mesh
_BED_MESH_CALIBRATE ; generate new mesh
{% endif %}
{% endif %}
{% else %} ; if bed mesh not configured
M{printcfg.error_output} Bed_mesh not configured!
{% endif %}
{% endif %}
## Dock probe
{% if printcfg.docking_probe == True %} ; if using a docking probe
M{printcfg.output} Docking probe ; status feedback
{printcfg.dock_macro} ; dock probe
{% endif %}
################################
####### FINALIZE_ENVIRO ########
################################
[gcode_macro FINALIZE_ENVIRO]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
## Preheat hotend
PREP_EXTRUDER
## Catch up
M400
## Status notifications
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=starting_print VALUE=0 ; complete print_start process
M{printcfg.output} Print Started ; status feedback
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_printing} ; LED feedback
{% endif %}
## Final catch up
M400
################################
######## PREP_EXTRUDER #########
################################
[gcode_macro PREP_EXTRUDER]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% if printcfg.auto_filament_sensor == True %} ; if using auto filament sensor
## Turn on Filament Sensor
ENABLEFILAMENTSENSOR
{% endif %}
## Begin heating extruder hotend
M{printcfg.output} Preheating tool ; status feedback
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_heat} ; LED feedback
{% endif %}
M104 S{printcfg.extruder_temp} ; set final nozzle temp
## Park for preheating
{% if printcfg.cleaning == True %} ; if using nozzle cleaning
G0 Z{25 + printcfg.clean_z} F240 ; move to pre-cleaning height
G0 X{printcfg.clean_x} Y{printcfg.clean_y} F3000 ; move to park position
{% else %} ; if not using nozzle cleaning
G0 Z{printcfg.preheat_z} F240 ; move to pre-heating height
G0 X{printcfg.preheat_x} Y{printcfg.preheat_y} F3000 ; move to park position
{% endif %}
## Wait for heating to complete
M109 S{printcfg.extruder_temp} ; wait for nozzle temp to stabilize
## Status Alert
{% if printcfg.audio_status == True %} ; if using audio status alerts
{printcfg.start_audio} ; audio feedback
{% endif %}
## Nozzle Cleaning
{% if printcfg.cleaning == True %} ; if using nozzle cleaning
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_clean} ; LED feedback
{% endif %}
{printcfg.clean_macro} ; clean nozzle
{% endif %}
## Nozzle Purging
{% if printcfg.purging == True %} ; if using nozzle purging
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_clean} ; LED feedback
{% endif %}
{printcfg.purge_macro} ; purge nozzle
{% endif %}
## Final catch up
M400
## Extruder configuration
G21 ; set units to millimeters
G90 ; use absolute coordinates
M82 ; use absolute distances for extrusion
G92 E0 ; reset extrusion distance
################################
########## END_PRINT ###########
################################
[gcode_macro END_PRINT]
description: Present the finished print
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% if printcfg.end_print == True %} ; if using end print macro
## Final catch up
M400
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_part_ready} ; LED feedback
{% endif %}
{% if printcfg.end_retract == True %} ; if using end retraction
G1 E-{printcfg.end_retract_length} F{printcfg.end_retract_speed * 60} ; retract filament
{% endif %}
{% if printcfg.clean_end == True %} ; if using end_print nozzle cleaning
{printcfg.clean_macro} ; clean nozzle
{% endif %}
{printcfg.park_base} ; park toolhead
## Acknowledge success!
M{printcfg.output} Print Complete ; status feedback
{% if printcfg.audio_status == True %} ; if using audio status alerts
{printcfg.success_audio} ; audio feedback
{% endif %}
{% if printcfg.led_status == True %} ; if using LED status
{printcfg.status_ready} ; LED feedback
{% endif %}
{% if printcfg.end_unload == True %} ; if using end_print filament unload
{printcfg.m600} ; unload filament
{% endif %}
STOP_COMPONENTS ; stop components
{% endif %}
################################
###### STOP_COMPONENTS #########
################################
[gcode_macro STOP_COMPONENTS]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% if printcfg.auto_filament_sensor == True %} ; if using auto filament sensor
## Disable filament sensor
DISABLEFILAMENTSENSOR
{% endif %}
{% if printcfg.controller_fan == True %} ; if using controller fan
{printcfg.controller_fan_stop} ; stop controller fan
{% endif %}
{% if printcfg.use_scrubber == True %} ; if using scrubber
## Scrub VOCs
SCRUBBER ; turn on scrubber
{% else %}
{% if printcfg.exhaust_fan == True %} ; if using exhaust fan
M{printcfg.output} Exhausting chamber; status feedback
{printcfg.exhaust_fan_start} ; start exhaust fan
UPDATE_DELAYED_GCODE ID=exhaust_fan_delay DURATION={printcfg.exhaust_fan_delay} ; start exhaust fan delay
{% else %} ; if not using exhaust fan
SET_DEFAULTS MODE=END; reset to default settings
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=end_print VALUE=0 ; reset end_print
{% if printcfg.power_off == True %} ; if using power off at end of print
{printcfg.off_macro} ; power off printer
{% endif %}
{% endif %}
{% endif %}
G90 ; use absolute coordinates
TURN_OFF_HEATERS ; turn off heaters
M84 ; disable motors
################################
##### EXHAUST FAN DELAY ########
################################
[delayed_gcode exhaust_fan_delay]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
M{printcfg.output} Exhaust complete ; status feedback
{printcfg.exhaust_fan_stop} ; stop exhaust fan
{% if printcfg.end_print == True %}
SET_DEFAULTS MODE=END; reset to default settings
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=end_print VALUE=0 ; reset end_print
{% if printcfg.power_off == True %} ; if using power off at end of print
{printcfg.off_macro} ; power off printer
{% endif %}
{% endif %}
################################
######## ADAPTIVE MESH #########
################################
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: _BED_MESH_CALIBRATE
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% set config = printer.configfile.settings %} ; get realtime configfile settings
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
{% set bed_mesh_min = config.bed_mesh.mesh_min %}
{% set bed_mesh_max = config.bed_mesh.mesh_max %}
{% set max_probe_point_distance_x = ( bed_mesh_max[0] - bed_mesh_min[0] ) / (config.bed_mesh.probe_count[0]-2) %}
{% set max_probe_point_distance_y = ( bed_mesh_max[1] - bed_mesh_min[1] ) / (config.bed_mesh.probe_count[1]-2) %}
{% set x_min = bed_mesh_min[0] %}
{% set y_min = bed_mesh_min[1] %}
{% set x_max = bed_mesh_max[0] %}
{% set y_max = bed_mesh_max[1] %}
{ action_respond_info("{} points, clamping to mesh [{!r} {!r}]".format(
all_points | count,
bed_mesh_min,
bed_mesh_max,
)) }
{% if printcfg.mesh_fuzz_enable == True %}
{% if all_points %}
{% set fuzz_range = range(printcfg.mesh_fuzz_min * 100 | int, printcfg.mesh_fuzz_max * 100 | int) %}
{% set x_min = ( bed_mesh_min[0], ((all_points | map(attribute=0) | min - (fuzz_range | random / 100.0)) | default(bed_mesh_min[0])) ) | max %}
{% set y_min = ( bed_mesh_min[1], ((all_points | map(attribute=1) | min - (fuzz_range | random / 100.0)) | default(bed_mesh_min[1])) ) | max %}
{% set x_max = ( bed_mesh_max[0], ((all_points | map(attribute=0) | max + (fuzz_range | random / 100.0)) | default(bed_mesh_max[0])) ) | min %}
{% set y_max = ( bed_mesh_max[1], ((all_points | map(attribute=1) | max + (fuzz_range | random / 100.0)) | default(bed_mesh_max[1])) ) | min %}
{% endif %}
{% else %}
{% set x_min = [ bed_mesh_min[0], (all_points | map(attribute=0) | min | default(bed_mesh_min[0])) ] | max %}
{% set y_min = [ bed_mesh_min[1], (all_points | map(attribute=1) | min | default(bed_mesh_min[1])) ] | max %}
{% set x_max = [ bed_mesh_max[0], (all_points | map(attribute=0) | max | default(bed_mesh_max[0])) ] | min %}
{% set y_max = [ bed_mesh_max[1], (all_points | map(attribute=1) | max | default(bed_mesh_max[1])) ] | min %}
{% endif %}
{ action_respond_info("Object bounds, clamped to the bed_mesh: {!r}, {!r}".format(
(x_min, y_min),
(x_max, y_max),
)) }
{% set points_x = (((x_max - x_min) / max_probe_point_distance_x) | int) + 2 %}
{% set points_y = (((y_max - y_min) / max_probe_point_distance_y) | int) + 2 %}
{% if (([points_x, points_y]|max) > 6) %}
{% set algorithm = "bicubic" %}
{% set min_points = 4 %}
{% else %}
{% set algorithm = "lagrange" %}
{% set min_points = 3 %}
{% endif %}
{ action_respond_info( "Algorithm: {}".format(algorithm)) }
{% set points_x = [points_x, min_points]|max %}
{% set points_y = [points_y, min_points]|max %}
{ action_respond_info( "Points: x: {}, y: {}".format(points_x, points_y) ) }
{% if config.bed_mesh.relative_reference_index is defined %}
{% set ref_index = (points_x * points_y / 2) | int %}
{ action_respond_info( "Reference index: {}".format(ref_index) ) }
{% else %}
{% set ref_index = -1 %}
{% endif %}
{% if printcfg.docking_probe == True %}
{printcfg.attach_macro} ; Attach/deploy a probe if the probe is stored somewhere outside of the print area
{% endif %}
{% if printcfg.led_status == True %}
{printcfg.status_mesh} ; LED feedback
{% endif %}
_BED_MESH_CALIBRATE mesh_min={x_min},{y_min} mesh_max={x_max},{y_max} ALGORITHM={algorithm} PROBE_COUNT={points_x},{points_y} RELATIVE_REFERENCE_INDEX={ref_index}
{% if printcfg.docking_probe == True %}
{printcfg.dock_macro} ; Detach/stow a probe if the probe is stored somewhere outside of the print area
{% endif %}
################################
######## ADAPTIVE_PURGE ########
################################
## This code is used to purge filament when the extruder is not at temperature
## and it is not possible to use the normal purge code.
## The purge is done by moving the extruder to the purge position and
## extruding a set amount of filament.
[gcode_macro ADAPTIVE_PURGE]
description: A purge macro that adapts to be near your actual printed objects
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% if printcfg.purge_adaptive == True %}
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
{% set x_origin = (all_points | map(attribute=0) | min | default(printcfg.purge_x + printcfg.purge_dist_x + printcfg.purge_size)) - printcfg.purge_dist_x - printcfg.purge_size %}
{% set y_origin = (all_points | map(attribute=1) | min | default(printcfg.purge_y + printcfg.purge_dist_y + printcfg.purge_size)) - printcfg.purge_dist_y - printcfg.purge_size %}
{% set x_origin = ([x_origin, 0] | max) %}
{% set y_origin = ([y_origin, 0] | max) %}
{% else %}
{% set x_origin = printcfg.purge_x | float %}
{% set y_origin = printcfg.purge_y | float %}
{% endif %}
{% set purge_move_speed = 2.31 * printcfg.purge_size * printcfg.purge_flow_rate / (printcfg.purge_amount * 2.405) %}
{% set prepurge_speed = printcfg.purge_flow_rate / 2.405 %}
{% if printcfg.purge_debug == True %}
{ action_respond_info( "x: " + x_origin|string + " y: " + y_origin|string + " purge_move_speed: " + purge_move_speed|string + " prepurge_speed: " + prepurge_speed|string ) }
{% endif %}
{% if printcfg.led_status == True %}
{printcfg.status_clean} ; LED feedback
{% endif %}
G92 E0
G0 F{printcfg.travel_speed*60} ; Set travel speed
G90 ; Absolute positioning
G0 X{x_origin} Y{y_origin+printcfg.purge_size/2} ; Move to purge position
G0 Z{printcfg.purge_z_height} ; Move to purge Z height
M83 ; Relative extrusion mode
G1 E{printcfg.purge_tip_distance} F{prepurge_speed*60} ; Move tip of filament to nozzle
G1 X{x_origin+printcfg.purge_size*0.289} Y{y_origin+printcfg.purge_size} E{printcfg.purge_amount/4} F{purge_move_speed*60} ; Purge first line of logo
G1 E-.5 F2100 ; Retract
G0 Z{printcfg.purge_z_height*2} ; Z hop
G0 X{x_origin+printcfg.purge_size*0.789} Y{y_origin+printcfg.purge_size} ; Move to second purge line origin
G0 Z{printcfg.purge_z_height} ; Move to purge Z height
G1 E.5 F2100 ; Recover
G1 X{x_origin+printcfg.purge_size*0.211} Y{y_origin} E{printcfg.purge_amount/2} F{purge_move_speed*60} ; Purge second line of logo
G1 E-.5 F2100 ; Retract
G0 Z{printcfg.purge_z_height*2} ; Z hop
G0 X{x_origin+printcfg.purge_size*0.711} Y{y_origin} ; Move to third purge line origin
G0 Z{printcfg.purge_z_height} ; Move to purge Z height
G1 E.5 F2100 ; Recover
G1 X{x_origin+printcfg.purge_size} Y{y_origin+printcfg.purge_size/2} E{printcfg.purge_amount/4} F{purge_move_speed*60} ; Purge third line of logo
G1 E-.5 F2100 ; Retract
G92 E0 ; Reset extruder distance
G0 Z{printcfg.purge_z_height*2} ; Z hop
################################
######### CLEAN_NOZZLE #########
################################
[gcode_macro CLEAN_NOZZLE]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
CG28 ; Home all axes if needed
{% set nozzle_targ = params.TARGET|default(0)|float %}
{% set is_hot = printcfg.clean_hot %}
{% if params.HEAT is defined %}
{% if params.HEAT|lower == 'true' %}
{% set is_hot = False %}
{% elif params.HEAT|lower == 'false' %}
{% set is_hot = True %}
{% endif %}
{% endif %}
{% if is_hot == False %}
{% if printcfg.led_status == True %}
{printcfg.status_heat}
{% endif %}
M{printcfg.output} Heating extruder
{% if nozzle_targ > 0 %}
M109 S{nozzle_targ}
{% elif printcfg.clean_temp > 0 %}
M109 S{printcfg.clean_temp}
{% endif %}
{% endif %}
G90 ; absolute positioning
## Move nozzle to start position
G0 X{printcfg.clean_x} Y{printcfg.clean_y} F6000
G0 Z{printcfg.clean_z} F1500
## Set lighting
{% if printcfg.led_status == True %}
{printcfg.status_clean} ; LED feedback
{% endif %}
## Wipe nozzle
M{printcfg.output} Wiping nozzle
{% for wipes in range(1, (printcfg.clean_wipe_qty + 1)) %}
G0 X{printcfg.clean_x + printcfg.clean_wipe_dist} F{printcfg.clean_wipe_spd * 60}
G0 X{printcfg.clean_x} F{printcfg.clean_wipe_spd * 60}
{% endfor %}
## Raise nozzle
G0 Z{printcfg.clean_raise_dist}
{% if is_hot == False %}
M{printcfg.output} Cooling extruder
M104 S0
{% endif %}
{% if printcfg.post_clean_home == True %}
G28 Z
{% endif %}
################################
######### SET_CLEANING #########
################################
[gcode_macro SET_NOZZLE_CLEANING]
description: Set up nozzle cleaning parameters
gcode:
################## Get PrintCFG ##################
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
################## Get Parameters ##################
## Cleaning Coordinates
{% set clean_x = params.X | default(printcfg.clean_x) | float %}
{% set clean_y = params.Y | default(printcfg.clean_y) | float %}
{% set clean_z = params.Z | default(printcfg.clean_z) | float %}
{% set cleaning = params.USE_CLEAN | default(printcfg.cleaning) | int %}
## Cleaning Temperature
{% set clean_temp = params.TEMPERATURE | default(printcfg.clean_temp) | float %}
## Cleaning Scenarios
{% set clean_probe = params.CLEAN_BEFORE_PROBING | default(printcfg.clean_probe) | int %}
{% set clean_end = params.CLEAN_AFTER_PRINT | default(printcfg.clean_end) | int %}
{% set post_clean_home = params.HOME_AFTER_CLEANING | default(printcfg.post_clean_home) | int %}
{% set clean_m600 = params.CLEAN_AFTER_M600 | default(printcfg.clean_m600) | int %}
## Cleaning Wipe
{% set clean_wipe_qty = params.WIPE_QUANTITY | default(printcfg.clean_wipe_qty) | int %}
{% set clean_wipe_dist = params.WIPE_DISTANCE | default(printcfg.clean_wipe_dist) | float %}
{% set clean_wipe_spd = params.WIPE_SPEED | default(printcfg.clean_wipe_spd) | float %}
## Cleaning Raise
{% set clean_raise_dist = params.RAISE_DISTANCE | default(printcfg.clean_raise_dist) | float %}
################ Get Axis Limits ################
{% set x_min = printer.toolhead.axis_minimum.x %}
{% set x_max = printer.toolhead.axis_maximum.x %}
{% set y_min = printer.toolhead.axis_minimum.y %}
{% set y_max = printer.toolhead.axis_maximum.y %}
{% set z_min = printer.toolhead.axis_minimum.z %}
{% set z_max = printer.toolhead.axis_maximum.z %}
############### Check Coordinates ################
{% set x = clean_x %}
{% set y = clean_y %}
{% set z = clean_z %}
{% set mode = "Cleaning" %}
{% if x < x_min or x > x_max %} ; if x is out of range
{% set title = mode + " Coordinates" %}
{% set msg = "X position is out of range: " + x|string %} ; set message
{% set level = "error" %} ; set level
{ action_respond_info( "{}: {}".format( title, msg ) ) } ; report error
{% else %}
{% set title = mode + " Coordinates" %}
{% set msg = "X position is within range: " + x|string %} ; set message
{% set level = "debug" %} ; set level
{% endif %}
logger title="{title}" msg="{msg}" level={level} ; log message
{% if y < y_min or y > y_max %} ; if y is out of range
{% set title = mode + " Coordinates" %}
{% set msg = "Y position is out of range: " + y|string %} ; set message
{% set level = "error" %} ; set level
{ action_respond_info( "{}: {}".format( title, msg ) ) } ; report error
{% else %}
{% set title = mode + " Coordinates" %}
{% set msg = "Y position is within range: " + y|string %} ; set message
{% set level = "debug" %} ; set level
{% endif %}
logger title="{title}" msg="{msg}" level={level} ; log message
{% if z < z_min or z > z_max %} ; if z is out of range
{% set title = mode + " Coordinates" %}
{% set msg = "Z position is out of range: " + z|string %} ; set message
{% set level = "error" %} ; set level
{ action_respond_info( "{}: {}".format( title, msg ) ) } ; report error
{% else %}
{% set title = mode + " Coordinates" %}
{% set msg = "Z position is within range: " + z|string %} ; set message
{% set level = "debug" %} ; set level
{% endif %}
logger title="{title}" msg="{msg}" level={level} ; log message
############## Make Strings Booleans ##############%}
{% if params.USE_CLEAN is defined and params.USE_CLEAN | lower == 'true' %}
{% set cleaning = 1 %}
{% elif params.USE_CLEAN is defined and params.USE_CLEAN | lower == 'false' %}
{% set cleaning = 0 %}
{% endif %}
{% if params.CLEAN_BEFORE_PROBING is defined and params.CLEAN_BEFORE_PROBING | lower == 'true' %}
{% set clean_probe = 1 %}
{% elif params.CLEAN_BEFORE_PROBING is defined and params.CLEAN_BEFORE_PROBING | lower == 'false' %}
{% set clean_probe = 0 %}
{% endif %}
{% if params.CLEAN_AFTER_PRINT is defined and params.CLEAN_AFTER_PRINT | lower == 'true' %}
{% set clean_end = 1 %}
{% elif params.CLEAN_AFTER_PRINT is defined and params.CLEAN_AFTER_PRINT | lower == 'false' %}
{% set clean_end = 0 %}
{% endif %}
{% if params.HOME_AFTER_CLEANING is defined and params.HOME_AFTER_CLEANING | lower == 'true' %}
{% set post_clean_home = 1 %}
{% elif params.HOME_AFTER_CLEANING is defined and params.HOME_AFTER_CLEANING | lower == 'false' %}
{% set post_clean_home = 0 %}
{% endif %}
{% if params.CLEAN_AFTER_M600 is defined and params.CLEAN_AFTER_M600 | lower == 'true' %}
{% set clean_m600 = 1 %}
{% elif params.CLEAN_AFTER_M600 is defined and params.CLEAN_AFTER_M600 | lower == 'false' %}
{% set clean_m600 = 0 %}
{% endif %}
################## Set Variables ##################
## Use CLeaning
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=cleaning VALUE={ cleaning } ; set cleaning
## Cleaning Scenarios
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_probe VALUE={ clean_probe } ; set clean probe
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_end VALUE={ clean_end } ; set clean end
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=post_clean_home VALUE={ post_clean_home } ; set post clean home
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_m600 VALUE={ clean_m600 } ; set clean m600
## Cleaning Coordinates
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_x VALUE={ clean_x } ; set clean x
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_y VALUE={ clean_y } ; set clean y
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_z VALUE={ clean_z } ; set clean z
## Cleaning Wipe
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_wipe_qty VALUE={ clean_wipe_qty } ; set clean wipe qty
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_wipe_dist VALUE={ clean_wipe_dist } ; set clean wipe dist
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_wipe_spd VALUE={ clean_wipe_spd } ; set clean wipe speed
## Cleaning Raise
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_raise_dist VALUE={ clean_raise_dist } ; set clean raise dist
## Cleaning Temperture
SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=clean_temp VALUE={ clean_temp } ; set clean temp
################################
######## SET_DEFAULTS ##########
################################
[gcode_macro SET_DEFAULTS]
description: Reset some defaults
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
{% set mode = params.MODE|default('none')|lower %} ; get mode
{% if mode == 'none' %} ; if no mode is specified, reset all
SET_GCODE_OFFSET Z={printcfg.z_offset} ; reset Z offset
M220 S{printcfg.default_speed_factor} ; reset speed factor
{% elif mode == 'start' %} ; if start mode is specified, reset only start values
{% if printcfg.start_z_offset == True %} ; if start Z offset is enabled, reset it
SET_GCODE_OFFSET Z={printcfg.z_offset} ; reset Z offset
{% endif %}
{% if printcfg.start_speed_factor == True %} ; if start speed factor is enabled, reset it
M220 S{printcfg.default_speed_factor} ; reset speed factor
{% endif %}
{% elif mode == 'end' %} ; if end mode is specified, reset only end values
{% if printcfg.end_z_offset == True %} ; if end Z offset is enabled, reset it
SET_GCODE_OFFSET Z={printcfg.z_offset} ; reset Z offset
{% endif %}
{% if printcfg.end_speed_factor == True %} ; if end speed factor is enabled, reset it
M220 S{printcfg.default_speed_factor} ; reset speed factor
{% endif %}
SET_NOZZLE ; set nozzle-specific settings
SET_MATERIAL ; set material-specific settings
{% endif %}
################################
########## SCRUBBER ############
################################
[gcode_macro SCRUBBER]
description: Run the Nevermore for a set time
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables
M{printcfg.output} Scrubbing VOCs ; status feedback
{% if printcfg.led_status == True %}
{printcfg.status_clean} ; LED feedback
{% endif %}
## Turn on Nevermore to scrub
SET_FAN_SPEED FAN={printcfg.nevermore_name} SPEED={printcfg.scrub_speed}
## Set shut-off timer
UPDATE_DELAYED_GCODE ID=scrub_timer DURATION={printcfg.scrub_time}
[delayed_gcode scrub_timer]
gcode:
{% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables