[force_move]
enable_force_move: True


[respond]
default_type: echo

[gcode_macro G31]
gcode:
      RUN_SHELL_COMMAND CMD=clear_plr
      SAVE_VARIABLE VARIABLE=was_interrupted VALUE=False
[gcode_shell_command clear_plr]
command: sh /home/mks/clear_plr.sh
timeout: 5.
[gcode_macro save_last_file]
gcode:

  {% set svv = printer.save_variables.variables %}

  {% set filepath=printer.virtual_sdcard.file_path %}

  {% set filename=filepath.split('/')%}

  SAVE_VARIABLE VARIABLE=last_file VALUE='"{ filename[-1] }"'
  SAVE_VARIABLE VARIABLE=filepath VALUE='"{ printer.virtual_sdcard.file_path }"'


  #M118 Last File: { filename[-1] }

[gcode_macro clear_last_file]
gcode:
  {% set filename='' %}
  {% set filepath='' %}
  SAVE_VARIABLE VARIABLE=last_file VALUE='"{ filename }"'
  SAVE_VARIABLE VARIABLE=filepath VALUE='"{ filepath }"'
  
[gcode_shell_command POWER_LOSS_RESUME]
command: /home/mks/plr.sh
timeout: 420.


[gcode_macro RESUME_INTERRUPTED]
gcode =
    SET_KINEMATIC_POSITION X=0
    SET_KINEMATIC_POSITION Y=0
    SET_KINEMATIC_POSITION Z=0
    {% set z_height = params.Z_HEIGHT|default(printer.save_variables.variables.power_resume_z)|float %}
    {% set last_file = params.GCODE_FILE|default(printer.save_variables.variables.last_file)|string %}
    m118 {last_file}

    RUN_SHELL_COMMAND CMD=POWER_LOSS_RESUME PARAMS="{z_height} \"{last_file}\""
    SDCARD_PRINT_FILE FILENAME=plr/"{last_file}"
[gcode_macro LOG_Z]
gcode:
    {% set z_pos = printer.gcode_move.gcode_position.z %}
    RESPOND MSG="Current Z is {z_pos}"
    SAVE_VARIABLE VARIABLE=power_resume_z VALUE={z_pos}
[save_variables]
filename =/home/mks/printer_data/config/saved_variables.cfg