[pause_resume]

[gcode_macro PAUSE]
description: Pause the actual running print
rename_existing: PAUSE_BASE
# change this if you need more or less extrusion
variable_extrude: 1.0
gcode:
  ##### read E from pause macro #####
  {% set E = printer["gcode_macro PAUSE"].extrude|float %}
  ##### set park positon for x and y #####
  # default is your max posion from your printer.cfg
  {% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %}
  {% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %}
  ##### calculate save lift position #####
  {% set max_z = printer.toolhead.axis_maximum.z|float %}
  {% set act_z = printer.toolhead.position.z|float %}
  {% if act_z < (max_z - 2.0) %}
      {% set z_safe = 2.0 %}
  {% else %}
      {% set z_safe = max_z - act_z %}
  {% endif %}
  ##### end of definitions #####
  PAUSE_BASE
  G91
  {% if printer.extruder.can_extrude|lower == 'true' %}
    G1 E-{E} F2100
  {% else %}
    {action_respond_info("Extruder not hot enough")}
  {% endif %}
  {% if "xyz" in printer.toolhead.homed_axes %}
    G1 Z{z_safe} F900
    G90
    G1 X{x_park} Y{y_park} F6000
  {% else %}
    {action_respond_info("Printer not homed")}
  {% endif %} 
  
[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
  ##### read E from pause macro #####
  {% set E = printer["gcode_macro PAUSE"].extrude|float %}
  #### get VELOCITY parameter if specified ####
  {% if 'VELOCITY' in params|upper %}
    {% set get_params = ('VELOCITY=' + params.VELOCITY)  %}
  {%else %}
    {% set get_params = "" %}
  {% endif %}
  ##### end of definitions #####
  {% if printer.extruder.can_extrude|lower == 'true' %}
    G91
    G1 E{E} F2100
  {% else %}
    {action_respond_info("Extruder not hot enough")}
  {% endif %}  
  RESUME_BASE {get_params}

[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
gcode:
  TURN_OFF_HEATERS
  CANCEL_PRINT_BASE
  
# The print bed can move so far to the front, that the nozzle can reach the
# plastic cover of the print bed heater cable (only when the bed is moved by
# hand). By homing the Y axis before the X axis, it is ensured the nozzle will
# not melt through the plastic part.
# BEWARE: You will lose the ability to home axes individually. The printer will
# always home all axes for every G28 command.
#[homing_override]
#gcode:
# G28 Y0
# G28 X0
# G28 Z0

# ================================================================================
# GCode Macro: START_PRINT
# Add START_PRINT in your slicers starting script. 
# ================================================================================
[gcode_macro START_PRINT]
gcode:
    G28; Home all axes    
    BED_MESH_CALIBRATE    
    G92 E0; Reset Extruder
    G1 Z25.0 F3000; Move Z Axis up little to prevent scratching of Heat Bed
    G1 X0.1 Y20 Z0.3 F5000.0; Move to start position
    G1 X0.1 Y200.0 Z0.3 F1500.0 E15; Draw the first line
    G1 X0.4 Y200.0 Z0.3 F5000.0; Move to side a little
    G1 X0.4 Y20 Z0.3 F1500.0 E30; Draw the second line
    G92 E0; Reset Extruder
    G1 Z25.0 F3000; Move Z Axis up little to prevent scratching of Heat Bed
    M118 punt gcode_macro START_PRINT
    
# ================================================================================
# GCode Macro: END_PRINT
# Add END_PRINT in your slicers ending script
# ================================================================================
[gcode_macro END_PRINT]
gcode:
    G91; Relative Positioning
    G1 Z+10; Move Z up so it doesn't hit anything
    G90; Absolute Positioning
    G1 Y190 F1500; bring Y up front 
#    G10 ; set tool offset?  or retract?
#    G1 E-10 F300; Retrack-10
    G1 X10 Y220 F2000; Move to X10, Y220
    M104 S0; Turn off Extruder temperature (set it to 0)
    M140 S0; Turn off Bed temperature (set it to 0)
    M106 S0; turn off cooling fan
    M84; Disable steppers
# ================================================================================
# GCode Macro G29
# Fires when G29 is sent to the printer
# ================================================================================
#[gcode_macro G29]
#gcode:
#    G1 Z10 F600
#    G4 P200
#    G1 Z10 F600
#    G4 P100

### Raspberry Pi als MCU om de GPIO te gebruiken voor in- en output
