################################################################################
# Board: MKS Robin Nano v1.1 (Flying Bear Reborn 2.0) / MKS Robin Nano v1.3 / MKS Robin Nano-S v1.3
# Printer: Flying Bear Ghost 4S / Ghost 5 / Reborn
# G-code Macros by ODUCCEU
################################################################################
# WARNING! DO NOT EDIT THIS FILE!
# To override settings from this file, you can copy and paste the relevant
# sections into your printer.cfg and change it there.
################################################################################

# Wipe the nozzle ##############################################################

[gcode_macro PRIME_LINE]
gcode: 
    {% set feedrate = params.F|default(10)|float * 60 %}
    {% set length = 100.0 %}
    {% set width = printer.configfile.settings.extruder.nozzle_diameter|float * 1.1 %}
    {% set height = ( (width / 0.04)|int - (width / 0.04 / 4)|int )|float * 0.04 %}
    {% set extrude = 2 * length * width * height / 2.4 %}
    {% if 'Y' in params %}
        {% set x_start = 1.0 %}
        {% set y_start = (printer.toolhead.axis_maximum.y|float - 100) / 2 %}
    {% else %}
        {% set x_start = (printer.toolhead.axis_maximum.x|float - 100) / 2 %}
        {% set y_start = 1.0 %}
    {% endif %}
    SAVE_GCODE_STATE NAME=PRIME_LINE_STATE
    SET_IDLE_TIMEOUT TIMEOUT=7200
    G0 Z0 F600 
    G0 Y1 F12000                                                                # cut the crap
    G0 Z10 F600 
    G0 X{x_start} Y{y_start} F6000                                              # move to start position
    G0 Z{height} F600 
    G91                                                                         # relative positioning
    {% if 'Y' in params %}
        G1 Y100 E{extrude} F{feedrate}                                          # prime
        G1 Y-100 F12000                                                         # wipe
    {% else %}
        G1 X100 E{extrude} F{feedrate}                                          # prime
        G1 X-100 F12000                                                         # wipe
    {% endif %}
    G0 Z10 F600 
    RESTORE_GCODE_STATE NAME=PRIME_LINE_STATE

################################################################################
