-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathmymacros_code.cfg
953 lines (723 loc) · 31.7 KB
/
mymacros_code.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
##### LH Stinger User Macros Code #####
[virtual_sdcard]
path: ~/printer_data/gcodes
on_error_gcode:
RESPOND TYPE=command MSG='Vritual SD error triggered. Starting CANCEL_PRINT'
CANCEL_PRINT
[gcode_macro CANCEL_PRINT]
rename_existing: CANCEL_PRINT_BASE
gcode:
PRINT_END
CANCEL_PRINT_BASE
[gcode_macro RESET]
description: RESTART
gcode:
RESTART
##### Slicer Macros #####
[gcode_macro PRINT_START_LHS]
gcode:
# Parameters
{% set bedtemp = params.BED|int %}
{% set hotendtemp = params.HOTEND|int %}
{% set autopurge = params.AUTOPURGE| default(0) | int %}
{% set automesh = params.AUTOMESH| default(0) | int %}
{% set quietmode = params.QUIETMODE| default(0) | int %}
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
_CHECK_SETTINGS_VERSION_LHS # Settings file version check
{% if client.stop_bg_services == True %}
_STOP_CRON # Stop background host scheduled tasks
{% endif %}
SAVE_GCODE_STATE NAME=print_start
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=end_park VALUE=False
G90
M83
## If Y axis homed, move bed to center to avoid heating over the motors
{% if "y" in printer.toolhead.homed_axes %}
{% set home = printer.configfile.settings.xz_dockable_probe.home_xy_position.split(',') %}
G1 Y{home[1]} F{150*60}
{% endif %}
RESPOND TYPE=command MSG='Heating Bed. Please wait'
M190 S{bedtemp} # Heat bed and wait
M104 S{hotendtemp-60} # Pre-heat hotend to target-60C to prevent oozing
RESPOND TYPE=command MSG='Homing printer'
PROBE_LOCK
SET_VELOCITY_LIMIT VELOCITY={client.velocity_start} ACCEL={client.accel_start} # Lower velocity for setup moves
G28 # home
Z_TILT_ADJUST SAMPLES=1 RETRY_TOLERANCE=0.02
Z_TILT_ADJUST SAMPLES=1
G28 Z
{% if automesh == 0 %} # Selecting bed mesh based on temperature. REQ Profiles: "default", "75", "105"
RESPOND TYPE=command MSG='Automesh OFF. Loading saved mesh'
{% if client.use_multi_bed_mesh_profiles == True %}
{% if bedtemp > 95 %}
BED_MESH_PROFILE LOAD=105
{% elif bedtemp > 69 %}
BED_MESH_PROFILE LOAD=75
{% else %}
BED_MESH_PROFILE LOAD=default
{% endif %}
{% else %}
BED_MESH_PROFILE LOAD=default
{% endif %}
{% elif automesh == -1 %} # Skip bed mesh
RESPOND TYPE=command MSG='Automesh disabled. Continuing'
BED_MESH_CLEAR
{% else %}
BED_MESH_CLEAR
BED_MESH_CALIBRATE ADAPTIVE=1
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=automeshed VALUE=True
G28 Z
{% endif %}
PROBE_UNLOCK
PROBE_DETACH
G1 X{client.nozzle_heat_x} Y{client.nozzle_heat_y} Z{client.nozzle_heat_z} F3000 # Safe spot to heat up nozzle
RESPOND TYPE=command MSG='Heating Hotend. Please wait'
M109 S{hotendtemp} # Heat hotend and wait
{% if autopurge == 0 %}
G1 E{client.my_end_retract} F{10*60} # Prime nozzle
{% else %}
_PURGE_LINE
{% endif %}
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} # Restore velocity to default
G92 E0 # Reset Extruder
RESPOND TYPE=command MSG='Print Started'
RESTORE_GCODE_STATE NAME=print_start
G90
#Quiet Mode
{% if quietmode == 1 %}
Qmode
{% endif %}
[gcode_macro PRINT_END]
gcode:
TURN_OFF_HEATERS # Safety call in case of any other move fails
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
{% set can_extrude = True if printer.toolhead.extruder == '' # no extruder defined in config
else printer[printer.toolhead.extruder].can_extrude %} # status of active extruder
G90 # Absolute Position
M83 # Relative Extrude
G92 E0 # Reset Extruder
{% if "xyz" in printer.toolhead.homed_axes and can_extrude == True %}
G1 E-0.2 F{60*60} # Tiny retract at end Print
{% set z_move = [printer.toolhead.axis_maximum.z, printer.toolhead.position.z+4] | min %} # Hop
G1 X40 Z{z_move} E-0.8 F{60*400} # Print end retract
#Tip Forming and Filament Park
{% if client.my_end_retract > 0 %}
G1 E-{(client.my_end_retract)*0.5} F{10*60}
G1 E{(client.my_end_retract)*0.5} F{80*60}
G1 E-{(client.my_end_retract)} F{10*80}
{% endif %}
{% endif %}
RESPOND TYPE=command MSG='Print Ended! Turning things off.'
{% if rt.automeshed == True %} # Clear Adaptive Bed Mesh
BED_MESH_CLEAR
{% endif %}
G90 # Absolute positioning
{% if rt.end_park == False %}
_TOOLHEAD_PARK_PAUSE_CANCEL
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=end_park VALUE=True
{% endif %}
Qmode_exit
OFF
{% if client.stop_bg_services == True %}
_START_CRON # Enable background host scheduled tasks
{% endif %}
M117 Done!
[gcode_macro OFF]
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
M84 # turn steppers off
TURN_OFF_HEATERS # turn bed / hotend off
M107 # turn fans off
M106.1 S0 # force part fan off
{% if client.has_aux_fan == True %} # force aux fan off
SET_FAN_SPEED FAN=aux SPEED=0
{% endif %}
#SET_FAN_SPEED FAN=Exhaust SPEED=0 # turn exhaust fan off
#SET_FAN_SPEED FAN=BedFans SPEED=0 # bed fan off
#SET_PIN PIN=caselight VALUE=0 # turn case light off
RESPOND TYPE=command MSG='All OFF'
[gcode_macro M109] # Wait Hotend Temp
rename_existing: M109.1
gcode:
{% set s = params.S|float %}
{% set range = printer['gcode_macro _CLIENT_VARIABLE'].heat_range if printer['gcode_macro _CLIENT_VARIABLE'].heat_range is defined else 5 %}
M104 {% for p in params %}{'%s%s' % (p, params[p])}{% endfor %} # Set hotend temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={s-range} MAXIMUM={s+range} # Wait for hotend temp (within n degrees)
{% endif %}
[gcode_macro M190] # Wait Bed Temp
rename_existing: M190.1
gcode:
{% set s = params.S|float %}
{% set range = printer['gcode_macro _CLIENT_VARIABLE'].heat_range if printer['gcode_macro _CLIENT_VARIABLE'].heat_range is defined else 5 %}
M140 {% for p in params %}{'%s%s' % (p, params[p])}{% endfor %} # Set bed temp
{% if s != 0 %}
TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={s-range} MAXIMUM={s+range} # Wait for bed temp (within n degrees)
{% endif %}
[gcode_macro _PURGE_LINE] # Purge line
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
G90
M83
G0 X{client.purge_x} Y{client.purge_y} Z{client.purge_z} F12000
G1 E{client.my_end_retract} F500
G1 X{client.purge_x+client.purge_length} Y{client.purge_y} E{0.2*client.purge_amount} F500
G1 X{client.purge_x+client.purge_length+5} E-0.2 F1000
G1 Y{client.purge_y+30} Z{client.purge_z+10} E-0.5 F18000
G1 E0.2 F600
#### Quiet Modes #####
[gcode_macro Qmode]
variable_accel: 0
variable_velocity: 0
variable_square_corner_velocity: 0
variable_min_cruise: 0.0
variable_fan_value: 0.00
variable_fan_aux_value: 0.00
variable_fan2_value: 0.00
variable_speed_factor: 0
variable_is_aux_linked: True
variable_manual_aux: 0
gcode:
{% set printer_state = printer.print_stats.state %}
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=q_active VALUE=True
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=accel VALUE={printer.toolhead.max_accel}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=velocity VALUE={printer.toolhead.max_velocity}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=square_corner_velocity VALUE={printer.toolhead.square_corner_velocity}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=min_cruise VALUE={printer.toolhead.minimum_cruise_ratio}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=speed_factor VALUE={printer.gcode_move.speed_factor}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=fan_value VALUE={printer.fan.speed}
{% if client.has_aux_fan == True %}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=fan_aux_value VALUE={printer['fan_generic aux'].speed}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=is_aux_linked VALUE={client.link_aux}
SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=manual_aux VALUE={rt.manual_aux}
{% endif %}
# Switch to Stealthchop
{% if client.q_stealthchop|int == True %}
SET_TMC_FIELD STEPPER=stepper_x FIELD=TPWMTHRS value=0
SET_TMC_FIELD STEPPER=stepper_y FIELD=TPWMTHRS value=0
SET_TMC_FIELD STEPPER=stepper_y1 FIELD=TPWMTHRS value=0
SET_TMC_FIELD STEPPER=stepper_z FIELD=TPWMTHRS value=0
SET_TMC_FIELD STEPPER=stepper_z1 FIELD=TPWMTHRS value=0
{% endif %}
# Set Motion Parameters
M220 S{client.q_feedrate} #set feedrate
RESPOND MSG="Feedrate: {client.q_feedrate}"
RESPOND MSG="Setting Motion Parameters: VELOCITY={client.q_max_velocity} ACCEL={client.q_max_accel} SQUARE_CORNER_VELOCITY={client.q_scv} MINIMUM_CRUISE_RATIO={client.q_min_cruise}"
SET_VELOCITY_LIMIT VELOCITY={client.q_max_velocity} ACCEL={client.q_max_accel} SQUARE_CORNER_VELOCITY={client.q_scv} MINIMUM_CRUISE_RATIO={client.q_min_cruise}
RESPOND MSG="Finished Setting Motion Parameters"
# Set Fan Parameters
MAX_FAN MAX_FAN={client.q_fan_max}
# Set AUX Fan Parameters
MAX_FAN LINK_AUX={client.q_link_aux}
MAX_FAN MANUAL_AUX={client.q_fan_aux}
RESPOND TYPE=command MSG='Quiet Mode Active'
[gcode_macro Qmode_exit]
gcode:
{% set printer_state = printer.print_stats.state %}
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
{% if rt.q_active == True %}
SET_VELOCITY_LIMIT ACCEL={printer['gcode_macro Qmode'].accel} VELOCITY={printer['gcode_macro Qmode'].velocity} SQUARE_CORNER_VELOCITY={printer['gcode_macro Qmode'].square_corner_velocity}
SET_VELOCITY_LIMIT MINIMUM_CRUISE_RATIO={printer['gcode_macro Qmode'].min_cruise}
M220 S{printer['gcode_macro Qmode'].speed_factor * 100}
# Restore Fan Values
MAX_FAN MAX_FAN=100
M106 S{printer['gcode_macro Qmode'].fan_value*255}
{% if client.has_aux_fan == True %}
MAX_FAN LINK_AUX={printer['gcode_macro Qmode'].is_aux_linked}
MAX_FAN MANUAL_AUX={printer['gcode_macro Qmode'].manual_aux}
M106 P2 S{printer['gcode_macro Qmode'].fan_aux_value*255}
{% endif %}
# Switch to Spreadcycle - Use with TMC 2240 only
{% if client.q_stealthchop|int == True %}
SET_TMC_FIELD STEPPER=stepper_x FIELD=TPWMTHRS value=1048575
SET_TMC_FIELD STEPPER=stepper_y FIELD=TPWMTHRS value=1048575
SET_TMC_FIELD STEPPER=stepper_y1 FIELD=TPWMTHRS value=1048575
SET_TMC_FIELD STEPPER=stepper_z FIELD=TPWMTHRS value=1048575
SET_TMC_FIELD STEPPER=stepper_z1 FIELD=TPWMTHRS value=1048575
{% endif %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=q_active VALUE=False
RESPOND TYPE=command MSG='Quiet Mode Disabled'
{% endif %}
##### Acceleration #####
[gcode_macro SET_VELOCITY_LIMIT] # Set Velocity Limits
rename_existing: _SET_VELOCITY_LIMIT
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
{% set base_params = "" %}
{% if rt.q_active == False %} # Normal behaviour
{% if 'VELOCITY' in params %}
{% set base_params = base_params ~ ' VELOCITY=' ~ params.VELOCITY %}
{% endif %}
{% if 'ACCEL' in params %}
{% set adjusted_accel = params.ACCEL|int * client.accel_factor %}
{% set base_params = base_params ~ ' ACCEL=' ~ adjusted_accel %}
{% endif %}
{% if 'MINIMUM_CRUISE_RATIO' in params %}
{% set base_params = base_params ~ ' MINIMUM_CRUISE_RATIO=' ~ params.MINIMUM_CRUISE_RATIO %}
{% endif %}
{% if 'SQUARE_CORNER_VELOCITY' in params %}
{% set base_params = base_params ~ ' SQUARE_CORNER_VELOCITY=' ~ params.SQUARE_CORNER_VELOCITY %}
{% endif %}
_SET_VELOCITY_LIMIT {base_params}
{% else %} # Qmode behaviour
{% if 'VELOCITY' in params %}
{% set base_params = (base_params ~ ' VELOCITY=' ~ [params.VELOCITY|int, client.q_max_velocity | int] | min | string) %}
{% endif %}
{% if 'ACCEL' in params %}
{% set lim_accel = [(params.ACCEL | float * client.q_accel_factor)|int, client.q_max_accel | int] | min %}
{% set base_params = (base_params ~ ' ACCEL=' ~ lim_accel | string) %}
{% endif %}
{% if 'SQUARE_CORNER_VELOCITY' in params %}
{% set base_params = (base_params ~ ' SQUARE_CORNER_VELOCITY=' ~ [params.SQUARE_CORNER_VELOCITY|int, client.q_scv | int] | min | string) %}
{% endif %}
{% if 'MINIMUM_CRUISE_RATIO' in params %}
{% set base_params = (base_params ~ ' MINIMUM_CRUISE_RATIO=' ~ [params.MINIMUM_CRUISE_RATIO|float, client.q_min_cruise | float] | max | string) %}
{% endif %}
_SET_VELOCITY_LIMIT {base_params}
{% endif %}
[gcode_macro M204] # Set Acceleration
rename_existing: M204.1
gcode:
{% if 'P' in params %}
{% set my_s = params.P %}
{% elif 'S' in params %}
{% set my_s = params.S %}
{% elif 'T' in params %}
{% set my_s = params.T %}
{% endif %}
{% if my_s is defined %}
SET_VELOCITY_LIMIT ACCEL={my_s|float}
{% endif %}
#### Fans #####
[gcode_macro M106] #Set Fan
rename_existing: M106.1
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
{% set vars = printer["gcode_macro M106"] %}
{% if 'S' in params and params.P is not defined %} # Part fan control
{% if rt.manual_fan < 0 %} # normal mode
{% set S = params.S|float %}
{% set S = [(S * rt.fan_multiplier), (rt.max_fan*2.55)] | min %}
{% else %}
{% set S = rt.manual_fan*2.55 %} # manual mode
{% endif %}
M106.1 S{'%d' % (S)}
{% if client.has_aux_fan == True and client.link_aux == True and rt.manual_aux < 0 %}
SET_FAN_SPEED FAN=aux SPEED={(S/255)*client.aux_ratio} # linked aux mode
{% endif %}
{% endif %}
{% if 'S' in params and params.P is defined and client.has_aux_fan == True %} # When P2 (AUX) value is present
{% set S = params.S|float %}
{% if rt.manual_aux < 0 and client.link_aux == False %} # normal unlinked aux mode
{% set S = [(S * rt.fan_multiplier), (rt.max_fan*2.55)] | min %}
SET_FAN_SPEED FAN=aux SPEED={S/255}
{% elif rt.manual_aux >= 0 %} # manual aux
SET_FAN_SPEED FAN=aux SPEED={rt.manual_aux/100}
{% endif %}
{% endif %}
[gcode_macro MAX_FAN] #Set Fan UI
description: Set max fan speed or override it to manual control
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set MAX_FAN_P = params.MAX_FAN | default(0) | int %} # Maximum value that the slicer can set
{% set FAN_MULTIPLIER_P = params.FAN_MULTIPLIER | default(0) | float %} # Global fan multplier
{% set MANUAL_FAN_P = params.MANUAL_FAN | default(0) | int %} # -1 = Manual fan disabled, Manual fan control = 0-100, Slicer control off
{% set MANUAL_AUX_P = params.MANUAL_AUX | default(0) | int %} # -1 = Manual fan disabled, Manual fan control = 0-100, Slicer control off
{% set LINK_AUX_P = params.LINK_AUX | default(0) | int %} # Links Aux fan to Part fan
{% set AUX_RATIO_P = params.AUX_RATIO | default(0) | float %} # Aux fan multiply factor when linked to Part fan
{% if 'MAX_FAN' in params %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=max_fan VALUE={MAX_FAN_P}
RESPOND MSG="Setting MAX_FAN to: {MAX_FAN_P}"
{% endif %}
{% if 'MANUAL_FAN' in params %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=manual_fan VALUE={MANUAL_FAN_P}
RESPOND MSG="Setting MANUAL_FAN to: {MANUAL_FAN_P}"
{% endif %}
{% if 'MANUAL_AUX' in params %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=manual_aux VALUE={MANUAL_AUX_P}
RESPOND MSG="Setting MANUAL_AUX to: {MANUAL_AUX_P}"
{% endif %}
{% if 'FAN_MULTIPLIER' in params %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE_RUNTIME VARIABLE=fan_multiplier VALUE={FAN_MULTIPLIER_P}
RESPOND MSG="Setting FAN_MULTIPLIER to: {FAN_MULTIPLIER_P}"
{% endif %}
{% if 'LINK_AUX' in params %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE VARIABLE=link_aux VALUE={LINK_AUX_P}
RESPOND MSG="Setting LINK_AUX to: {LINK_AUX_P}"
{% endif %}
{% if 'AUX_RATIO' in params %}
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE VARIABLE=aux_ratio VALUE={AUX_RATIO_P}
RESPOND MSG="Setting AUX_RATIO to: {AUX_RATIO_P}"
{% endif %}
M106 S{printer.fan.speed*255.0}
{% if client.has_aux_fan == True %}
M106 P2 S{printer['fan_generic aux'].speed*255.0}
{% endif %}
[gcode_macro M107] # Fans OFF
rename_existing: M107.1
gcode:
M106 S0
M106 P2 S0
##### Filament Management #####
[gcode_macro M600]
description: Filament change
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
PAUSE X={client.nozzle_heat_x} Y={client.nozzle_heat_y} Z_MIN={client.change_z_min}
FILAMENT_UNLOAD
RESPOND TYPE=command MSG='Load next filament and Resume'
[gcode_macro FILAMENT_LOAD]
gcode:
_CLOSE_UI
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set EXTRUDER_TEMP = params.TEMP|default(0) | int %}
{% if EXTRUDER_TEMP == 0 %}
{% if printer['extruder'].target >= 220 %}
{% set EXTRUDER_TEMP = printer['extruder'].target %}
{% else %}
{% set EXTRUDER_TEMP = 220 %}
{% endif %}
{% endif %}
M109 S{EXTRUDER_TEMP} #set hotend temperature and wait
SAVE_GCODE_STATE NAME=load_state
M83 # set extruder to relative
G1 E{client.my_load_len} F800 # load
G1 E{client.my_load_prime_len} F250 # prime nozzle with filament
G1 E-8 F600
RESTORE_GCODE_STATE NAME=load_state
M400 # wait to finish above
RESPOND TYPE=command MSG='Filament Loaded'
_FILAMENT_MANAGEMENT_END
[gcode_macro FILAMENT_UNLOAD]
gcode:
_CLOSE_UI
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set EXTRUDER_TEMP = params.TEMP|default(0) | int %}
{% if EXTRUDER_TEMP == 0 %}
{% if printer['extruder'].target >= 220 %}
{% set EXTRUDER_TEMP = printer['extruder'].target %}
{% else %}
{% set EXTRUDER_TEMP = 220 %}
{% endif %}
{% endif %}
M109 S{EXTRUDER_TEMP} #set hotend temperature and wait
SAVE_GCODE_STATE NAME=unload_state
#M106 S0 # Turn off fan
M83 # set extruder to relative
G0 E2 F300 # extract filament to cold end
G0 E-8 F2000 # extract filament to cold end
G4 P4000 # wait for 4 seconds
G0 E8 F2000 # push back the filament to strive stringing
G0 E-27 F2150 # Extract fast in the cold zone
G1 E-{client.my_unload_len} F300 # Pull rest. Continue extraction slow allow filament to be cooled enough before reaches the gears
RESTORE_GCODE_STATE NAME=unload_state
M400 # wait to finish above
RESPOND TYPE=command MSG='Filament Unloaded'
_FILAMENT_MANAGEMENT_END
[gcode_macro FILAMENT_PURGE]
gcode:
_CLOSE_UI
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
SAVE_GCODE_STATE NAME=purge_state
#M106 S0 # Turn off fan
M83
G1 E{client.my_purge_len} F250 # prime nozzle with filament
RESTORE_GCODE_STATE NAME=purge_state
M400 # wait to finish above
RESPOND TYPE=command MSG='Filament Purged'
_FILAMENT_MANAGEMENT_END
[gcode_macro _COOLDOWN]
gcode:
M104 S0
_CLOSE_UI
[gcode_macro _FILAMENT_MANAGEMENT_END]
gcode:
RESPOND TYPE=command MSG="action:prompt_begin Filament Management"
RESPOND TYPE=command MSG="action:prompt_text Proceed:"
RESPOND TYPE=command MSG="action:prompt_button_group_start"
RESPOND TYPE=command MSG="action:prompt_button Load|FILAMENT_LOAD|primary"
RESPOND TYPE=command MSG="action:prompt_button Unload|FILAMENT_UNLOAD|warning"
RESPOND TYPE=command MSG="action:prompt_button Purge|FILAMENT_PURGE|secondary"
RESPOND TYPE=command MSG="action:prompt_button_group_end"
RESPOND TYPE=command MSG="action:prompt_button_group_start"
RESPOND TYPE=command MSG="action:prompt_button Close|_CLOSE_UI|error"
RESPOND TYPE=command MSG="action:prompt_button Resume|RESUME|default"
RESPOND TYPE=command MSG="action:prompt_button Cooldown|_COOLDOWN|default"
RESPOND TYPE=command MSG="action:prompt_button_group_end"
RESPOND TYPE=command MSG="action:prompt_show"
[gcode_macro COLD_PULL] # Experimental. Requires lowering extruder print min temp to ~80C # When you hear the extruder perform the last fast retraction, go and pull out the filament by hand
gcode:
{% set EXTRUDER = params.EXTRUDER|default(220) %}
{% set PULLTEMP = params.PULLTEMP|default(85) %}
G90
M83
G92 E0
M109 S{EXTRUDER}
M104 S{PULLTEMP}
M106 S120 #fan on
FORCE_MOVE STEPPER=extruder DISTANCE=7 VELOCITY=2 ACCEL=200
FORCE_MOVE STEPPER=extruder DISTANCE=5 VELOCITY=1 ACCEL=200
M109 S{PULLTEMP}
FORCE_MOVE STEPPER=extruder DISTANCE=-25 VELOCITY=1 ACCEL=200
FORCE_MOVE STEPPER=extruder DISTANCE=-50 VELOCITY=4 ACCEL=200
FORCE_MOVE STEPPER=extruder DISTANCE=-150 VELOCITY=50 ACCEL=600
M400 # wait to finish above
RESPOND TYPE=command MSG='Remove Filament Now!'
G92 E0
M106 S0
M104 S0
##### Moves #####
[gcode_macro _GO_HOME]
gcode:
{% set home = printer.configfile.settings.xz_dockable_probe.home_xy_position.split(',') %}
G90
G1 x{home[0]} y{home[1]} F{150*60}
G1 z20 F{25*60}
[gcode_macro _GO_CENTER]
gcode:
G90
{% set home = printer.configfile.settings.xz_dockable_probe.home_xy_position.split(',') %}
G1 x{home[0]} y{home[1]} Z{printer.toolhead.axis_maximum.z/2} F{200*60}
[gcode_macro _GO_Z_OFFSET]
gcode:
{% set home = printer.configfile.settings.xz_dockable_probe.home_xy_position.split(',') %}
{% set x_offset = printer.configfile.settings.probe.x_offset|float %}
{% set y_offset = printer.configfile.settings.probe.y_offset|float %}
QD_DOCK
G90
G1 x{home[0]|float+x_offset} y{home[1]|float+y_offset} F{150*60}
G1 z12 F{25*60}
##### Force Moves #####
[gcode_macro FORCE_UP]
gcode:
SET_KINEMATIC_POSITION X=127 Y=127 Z=150
G90
G1 Z180 F600
M84
[gcode_macro FORCE_DOWN]
gcode:
SET_KINEMATIC_POSITION X=127 Y=127 Z=150
G90
G1 Z120 F600
M84
[gcode_macro FORCE_SET_POS]
gcode:
{% if 'resonance_tester' in printer.configfile.settings %}
{% set home = printer.configfile.settings.resonance_tester.probe_points[0] %}
{% endif %}
{% set K_X = params.X | default(home[0] if home else 127 ) | float %}
{% set K_Y = params.Y | default(home[1] if home else 127) | float %}
{% set K_Z = params.Z | default(home[2] if home else 0) | float %}
SET_KINEMATIC_POSITION X={K_X} Y={K_Y} Z={K_Z}
# Moving To Full step positions:
G91
G1 X0.1 Y0.1 Z0.025
SET_KINEMATIC_POSITION X={K_X} Y={K_Y} Z={K_Z}
G90
# Done
# Cycling motion
G91
G1 X0.001 Y0.001 Z0.001
G1 X-0.001 Y-0.001 Z-0.001
G90
[gcode_macro DISABLE]
gcode:
M84
##### Park by Ellis #####
# Park front center
[gcode_macro PARKFRONT]
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %}
G28 # home if not already homed
{% endif %}
SAVE_GCODE_STATE NAME=PARKFRONT
G90 # absolute positioning
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_minimum.y+5} Z{printer.toolhead.axis_maximum.z/2} F6000
RESTORE_GCODE_STATE NAME=PARKFRONT
# Park front center, but low down.
[gcode_macro PARKFRONTLOW]
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %}
G28 # home if not already homed
{% endif %}
SAVE_GCODE_STATE NAME=PARKFRONT
G90 # absolute positioning
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_minimum.y+5} Z20 F6000
RESTORE_GCODE_STATE NAME=PARKFRONT
# Park top rear left
[gcode_macro PARKREAR]
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %}
G28 # home if not already homed
{% endif %}
SAVE_GCODE_STATE NAME=PARKREAR
G90 # absolute positioning
G0 X{printer.toolhead.axis_minimum.x+10} Y{printer.toolhead.axis_maximum.y-10} Z{printer.toolhead.axis_maximum.z-50} F6000
RESTORE_GCODE_STATE NAME=PARKREAR
# Park at center of build volume
[gcode_macro PARKCENTER]
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %}
QD_home_tilt # home if not already homed
{% endif %}
_GO_Z_OFFSET
# Park 15mm above center of bed
[gcode_macro PARKBED]
gcode:
{% if "xyz" not in printer.toolhead.homed_axes %}
G28 # home if not already homed
{% endif %}
SAVE_GCODE_STATE NAME=PARKBED
G90 # absolute positioning
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_maximum.y/2} Z15 F6000
RESTORE_GCODE_STATE NAME=PARKBED
#### Utilities ####
[gcode_macro VIBRATION_TEST] # Change accel per hz in printer.cfg under resonace_holder
gcode:
# Axis
{% set axis = params.AXIS|string %}
# Seconds
{% set seconds = params.SECONDS|int %}
#Freq
{%set int = params.FREQ| int%}
HOLD_RESONANCE {rawparams}
[gcode_macro AWD_SYNC]
description: Remember to move the bed to the center and loosen the front stepper pulley grub screws
gcode:
{% set iterations = params.ITERATIONS|default(4)|int %}
{% set p_time = params.PAUSE_TIME|default(0)|int %}
{% for i in range(iterations) %}
SET_KINEMATIC_POSITION X=117 Y=117 Z=20
G91
### Moving to full step motor position
G1 X0.1 Y0.1 Z0.025
G1 X0.02 Y0.02 Z0.05
G1 X-0.02 Y-0.02 Z-0.05
{% if i < (iterations-1) %}
M84
{% endif %}
G4 P500
{% if i == 1 %}
G4 P{1000*p_time}
{% endif %}
{% endfor %}
G90
# Done
[gcode_macro Z_OFFSET_PRINT]
description: Prints the z offset value
gcode:
{% set config = printer.configfile.config %}
# Find probe config in configfile
{% if config["probe"] %}
# probe section found
{% set probe = config["probe"] %}
{% set has_probe = True %}
{% else %}
# No probe or bltouch sections found
RESPOND MSG="Failed to detect probe in configfile"
{% endif %}
{% if has_probe %}
RESPOND MSG="Configured Probe Z-Offset {probe.z_offset}"
RESPOND MSG="Last Probed value was {printer.probe.last_z_result}"
{% endif %}
[gcode_macro SET_ACCEL_FACTOR]
description: Scale acceleration value by factor
gcode:
{% set factor = params.FACTOR|default(1)|float %}
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
RESPOND TYPE=command MSG='Previous ACCEL FACTOR: {client.accel_factor}'
SET_GCODE_VARIABLE MACRO=_CLIENT_VARIABLE VARIABLE=accel_factor VALUE={factor}
RESPOND TYPE=command MSG='New ACCEL FACTOR: {factor}'
[gcode_macro _DUMP_VARIABLES] # by Ellis
gcode:
{% set filter_name = params.NAME|default('')|string|lower %}
{% set filter_value = params.VALUE|default('')|string|lower %}
{% set show_cfg = params.SHOW_CFG|default(0)|int %}
{% set out = [] %}
{% for key1 in printer %}
{% for key2 in printer[key1] %}
{% if (show_cfg or not (key1|lower == 'configfile' and key2|lower in ['config', 'settings'])) and (filter_name in key1|lower or filter_name in key2|lower) and filter_value in printer[key1][key2]|string|lower %}
{% set dummy = out.append("printer['%s'].%s = %s" % (key1, key2, printer[key1][key2])) %}
{% endif %}
{% else %}
{% if filter_name in key1|lower and filter_value in printer[key1]|string|lower %}
{% set dummy = out.append("printer['%s'] = %s" % (key1, printer[key1])) %}
{% endif %}
{% endfor %}
{% endfor %}
{action_respond_info(out|join("\n"))}
[gcode_macro _STOP_CRON]
gcode:
RUN_SHELL_COMMAND CMD=stop_cron
[gcode_shell_command stop_cron]
command: /etc/init.d/cron stop
timeout: 10.
verbose: True
[gcode_macro _START_CRON]
gcode:
RUN_SHELL_COMMAND CMD=start_cron
[gcode_shell_command start_cron]
command: /etc/init.d/cron start
timeout: 10.
verbose: True
[delayed_gcode start_cron]
initial_duration: 1
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% if client.stop_bg_services == True %}
_START_CRON # Enable background host scheduled tasks
{% endif %}
[gcode_macro _CHECK_SETTINGS_VERSION_LHS]
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
{% if rt.required_version > client.version %}
RESPOND TYPE=error MSG="WARNING: mymacros_code.cfg requires an updated mymacros.cfg v({rt.required_version}) settings file. Please review the latest configuration changes and update your mymacros.cfg."
{% endif %}
[delayed_gcode _CHECK_SETTINGS_VERSION_LHS_DL]
initial_duration: 2
gcode:
{% set client = printer['gcode_macro _CLIENT_VARIABLE'] %}
{% set rt = printer['gcode_macro _CLIENT_VARIABLE_RUNTIME'] %}
{% if rt.required_version > client.version %}
RESPOND TYPE=error MSG="WARNING: mymacros_code.cfg requires an updated mymacros.cfg v({rt.required_version}) settings file. Please review the latest configuration changes and update your mymacros.cfg."
{% endif %}
##### UI #####
## https://docs.mainsail.xyz/overview/features/macro-prompts
[gcode_macro _SHOW_DEMO_BUTTON_GROUPS]
gcode:
RESPOND TYPE=command MSG="action:prompt_begin MacroPrompt"
RESPOND TYPE=command MSG="action:prompt_text These are all button colors"
RESPOND TYPE=command MSG="action:prompt_button Close|_CLOSE_UI|error"
RESPOND TYPE=command MSG="action:prompt_button default|TEST"
RESPOND TYPE=command MSG="action:prompt_button_group_start"
RESPOND TYPE=command MSG="action:prompt_button primary|TEST|primary"
RESPOND TYPE=command MSG="action:prompt_button secondary|TEST|secondary"
RESPOND TYPE=command MSG="action:prompt_button_group_end"
RESPOND TYPE=command MSG="action:prompt_button_group_start"
RESPOND TYPE=command MSG="action:prompt_button info|Z_OFFSET_PRINT|info"
RESPOND TYPE=command MSG="action:prompt_button warning|TEST|warning"
RESPOND TYPE=command MSG="action:prompt_button_group_end"
RESPOND TYPE=command MSG="action:prompt_show"
[gcode_macro _CLOSE_UI]
gcode:
RESPOND TYPE=command MSG="action:prompt_end"
##### RUNTIME VARIABLES #####
[gcode_macro _CLIENT_VARIABLE_RUNTIME]
### LH Stinger Utility Variables # Don't change manually! Internal utility variables used by macros.
variable_required_version: 2.0
variable_automeshed: False # Used internally by other macros to track the autogenerated bed mesh.
variable_max_fan: 100 # Part of MAX_FAN
variable_manual_fan: -1 # Part of MAX_FAN
variable_manual_aux: -1 # Part of MAX_FAN
variable_fan_multiplier: 1.0 # Part of MAX_FAN
variable_q_active: False # Part of Qmode
variable_end_park: False # if toolhead was parked already at print end
gcode: