Browse Source

Merge pull request #10479 from thinkyhead/bf2_creality_power_loss_resume

[2.0.x] Creality3D Power-Loss Recovery
Scott Lahteine 6 years ago
parent
commit
023385ca59
No account linked to committer's email address
64 changed files with 1029 additions and 41 deletions
  1. 1
    1
      .travis.yml
  2. 10
    0
      Marlin/Configuration_adv.h
  3. 8
    0
      Marlin/src/Marlin.cpp
  4. 10
    0
      Marlin/src/config/default/Configuration_adv.h
  5. 10
    0
      Marlin/src/config/examples/AlephObjects/TAZ4/Configuration_adv.h
  6. 10
    0
      Marlin/src/config/examples/Anet/A6/Configuration_adv.h
  7. 10
    0
      Marlin/src/config/examples/Anet/A8/Configuration_adv.h
  8. 10
    0
      Marlin/src/config/examples/Azteeg/X5GT/Configuration_adv.h
  9. 10
    0
      Marlin/src/config/examples/BIBO/TouchX/cyclops/Configuration_adv.h
  10. 10
    0
      Marlin/src/config/examples/BIBO/TouchX/default/Configuration_adv.h
  11. 10
    0
      Marlin/src/config/examples/BQ/Hephestos/Configuration_adv.h
  12. 10
    0
      Marlin/src/config/examples/BQ/Hephestos_2/Configuration_adv.h
  13. 10
    0
      Marlin/src/config/examples/BQ/WITBOX/Configuration_adv.h
  14. 10
    0
      Marlin/src/config/examples/Cartesio/Configuration_adv.h
  15. 10
    0
      Marlin/src/config/examples/Creality/CR-10/Configuration_adv.h
  16. 10
    0
      Marlin/src/config/examples/Creality/CR-10S/Configuration_adv.h
  17. 10
    0
      Marlin/src/config/examples/Creality/CR-10mini/Configuration_adv.h
  18. 10
    0
      Marlin/src/config/examples/Creality/CR-8/Configuration_adv.h
  19. 10
    0
      Marlin/src/config/examples/Creality/Ender-2/Configuration_adv.h
  20. 10
    0
      Marlin/src/config/examples/Creality/Ender-4/Configuration_adv.h
  21. 10
    0
      Marlin/src/config/examples/Felix/Configuration_adv.h
  22. 10
    0
      Marlin/src/config/examples/FolgerTech/i3-2020/Configuration_adv.h
  23. 10
    0
      Marlin/src/config/examples/Infitary/i3-M508/Configuration_adv.h
  24. 10
    0
      Marlin/src/config/examples/JGAurora/A5/Configuration_adv.h
  25. 10
    0
      Marlin/src/config/examples/MakerParts/Configuration_adv.h
  26. 10
    0
      Marlin/src/config/examples/Malyan/M150/Configuration_adv.h
  27. 10
    0
      Marlin/src/config/examples/Malyan/M200/Configuration_adv.h
  28. 10
    0
      Marlin/src/config/examples/Micromake/C1/enhanced/Configuration_adv.h
  29. 10
    0
      Marlin/src/config/examples/Mks/Sbase/Configuration_adv.h
  30. 10
    0
      Marlin/src/config/examples/RigidBot/Configuration_adv.h
  31. 10
    0
      Marlin/src/config/examples/SCARA/Configuration_adv.h
  32. 10
    0
      Marlin/src/config/examples/Sanguinololu/Configuration_adv.h
  33. 10
    0
      Marlin/src/config/examples/TheBorg/Configuration_adv.h
  34. 10
    0
      Marlin/src/config/examples/TinyBoy2/Configuration_adv.h
  35. 10
    0
      Marlin/src/config/examples/UltiMachine/Archim2/Configuration_adv.h
  36. 10
    0
      Marlin/src/config/examples/Velleman/K8200/Configuration_adv.h
  37. 10
    0
      Marlin/src/config/examples/Velleman/K8400/Configuration_adv.h
  38. 10
    0
      Marlin/src/config/examples/Wanhao/Duplicator 6/Configuration_adv.h
  39. 10
    0
      Marlin/src/config/examples/delta/FLSUN/auto_calibrate/Configuration_adv.h
  40. 10
    0
      Marlin/src/config/examples/delta/FLSUN/kossel/Configuration_adv.h
  41. 10
    0
      Marlin/src/config/examples/delta/FLSUN/kossel_mini/Configuration_adv.h
  42. 10
    0
      Marlin/src/config/examples/delta/generic/Configuration_adv.h
  43. 10
    0
      Marlin/src/config/examples/delta/kossel_mini/Configuration_adv.h
  44. 10
    0
      Marlin/src/config/examples/delta/kossel_pro/Configuration_adv.h
  45. 10
    0
      Marlin/src/config/examples/delta/kossel_xl/Configuration_adv.h
  46. 10
    0
      Marlin/src/config/examples/gCreate/gMax1.5+/Configuration_adv.h
  47. 10
    0
      Marlin/src/config/examples/makibox/Configuration_adv.h
  48. 10
    0
      Marlin/src/config/examples/tvrrug/Round2/Configuration_adv.h
  49. 10
    0
      Marlin/src/config/examples/wt150/Configuration_adv.h
  50. 235
    0
      Marlin/src/feature/power_loss_recovery.cpp
  51. 86
    0
      Marlin/src/feature/power_loss_recovery.h
  52. 10
    7
      Marlin/src/gcode/calibrate/G28.cpp
  53. 1
    2
      Marlin/src/gcode/calibrate/M100.cpp
  54. 33
    4
      Marlin/src/gcode/queue.cpp
  55. 1
    1
      Marlin/src/gcode/queue.h
  56. 10
    3
      Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp
  57. 1
    1
      Marlin/src/inc/Conditionals_post.h
  58. 5
    1
      Marlin/src/inc/SanityCheck.h
  59. 1
    1
      Marlin/src/lcd/malyanlcd.cpp
  60. 71
    0
      Marlin/src/lcd/ultralcd.cpp
  61. 10
    9
      Marlin/src/libs/stopwatch.cpp
  62. 16
    10
      Marlin/src/libs/stopwatch.h
  63. 55
    0
      Marlin/src/sd/cardreader.cpp
  64. 15
    1
      Marlin/src/sd/cardreader.h

+ 1
- 1
.travis.yml View File

@@ -67,7 +67,7 @@ script:
67 67
   - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS
68 68
   - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED AUTO_POWER_CONTROL NOZZLE_PARK_FEATURE FILAMENT_RUNOUT_SENSOR
69 69
   - opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE
70
-  - opt_enable_adv ARC_P_CIRCLES ADVANCED_PAUSE_FEATURE CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS
70
+  - opt_enable_adv ARC_P_CIRCLES ADVANCED_PAUSE_FEATURE CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS POWER_LOSS_RECOVERY
71 71
   - opt_enable_adv FWRETRACT MAX7219_DEBUG LED_CONTROL_MENU CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CODEPENDENT_XY_HOMING
72 72
   - opt_set GRID_MAX_POINTS_X 16
73 73
   - opt_set_adv FANMUX0_PIN 53

+ 10
- 0
Marlin/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 8
- 0
Marlin/src/Marlin.cpp View File

@@ -126,6 +126,10 @@
126 126
   #include "feature/pause.h"
127 127
 #endif
128 128
 
129
+#if ENABLED(POWER_LOSS_RECOVERY)
130
+  #include "feature/power_loss_recovery.h"
131
+#endif
132
+
129 133
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
130 134
   #include "feature/runout.h"
131 135
 #endif
@@ -876,6 +880,10 @@ void setup() {
876 880
     pe_magnet_init();
877 881
   #endif
878 882
 
883
+  #if ENABLED(POWER_LOSS_RECOVERY)
884
+    do_print_job_recovery();
885
+  #endif
886
+
879 887
   #if ENABLED(USE_WATCHDOG) // Reinit watchdog after HAL_get_reset_source call
880 888
     watchdog_init();
881 889
   #endif

+ 10
- 0
Marlin/src/config/default/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/AlephObjects/TAZ4/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Anet/A6/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Anet/A8/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Azteeg/X5GT/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/BIBO/TouchX/cyclops/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/BIBO/TouchX/default/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/BQ/Hephestos/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/BQ/Hephestos_2/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/BQ/WITBOX/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Cartesio/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Creality/CR-10/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Creality/CR-10S/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Creality/CR-10mini/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Creality/CR-8/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Creality/Ender-2/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Creality/Ender-4/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Felix/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/FolgerTech/i3-2020/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Infitary/i3-M508/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/JGAurora/A5/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/MakerParts/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Malyan/M150/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Malyan/M200/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Micromake/C1/enhanced/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Mks/Sbase/Configuration_adv.h View File

@@ -557,6 +557,16 @@
557 557
   //#define MENU_ADDAUTOSTART
558 558
 
559 559
   /**
560
+   * Continue after Power-Loss (Creality3D)
561
+   *
562
+   * Store the current state to the SD Card at the start of each layer
563
+   * during SD printing. If the recovery file is found at boot time, present
564
+   * an option on the LCD screen to continue the print from the last-known
565
+   * point in the file.
566
+   */
567
+  //#define POWER_LOSS_RECOVERY
568
+
569
+  /**
560 570
    * Sort SD file listings in alphabetical order.
561 571
    *
562 572
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/RigidBot/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/SCARA/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Sanguinololu/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/TheBorg/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/TinyBoy2/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/UltiMachine/Archim2/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Velleman/K8200/Configuration_adv.h View File

@@ -569,6 +569,16 @@
569 569
   //#define MENU_ADDAUTOSTART
570 570
 
571 571
   /**
572
+   * Continue after Power-Loss (Creality3D)
573
+   *
574
+   * Store the current state to the SD Card at the start of each layer
575
+   * during SD printing. If the recovery file is found at boot time, present
576
+   * an option on the LCD screen to continue the print from the last-known
577
+   * point in the file.
578
+   */
579
+  //#define POWER_LOSS_RECOVERY
580
+
581
+  /**
572 582
    * Sort SD file listings in alphabetical order.
573 583
    *
574 584
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Velleman/K8400/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/Wanhao/Duplicator 6/Configuration_adv.h View File

@@ -558,6 +558,16 @@
558 558
   //#define MENU_ADDAUTOSTART
559 559
 
560 560
   /**
561
+   * Continue after Power-Loss (Creality3D)
562
+   *
563
+   * Store the current state to the SD Card at the start of each layer
564
+   * during SD printing. If the recovery file is found at boot time, present
565
+   * an option on the LCD screen to continue the print from the last-known
566
+   * point in the file.
567
+   */
568
+  //#define POWER_LOSS_RECOVERY
569
+
570
+  /**
561 571
    * Sort SD file listings in alphabetical order.
562 572
    *
563 573
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/delta/FLSUN/auto_calibrate/Configuration_adv.h View File

@@ -558,6 +558,16 @@
558 558
   //#define MENU_ADDAUTOSTART
559 559
 
560 560
   /**
561
+   * Continue after Power-Loss (Creality3D)
562
+   *
563
+   * Store the current state to the SD Card at the start of each layer
564
+   * during SD printing. If the recovery file is found at boot time, present
565
+   * an option on the LCD screen to continue the print from the last-known
566
+   * point in the file.
567
+   */
568
+  //#define POWER_LOSS_RECOVERY
569
+
570
+  /**
561 571
    * Sort SD file listings in alphabetical order.
562 572
    *
563 573
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/delta/FLSUN/kossel/Configuration_adv.h View File

@@ -558,6 +558,16 @@
558 558
   //#define MENU_ADDAUTOSTART
559 559
 
560 560
   /**
561
+   * Continue after Power-Loss (Creality3D)
562
+   *
563
+   * Store the current state to the SD Card at the start of each layer
564
+   * during SD printing. If the recovery file is found at boot time, present
565
+   * an option on the LCD screen to continue the print from the last-known
566
+   * point in the file.
567
+   */
568
+  //#define POWER_LOSS_RECOVERY
569
+
570
+  /**
561 571
    * Sort SD file listings in alphabetical order.
562 572
    *
563 573
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/delta/FLSUN/kossel_mini/Configuration_adv.h View File

@@ -558,6 +558,16 @@
558 558
   //#define MENU_ADDAUTOSTART
559 559
 
560 560
   /**
561
+   * Continue after Power-Loss (Creality3D)
562
+   *
563
+   * Store the current state to the SD Card at the start of each layer
564
+   * during SD printing. If the recovery file is found at boot time, present
565
+   * an option on the LCD screen to continue the print from the last-known
566
+   * point in the file.
567
+   */
568
+  //#define POWER_LOSS_RECOVERY
569
+
570
+  /**
561 571
    * Sort SD file listings in alphabetical order.
562 572
    *
563 573
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/delta/generic/Configuration_adv.h View File

@@ -558,6 +558,16 @@
558 558
   //#define MENU_ADDAUTOSTART
559 559
 
560 560
   /**
561
+   * Continue after Power-Loss (Creality3D)
562
+   *
563
+   * Store the current state to the SD Card at the start of each layer
564
+   * during SD printing. If the recovery file is found at boot time, present
565
+   * an option on the LCD screen to continue the print from the last-known
566
+   * point in the file.
567
+   */
568
+  //#define POWER_LOSS_RECOVERY
569
+
570
+  /**
561 571
    * Sort SD file listings in alphabetical order.
562 572
    *
563 573
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/delta/kossel_mini/Configuration_adv.h View File

@@ -558,6 +558,16 @@
558 558
   //#define MENU_ADDAUTOSTART
559 559
 
560 560
   /**
561
+   * Continue after Power-Loss (Creality3D)
562
+   *
563
+   * Store the current state to the SD Card at the start of each layer
564
+   * during SD printing. If the recovery file is found at boot time, present
565
+   * an option on the LCD screen to continue the print from the last-known
566
+   * point in the file.
567
+   */
568
+  //#define POWER_LOSS_RECOVERY
569
+
570
+  /**
561 571
    * Sort SD file listings in alphabetical order.
562 572
    *
563 573
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/delta/kossel_pro/Configuration_adv.h View File

@@ -563,6 +563,16 @@
563 563
   //#define MENU_ADDAUTOSTART
564 564
 
565 565
   /**
566
+   * Continue after Power-Loss (Creality3D)
567
+   *
568
+   * Store the current state to the SD Card at the start of each layer
569
+   * during SD printing. If the recovery file is found at boot time, present
570
+   * an option on the LCD screen to continue the print from the last-known
571
+   * point in the file.
572
+   */
573
+  //#define POWER_LOSS_RECOVERY
574
+
575
+  /**
566 576
    * Sort SD file listings in alphabetical order.
567 577
    *
568 578
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/delta/kossel_xl/Configuration_adv.h View File

@@ -558,6 +558,16 @@
558 558
   //#define MENU_ADDAUTOSTART
559 559
 
560 560
   /**
561
+   * Continue after Power-Loss (Creality3D)
562
+   *
563
+   * Store the current state to the SD Card at the start of each layer
564
+   * during SD printing. If the recovery file is found at boot time, present
565
+   * an option on the LCD screen to continue the print from the last-known
566
+   * point in the file.
567
+   */
568
+  //#define POWER_LOSS_RECOVERY
569
+
570
+  /**
561 571
    * Sort SD file listings in alphabetical order.
562 572
    *
563 573
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/gCreate/gMax1.5+/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/makibox/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/tvrrug/Round2/Configuration_adv.h View File

@@ -556,6 +556,16 @@
556 556
   //#define MENU_ADDAUTOSTART
557 557
 
558 558
   /**
559
+   * Continue after Power-Loss (Creality3D)
560
+   *
561
+   * Store the current state to the SD Card at the start of each layer
562
+   * during SD printing. If the recovery file is found at boot time, present
563
+   * an option on the LCD screen to continue the print from the last-known
564
+   * point in the file.
565
+   */
566
+  //#define POWER_LOSS_RECOVERY
567
+
568
+  /**
559 569
    * Sort SD file listings in alphabetical order.
560 570
    *
561 571
    * With this option enabled, items on SD cards will be sorted

+ 10
- 0
Marlin/src/config/examples/wt150/Configuration_adv.h View File

@@ -557,6 +557,16 @@
557 557
   //#define MENU_ADDAUTOSTART
558 558
 
559 559
   /**
560
+   * Continue after Power-Loss (Creality3D)
561
+   *
562
+   * Store the current state to the SD Card at the start of each layer
563
+   * during SD printing. If the recovery file is found at boot time, present
564
+   * an option on the LCD screen to continue the print from the last-known
565
+   * point in the file.
566
+   */
567
+  //#define POWER_LOSS_RECOVERY
568
+
569
+  /**
560 570
    * Sort SD file listings in alphabetical order.
561 571
    *
562 572
    * With this option enabled, items on SD cards will be sorted

+ 235
- 0
Marlin/src/feature/power_loss_recovery.cpp View File

@@ -0,0 +1,235 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * power_loss_recovery.cpp - Resume an SD print after power-loss
25
+ */
26
+
27
+#include "../inc/MarlinConfigPre.h"
28
+
29
+#if ENABLED(POWER_LOSS_RECOVERY)
30
+
31
+#include "power_loss_recovery.h"
32
+
33
+#include "../lcd/ultralcd.h"
34
+#include "../gcode/queue.h"
35
+#include "../module/planner.h"
36
+#include "../module/printcounter.h"
37
+#include "../module/temperature.h"
38
+#include "../sd/cardreader.h"
39
+#include "../core/serial.h"
40
+
41
+// Recovery data
42
+job_recovery_info_t job_recovery_info;
43
+JobRecoveryPhase job_recovery_phase = JOB_RECOVERY_IDLE;
44
+uint8_t job_recovery_commands_count; //=0
45
+char job_recovery_commands[BUFSIZE + APPEND_CMD_COUNT][MAX_CMD_SIZE];
46
+
47
+// Private
48
+static char sd_filename[MAXPATHNAMELENGTH];
49
+
50
+#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
51
+  void debug_print_job_recovery(const bool recovery) {
52
+    SERIAL_PROTOCOLPAIR("valid_head:", (int)job_recovery_info.valid_head);
53
+    SERIAL_PROTOCOLLNPAIR(" valid_foot:", (int)job_recovery_info.valid_foot);
54
+    if (job_recovery_info.valid_head) {
55
+      if (job_recovery_info.valid_head == job_recovery_info.valid_foot) {
56
+        SERIAL_PROTOCOLPGM("current_position");
57
+        LOOP_XYZE(i) SERIAL_PROTOCOLPAIR(": ", job_recovery_info.current_position[i]);
58
+        SERIAL_EOL();
59
+        SERIAL_PROTOCOLLNPAIR("feedrate: ", job_recovery_info.feedrate);
60
+        SERIAL_PROTOCOLPGM("target_temperature");
61
+        HOTEND_LOOP() SERIAL_PROTOCOLPAIR(": ", job_recovery_info.target_temperature[e]);
62
+        SERIAL_EOL();
63
+        SERIAL_PROTOCOLPGM("fanSpeeds");
64
+        for(uint8_t i = 0; i < FAN_COUNT; i++) SERIAL_PROTOCOLPAIR(": ", job_recovery_info.fanSpeeds[i]);
65
+        SERIAL_EOL();
66
+        #if HAS_LEVELING
67
+          SERIAL_PROTOCOLPAIR("leveling: ", int(job_recovery_info.leveling));
68
+          SERIAL_PROTOCOLLNPAIR(" fade: ", int(job_recovery_info.fade));
69
+        #endif
70
+        SERIAL_PROTOCOLLNPAIR("target_temperature_bed: ", job_recovery_info.target_temperature_bed);
71
+        SERIAL_PROTOCOLLNPAIR("cmd_queue_index_r: ", job_recovery_info.cmd_queue_index_r);
72
+        SERIAL_PROTOCOLLNPAIR("commands_in_queue: ", job_recovery_info.commands_in_queue);
73
+        if (recovery)
74
+          for (uint8_t i = 0; i < job_recovery_commands_count; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_commands[i]);
75
+        else
76
+          for (uint8_t i = 0; i < job_recovery_info.commands_in_queue; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_info.command_queue[i]);
77
+        SERIAL_PROTOCOLLNPAIR("sd_filename: ", sd_filename);
78
+        SERIAL_PROTOCOLLNPAIR("sdpos: ", job_recovery_info.sdpos);
79
+        SERIAL_PROTOCOLLNPAIR("print_job_elapsed: ", job_recovery_info.print_job_elapsed);
80
+      }
81
+      else
82
+        SERIAL_PROTOCOLLNPGM("INVALID DATA");
83
+    }
84
+  }
85
+#endif // DEBUG_POWER_LOSS_RECOVERY
86
+
87
+/**
88
+ * Check for Print Job Recovery
89
+ * If the file has a saved state, populate the job_recovery_commands queue
90
+ */
91
+void do_print_job_recovery() {
92
+  //if (job_recovery_commands_count > 0) return;
93
+  memset(&job_recovery_info, 0, sizeof(job_recovery_info));
94
+  ZERO(job_recovery_commands);
95
+
96
+  if (!card.cardOK) card.initsd();
97
+
98
+  if (card.cardOK) {
99
+
100
+    #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
101
+      SERIAL_PROTOCOLLNPAIR("Init job recovery info. Size: ", (int)sizeof(job_recovery_info));
102
+    #endif
103
+
104
+    if (card.jobRecoverFileExists()) {
105
+      card.openJobRecoveryFile(true);
106
+      card.loadJobRecoveryInfo();
107
+      card.closeJobRecoveryFile();
108
+      //card.removeJobRecoveryFile();
109
+
110
+      if (job_recovery_info.valid_head && job_recovery_info.valid_head == job_recovery_info.valid_foot) {
111
+
112
+        uint8_t ind = 0;
113
+
114
+        #if HAS_LEVELING
115
+          strcpy_P(job_recovery_commands[ind++], PSTR("M420 S0 Z0"));               // Leveling off before G92 or G28
116
+        #endif
117
+
118
+        strcpy_P(job_recovery_commands[ind++], PSTR("G92.0 Z0"));                   // Ensure Z is equal to 0
119
+        strcpy_P(job_recovery_commands[ind++], PSTR("G1 Z2"));                      // Raise Z by 2mm (we hope!)
120
+        strcpy_P(job_recovery_commands[ind++], PSTR("G28 R0"
121
+          #if !IS_KINEMATIC
122
+            " X Y"                                                                  // Home X and Y for Cartesian
123
+          #endif
124
+        ));
125
+
126
+        #if HAS_LEVELING
127
+          // Restore leveling state before G92 sets Z
128
+          // This ensures the steppers correspond to the native Z
129
+          sprintf_P(job_recovery_commands[ind++], PSTR("M420 S%i Z%s"), int(job_recovery_info.leveling), job_recovery_info.fade);
130
+        #endif
131
+
132
+        char str_1[16], str_2[16];
133
+        dtostrf(job_recovery_info.current_position[Z_AXIS] + 2, 1, 3, str_1);
134
+        dtostrf(job_recovery_info.current_position[E_AXIS]
135
+          #if ENABLED(SAVE_EACH_CMD_MODE)
136
+            - 5
137
+          #endif
138
+          , 1, 3, str_2
139
+        );
140
+        sprintf_P(job_recovery_commands[ind++], PSTR("G92.0 Z%s E%s"), str_1, str_2); // Current Z + 2 and E
141
+
142
+        strcpy_P(job_recovery_commands[ind++], PSTR("M117 Continuing..."));
143
+
144
+        uint8_t r = job_recovery_info.cmd_queue_index_r;
145
+        while (job_recovery_info.commands_in_queue) {
146
+          strcpy(job_recovery_commands[ind++], job_recovery_info.command_queue[r]);
147
+          job_recovery_info.commands_in_queue--;
148
+          r = (r + 1) % BUFSIZE;
149
+        }
150
+
151
+        job_recovery_commands_count = ind;
152
+
153
+        #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
154
+          debug_print_job_recovery(true);
155
+        #endif
156
+
157
+        card.openFile(sd_filename, true);
158
+        card.setIndex(job_recovery_info.sdpos);
159
+      }
160
+      else {
161
+        if (job_recovery_info.valid_head != job_recovery_info.valid_foot)
162
+          LCD_ALERTMESSAGEPGM("INVALID DATA");
163
+        memset(&job_recovery_info, 0, sizeof(job_recovery_info));
164
+      }
165
+    }
166
+  }
167
+}
168
+
169
+/**
170
+ * Save the current machine state to the "bin" file
171
+ */
172
+void save_job_recovery_info() {
173
+  #if SAVE_INFO_INTERVAL_MS > 0
174
+    static millis_t next_save_ms; // = 0;  // Init on reset
175
+    millis_t ms = millis();
176
+  #endif
177
+  if (
178
+    #if SAVE_INFO_INTERVAL_MS > 0
179
+      ELAPSED(ms, next_save_ms) ||
180
+    #endif
181
+    #if ENABLED(SAVE_EACH_CMD_MODE)
182
+      true
183
+    #else
184
+      (current_position[Z_AXIS] > 0 && current_position[Z_AXIS] > job_recovery_info.current_position[Z_AXIS])
185
+    #endif
186
+  ) {
187
+    #if SAVE_INFO_INTERVAL_MS > 0
188
+      next_save_ms = ms + SAVE_INFO_INTERVAL_MS;
189
+    #endif
190
+
191
+    // Head and foot will match if valid data was saved
192
+    if (!++job_recovery_info.valid_head) ++job_recovery_info.valid_head; // non-zero in sequence
193
+    job_recovery_info.valid_foot = job_recovery_info.valid_head;
194
+
195
+    // Machine state
196
+    COPY(job_recovery_info.current_position, current_position);
197
+    job_recovery_info.feedrate = feedrate_mm_s;
198
+    COPY(job_recovery_info.target_temperature, thermalManager.target_temperature);
199
+    job_recovery_info.target_temperature_bed = thermalManager.target_temperature_bed;
200
+    COPY(job_recovery_info.fanSpeeds, fanSpeeds);
201
+
202
+    #if HAS_LEVELING
203
+      job_recovery_info.leveling = planner.leveling_active;
204
+      job_recovery_info.fade = (
205
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
206
+          planner.z_fade_height
207
+        #else
208
+          0
209
+        #endif
210
+      );
211
+    #endif
212
+
213
+    // Commands in the queue
214
+    job_recovery_info.cmd_queue_index_r = cmd_queue_index_r;
215
+    job_recovery_info.commands_in_queue = commands_in_queue;
216
+    COPY(job_recovery_info.command_queue, command_queue);
217
+
218
+    // Elapsed print job time
219
+    job_recovery_info.print_job_elapsed = print_job_timer.duration() * 1000UL;
220
+
221
+    // SD file position
222
+    card.getAbsFilename(sd_filename);
223
+    job_recovery_info.sdpos = card.getIndex();
224
+
225
+    #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
226
+      SERIAL_PROTOCOLLNPGM("Saving job_recovery_info");
227
+      debug_print_job_recovery(false);
228
+    #endif
229
+
230
+    card.openJobRecoveryFile(false);
231
+    (void)card.saveJobRecoveryInfo();
232
+  }
233
+}
234
+
235
+#endif // POWER_LOSS_RECOVERY

+ 86
- 0
Marlin/src/feature/power_loss_recovery.h View File

@@ -0,0 +1,86 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * power_loss_recovery.h - Resume an SD print after power-loss
25
+ */
26
+
27
+#ifndef _POWER_LOSS_RECOVERY_H_
28
+#define _POWER_LOSS_RECOVERY_H_
29
+
30
+#include "../sd/cardreader.h"
31
+#include "../core/types.h"
32
+#include "../inc/MarlinConfigPre.h"
33
+
34
+#define SAVE_INFO_INTERVAL_MS 0
35
+//#define SAVE_EACH_CMD_MODE
36
+//#define DEBUG_POWER_LOSS_RECOVERY
37
+
38
+typedef struct {
39
+  uint8_t valid_head;
40
+
41
+  // Machine state
42
+  float current_position[NUM_AXIS], feedrate;
43
+  int16_t target_temperature[HOTENDS],
44
+          target_temperature_bed,
45
+          fanSpeeds[FAN_COUNT];
46
+
47
+  #if HAS_LEVELING
48
+    bool leveling;
49
+    float fade;
50
+  #endif
51
+
52
+  // Command queue
53
+  uint8_t cmd_queue_index_r, commands_in_queue;
54
+  char command_queue[BUFSIZE][MAX_CMD_SIZE];
55
+
56
+  // SD File position
57
+  uint32_t sdpos;
58
+
59
+  // Job elapsed time
60
+  millis_t print_job_elapsed;
61
+
62
+  uint8_t valid_foot;
63
+} job_recovery_info_t;
64
+
65
+extern job_recovery_info_t job_recovery_info;
66
+
67
+enum JobRecoveryPhase : unsigned char {
68
+  JOB_RECOVERY_IDLE,
69
+  JOB_RECOVERY_MAYBE,
70
+  JOB_RECOVERY_YES
71
+};
72
+extern JobRecoveryPhase job_recovery_phase;
73
+
74
+#if HAS_LEVELING
75
+  #define APPEND_CMD_COUNT 7
76
+#else
77
+  #define APPEND_CMD_COUNT 5
78
+#endif
79
+
80
+extern char job_recovery_commands[BUFSIZE + APPEND_CMD_COUNT][MAX_CMD_SIZE];
81
+extern uint8_t job_recovery_commands_count;
82
+
83
+void do_print_job_recovery();
84
+void save_job_recovery_info();
85
+
86
+#endif // _POWER_LOSS_RECOVERY_H_

+ 10
- 7
Marlin/src/gcode/calibrate/G28.cpp View File

@@ -152,7 +152,9 @@
152 152
  *  None  Home to all axes with no parameters.
153 153
  *        With QUICK_HOME enabled XY will home together, then Z.
154 154
  *
155
- * Cartesian parameters
155
+ *  Rn  Raise by n mm/inches before homing
156
+ *
157
+ * Cartesian/SCARA parameters
156 158
  *
157 159
  *  X   Home to the X endstop
158 160
  *  Y   Home to the Y endstop
@@ -226,12 +228,13 @@ void GcodeSuite::G28(const bool always_home_all) {
226 228
 
227 229
     #endif
228 230
 
229
-    #if ENABLED(UNKNOWN_Z_NO_RAISE)
230
-      const float z_homing_height = axis_known_position[Z_AXIS] ? Z_HOMING_HEIGHT : 0;
231
-    #else
232
-      constexpr float z_homing_height = Z_HOMING_HEIGHT;
233
-    #endif
234
-
231
+    const float z_homing_height = (
232
+      #if ENABLED(UNKNOWN_Z_NO_RAISE)
233
+        !axis_known_position[Z_AXIS] ? 0 :
234
+      #endif
235
+          (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
236
+    );
237
+ 
235 238
     if (z_homing_height && (home_all || homeX || homeY)) {
236 239
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
237 240
       destination[Z_AXIS] = z_homing_height;

+ 1
- 2
Marlin/src/gcode/calibrate/M100.cpp View File

@@ -25,6 +25,7 @@
25 25
 #if ENABLED(M100_FREE_MEMORY_WATCHER)
26 26
 
27 27
 #include "../gcode.h"
28
+#include "../queue.h"
28 29
 #include "../../libs/hex_print_routines.h"
29 30
 
30 31
 #include "../../Marlin.h" // for idle()
@@ -59,8 +60,6 @@
59 60
 
60 61
 #define TEST_BYTE ((char) 0xE5)
61 62
 
62
-extern char command_queue[BUFSIZE][MAX_CMD_SIZE];
63
-
64 63
 extern char* __brkval;
65 64
 extern size_t  __heap_start, __heap_end, __flp;
66 65
 extern char __bss_end;

+ 33
- 4
Marlin/src/gcode/queue.cpp View File

@@ -37,6 +37,10 @@
37 37
   #include "../feature/leds/leds.h"
38 38
 #endif
39 39
 
40
+#if ENABLED(POWER_LOSS_RECOVERY)
41
+  #include "../feature/power_loss_recovery.h"
42
+#endif
43
+
40 44
 /**
41 45
  * GCode line number handling. Hosts may opt to include line numbers when
42 46
  * sending commands to Marlin, and lines will be checked for sequentiality.
@@ -115,7 +119,7 @@ inline void _commit_command(bool say_ok
115 119
  * Return true if the command was successfully added.
116 120
  * Return false for a full buffer, or if the 'command' is a comment.
117 121
  */
118
-inline bool _enqueuecommand(const char* cmd, bool say_ok
122
+inline bool _enqueuecommand(const char* cmd, bool say_ok=false
119 123
   #if NUM_SERIAL > 1
120 124
     , int16_t port = -1
121 125
   #endif
@@ -133,8 +137,8 @@ inline bool _enqueuecommand(const char* cmd, bool say_ok
133 137
 /**
134 138
  * Enqueue with Serial Echo
135 139
  */
136
-bool enqueue_and_echo_command(const char* cmd, bool say_ok/*=false*/) {
137
-  if (_enqueuecommand(cmd, say_ok)) {
140
+bool enqueue_and_echo_command(const char* cmd) {
141
+  if (_enqueuecommand(cmd)) {
138 142
     SERIAL_ECHO_START();
139 143
     SERIAL_ECHOPAIR(MSG_ENQUEUEING, cmd);
140 144
     SERIAL_CHAR('"');
@@ -486,6 +490,22 @@ inline void get_serial_commands() {
486 490
     }
487 491
   }
488 492
 
493
+  #if ENABLED(POWER_LOSS_RECOVERY)
494
+
495
+    inline bool drain_job_recovery_commands() {
496
+      static uint8_t job_recovery_commands_index = 0; // Resets on reboot
497
+      if (job_recovery_commands_count) {
498
+        if (_enqueuecommand(job_recovery_commands[job_recovery_commands_index])) {
499
+          ++job_recovery_commands_index;
500
+          if (!--job_recovery_commands_count) job_recovery_phase = JOB_RECOVERY_IDLE;
501
+        }
502
+        return true;
503
+      }
504
+      return false;
505
+    }
506
+
507
+  #endif
508
+
489 509
 #endif // SDSUPPORT
490 510
 
491 511
 /**
@@ -501,6 +521,11 @@ void get_available_commands() {
501 521
 
502 522
   get_serial_commands();
503 523
 
524
+  #if ENABLED(POWER_LOSS_RECOVERY)
525
+    // Commands for power-loss recovery take precedence
526
+    if (job_recovery_phase == JOB_RECOVERY_YES && drain_job_recovery_commands()) return;
527
+  #endif
528
+
504 529
   #if ENABLED(SDSUPPORT)
505 530
     get_sdcard_commands();
506 531
   #endif
@@ -543,8 +568,12 @@ void advance_command_queue() {
543 568
           ok_to_send();
544 569
       }
545 570
     }
546
-    else
571
+    else {
547 572
       gcode.process_next_command();
573
+      #if ENABLED(POWER_LOSS_RECOVERY)
574
+        if (card.cardOK && card.sdprinting) save_job_recovery_info();
575
+      #endif
576
+    }
548 577
 
549 578
   #else
550 579
 

+ 1
- 1
Marlin/src/gcode/queue.h View File

@@ -95,7 +95,7 @@ void enqueue_and_echo_commands_P(const char * const pgcode);
95 95
 /**
96 96
  * Enqueue with Serial Echo
97 97
  */
98
-bool enqueue_and_echo_command(const char* cmd, bool say_ok=false);
98
+bool enqueue_and_echo_command(const char* cmd);
99 99
 
100 100
 #define HAS_LCD_QUEUE_NOW (ENABLED(MALYAN_LCD) || (ENABLED(ULTIPANEL) && (ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(PID_AUTOTUNE_MENU) || ENABLED(ADVANCED_PAUSE_FEATURE))))
101 101
 #define HAS_QUEUE_NOW (ENABLED(SDSUPPORT) || HAS_LCD_QUEUE_NOW)

+ 10
- 3
Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp View File

@@ -29,13 +29,16 @@
29 29
 #include "../../module/printcounter.h"
30 30
 #include "../../module/stepper.h"
31 31
 
32
+#if ENABLED(POWER_LOSS_RECOVERY)
33
+  #include "../../feature/power_loss_recovery.h"
34
+#endif
35
+
32 36
 #if ENABLED(PARK_HEAD_ON_PAUSE)
33 37
   #include "../../feature/pause.h"
34
-  #include "../queue.h"
35 38
 #endif
36 39
 
37
-#if NUM_SERIAL > 1
38
-  #include "../../gcode/queue.h"
40
+#if ENABLED(PARK_HEAD_ON_PAUSE) || NUM_SERIAL > 1
41
+  #include "../queue.h"
39 42
 #endif
40 43
 
41 44
 /**
@@ -78,6 +81,10 @@ void GcodeSuite::M23() {
78 81
  * M24: Start or Resume SD Print
79 82
  */
80 83
 void GcodeSuite::M24() {
84
+  #if ENABLED(POWER_LOSS_RECOVERY)
85
+    card.removeJobRecoveryFile();
86
+  #endif
87
+
81 88
   #if ENABLED(PARK_HEAD_ON_PAUSE)
82 89
     resume_print();
83 90
   #endif

+ 1
- 1
Marlin/src/inc/Conditionals_post.h View File

@@ -1334,7 +1334,7 @@
1334 1334
 #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
1335 1335
 
1336 1336
 // Add commands that need sub-codes to this list
1337
-#define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET) || ENABLED(CNC_COORDINATE_SYSTEMS)
1337
+#define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET) || ENABLED(CNC_COORDINATE_SYSTEMS) || ENABLED(POWER_LOSS_RECOVERY)
1338 1338
 
1339 1339
 // Parking Extruder
1340 1340
 #if ENABLED(PARKING_EXTRUDER)

+ 5
- 1
Marlin/src/inc/SanityCheck.h View File

@@ -462,7 +462,7 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
462 462
   #elif ENABLED(BABYSTEP_ZPROBE_OFFSET) && !HAS_BED_PROBE
463 463
     #error "BABYSTEP_ZPROBE_OFFSET requires a probe."
464 464
   #elif ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) && !ENABLED(DOGLCD)
465
-    #error "BABYSTEP_ZPROBE_GFX_OVERLAY requires a DOGLCD."
465
+    #error "BABYSTEP_ZPROBE_GFX_OVERLAY requires a Graphical LCD."
466 466
   #elif ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) && !ENABLED(BABYSTEP_ZPROBE_OFFSET)
467 467
     #error "BABYSTEP_ZPROBE_GFX_OVERLAY requires a BABYSTEP_ZPROBE_OFFSET."
468 468
   #endif
@@ -1708,4 +1708,8 @@ static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too m
1708 1708
   #endif
1709 1709
 #endif
1710 1710
 
1711
+#if ENABLED(POWER_LOSS_RECOVERY) && !ENABLED(ULTIPANEL)
1712
+  #error "POWER_LOSS_RECOVERY currently requires an LCD Controller."
1713
+#endif
1714
+
1711 1715
 #endif // _SANITYCHECK_H_

+ 1
- 1
Marlin/src/lcd/malyanlcd.cpp View File

@@ -302,7 +302,7 @@ void process_lcd_s_command(const char* command) {
302 302
 
303 303
     case 'H':
304 304
       // Home all axis
305
-      enqueue_and_echo_command("G28", false);
305
+      enqueue_and_echo_commands_P(PSTR("G28"));
306 306
       break;
307 307
 
308 308
     case 'L': {

+ 71
- 0
Marlin/src/lcd/ultralcd.cpp View File

@@ -43,6 +43,10 @@
43 43
   #include "../feature/pause.h"
44 44
 #endif
45 45
 
46
+#if ENABLED(POWER_LOSS_RECOVERY)
47
+  #include "../feature/power_loss_recovery.h"
48
+#endif
49
+
46 50
 #if ENABLED(PRINTCOUNTER) && ENABLED(LCD_INFO_MENU)
47 51
   #include "../libs/duration_t.h"
48 52
 #endif
@@ -862,10 +866,70 @@ void kill_screen(const char* lcd_msg) {
862 866
       abort_sd_printing = true;
863 867
       lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
864 868
       lcd_return_to_status();
869
+
870
+      #if ENABLED(POWER_LOSS_RECOVERY)
871
+        card.openJobRecoveryFile(false);
872
+        job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
873
+        (void)card.saveJobRecoveryInfo();
874
+        card.closeJobRecoveryFile();
875
+        job_recovery_commands_count = 0;
876
+      #endif
865 877
     }
866 878
 
867 879
   #endif // SDSUPPORT
868 880
 
881
+  #if ENABLED(POWER_LOSS_RECOVERY)
882
+
883
+    static void lcd_sdcard_recover_job() {
884
+      char cmd[20];
885
+
886
+      // Return to status now
887
+      lcd_return_to_status();
888
+
889
+      // Turn leveling off and home
890
+      enqueue_and_echo_commands_P(PSTR("M420 S0\nG28"
891
+        #if !IS_KINEMATIC
892
+          " X Y"
893
+        #endif
894
+      ));
895
+
896
+      // Restore the bed temperature
897
+      sprintf_P(cmd, PSTR("M190 S%i"), job_recovery_info.target_temperature_bed);
898
+      enqueue_and_echo_command(cmd);
899
+
900
+      // Restore all hotend temperatures
901
+      HOTEND_LOOP() {
902
+        sprintf_P(cmd, PSTR("M109 S%i"), job_recovery_info.target_temperature[e]);
903
+        enqueue_and_echo_command(cmd);
904
+      }
905
+
906
+      // Restore print cooling fan speeds
907
+      for (uint8_t i = 0; i < FAN_COUNT; i++) {
908
+        sprintf_P(cmd, PSTR("M106 P%i S%i"), i, job_recovery_info.fanSpeeds[i]);
909
+        enqueue_and_echo_command(cmd);
910
+      }
911
+
912
+      // Start draining the job recovery command queue
913
+      job_recovery_phase = JOB_RECOVERY_YES;
914
+
915
+      // Resume the print job timer
916
+      if (job_recovery_info.print_job_elapsed)
917
+        print_job_timer.resume(job_recovery_info.print_job_elapsed);
918
+
919
+      // Start getting commands from SD
920
+      card.startFileprint();
921
+    }
922
+
923
+    static void lcd_job_recovery_menu() {
924
+      defer_return_to_status = true;
925
+      START_MENU();
926
+      MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_recover_job);
927
+      MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
928
+      END_MENU();
929
+    }
930
+
931
+  #endif // POWER_LOSS_RECOVERY
932
+
869 933
   #if ENABLED(MENU_ITEM_CASE_LIGHT)
870 934
 
871 935
     #include "../feature/caselight.h"
@@ -5067,6 +5131,13 @@ void lcd_update() {
5067 5131
 
5068 5132
   #endif // SDSUPPORT && SD_DETECT_PIN
5069 5133
 
5134
+  #if ENABLED(POWER_LOSS_RECOVERY)
5135
+    if (job_recovery_commands_count && job_recovery_phase == JOB_RECOVERY_IDLE) {
5136
+      lcd_goto_screen(lcd_job_recovery_menu);
5137
+      job_recovery_phase = JOB_RECOVERY_MAYBE; // Waiting for a response
5138
+    }
5139
+  #endif
5140
+
5070 5141
   const millis_t ms = millis();
5071 5142
   if (ELAPSED(ms, next_lcd_update_ms)
5072 5143
     #if ENABLED(DOGLCD)

+ 10
- 9
Marlin/src/libs/stopwatch.cpp View File

@@ -71,6 +71,15 @@ bool Stopwatch::start() {
71 71
   else return false;
72 72
 }
73 73
 
74
+void Stopwatch::resume(const millis_t duration) {
75
+  #if ENABLED(DEBUG_STOPWATCH)
76
+    Stopwatch::debug(PSTR("resume"));
77
+  #endif
78
+
79
+  reset();
80
+  if ((accumulator = duration)) state = RUNNING;
81
+}
82
+
74 83
 void Stopwatch::reset() {
75 84
   #if ENABLED(DEBUG_STOPWATCH)
76 85
     Stopwatch::debug(PSTR("reset"));
@@ -82,16 +91,8 @@ void Stopwatch::reset() {
82 91
   accumulator = 0;
83 92
 }
84 93
 
85
-bool Stopwatch::isRunning() {
86
-  return (state == RUNNING) ? true : false;
87
-}
88
-
89
-bool Stopwatch::isPaused() {
90
-  return (state == PAUSED) ? true : false;
91
-}
92
-
93 94
 millis_t Stopwatch::duration() {
94
-  return (((isRunning()) ? millis() : stopTimestamp)
95
+  return ((isRunning() ? millis() : stopTimestamp)
95 96
           - startTimestamp) / 1000UL + accumulator;
96 97
 }
97 98
 

+ 16
- 10
Marlin/src/libs/stopwatch.h View File

@@ -54,30 +54,36 @@ class Stopwatch {
54 54
     FORCE_INLINE static void init() { reset(); }
55 55
 
56 56
     /**
57
-     * @brief Stops the stopwatch
58
-     * @details Stops the running timer, it will silently ignore the request if
59
-     * no timer is currently running.
60
-     * @return true is method was successful
57
+     * @brief Stop the stopwatch
58
+     * @details Stop the running timer, it will silently ignore the request if
59
+     *          no timer is currently running.
60
+     * @return true on success
61 61
      */
62 62
     static bool stop();
63 63
 
64 64
     /**
65 65
      * @brief Pause the stopwatch
66 66
      * @details Pause the running timer, it will silently ignore the request if
67
-     * no timer is currently running.
68
-     * @return true is method was successful
67
+     *          no timer is currently running.
68
+     * @return true on success
69 69
      */
70 70
     static bool pause();
71 71
 
72 72
     /**
73 73
      * @brief Start the stopwatch
74 74
      * @details Start the timer, it will silently ignore the request if the
75
-     * timer is already running.
76
-     * @return true is method was successful
75
+     *          timer is already running.
76
+     * @return true on success
77 77
      */
78 78
     static bool start();
79 79
 
80 80
     /**
81
+     * @brief Resume the stopwatch
82
+     * @details Resume a timer from a given duration
83
+     */
84
+    static void resume(const millis_t duration);
85
+
86
+    /**
81 87
      * @brief Reset the stopwatch
82 88
      * @details Reset all settings to their default values.
83 89
      */
@@ -88,14 +94,14 @@ class Stopwatch {
88 94
      * @details Return true if the timer is currently running, false otherwise.
89 95
      * @return true if stopwatch is running
90 96
      */
91
-    static bool isRunning();
97
+    FORCE_INLINE static bool isRunning() { return state == RUNNING; }
92 98
 
93 99
     /**
94 100
      * @brief Check if the timer is paused
95 101
      * @details Return true if the timer is currently paused, false otherwise.
96 102
      * @return true if stopwatch is paused
97 103
      */
98
-    static bool isPaused();
104
+    FORCE_INLINE static bool isPaused() { return state == PAUSED; }
99 105
 
100 106
     /**
101 107
      * @brief Get the running time

+ 55
- 0
Marlin/src/sd/cardreader.cpp View File

@@ -33,6 +33,10 @@
33 33
 #include "../core/language.h"
34 34
 #include "../gcode/queue.h"
35 35
 
36
+#if ENABLED(POWER_LOSS_RECOVERY)
37
+  #include "../feature/power_loss_recovery.h"
38
+#endif
39
+
36 40
 #if ENABLED(ADVANCED_PAUSE_FEATURE)
37 41
   #include "../feature/pause.h"
38 42
 #endif
@@ -968,6 +972,15 @@ void CardReader::printingHasFinished() {
968 972
   }
969 973
   else {
970 974
     sdprinting = false;
975
+
976
+    #if ENABLED(POWER_LOSS_RECOVERY)
977
+      openJobRecoveryFile(false);
978
+      job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
979
+      (void)saveJobRecoveryInfo();
980
+      closeJobRecoveryFile();
981
+      job_recovery_commands_count = 0;
982
+    #endif
983
+
971 984
     #if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
972 985
       stepper.cleaning_buffer_counter = 1; // The command will fire from the Stepper ISR
973 986
     #endif
@@ -1006,4 +1019,46 @@ void CardReader::printingHasFinished() {
1006 1019
   }
1007 1020
 #endif // AUTO_REPORT_SD_STATUS
1008 1021
 
1022
+#if ENABLED(POWER_LOSS_RECOVERY)
1023
+
1024
+  char job_recovery_file_name[4] = "bin";
1025
+
1026
+  void CardReader::openJobRecoveryFile(const bool read) {
1027
+    if (!cardOK) return;
1028
+    if (jobRecoveryFile.isOpen()) return;
1029
+    if (!jobRecoveryFile.open(&root, job_recovery_file_name, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) {
1030
+      SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, job_recovery_file_name);
1031
+      SERIAL_PROTOCOLCHAR('.');
1032
+      SERIAL_EOL();
1033
+    }
1034
+    else
1035
+      SERIAL_PROTOCOLLNPAIR(MSG_SD_WRITE_TO_FILE, job_recovery_file_name);
1036
+  }
1037
+
1038
+  void CardReader::closeJobRecoveryFile() { jobRecoveryFile.close(); }
1039
+
1040
+  bool CardReader::jobRecoverFileExists() {
1041
+    return jobRecoveryFile.open(&root, job_recovery_file_name, O_READ);
1042
+  }
1043
+
1044
+  int16_t CardReader::saveJobRecoveryInfo() {
1045
+    jobRecoveryFile.seekSet(0);
1046
+    const int16_t ret = jobRecoveryFile.write(&job_recovery_info, sizeof(job_recovery_info));
1047
+    if (ret == -1) SERIAL_PROTOCOLLNPGM("Power-loss file write failed.");
1048
+    return ret;
1049
+  }
1050
+
1051
+  int16_t CardReader::loadJobRecoveryInfo() {
1052
+    return jobRecoveryFile.read(&job_recovery_info, sizeof(job_recovery_info));
1053
+  }
1054
+
1055
+  void CardReader::removeJobRecoveryFile() {
1056
+    if (jobRecoveryFile.remove(&root, job_recovery_file_name))
1057
+      SERIAL_PROTOCOLLNPGM("Power-loss file deleted.");
1058
+    else
1059
+      SERIAL_PROTOCOLLNPGM("Power-loss file delete failed.");
1060
+  }
1061
+
1062
+#endif // POWER_LOSS_RECOVERY
1063
+
1009 1064
 #endif // SDSUPPORT

+ 15
- 1
Marlin/src/sd/cardreader.h View File

@@ -103,11 +103,21 @@ public:
103 103
     #endif
104 104
   #endif
105 105
 
106
+  #if ENABLED(POWER_LOSS_RECOVERY)
107
+    void openJobRecoveryFile(const bool read);
108
+    void closeJobRecoveryFile();
109
+    bool jobRecoverFileExists();
110
+    int16_t saveJobRecoveryInfo();
111
+    int16_t loadJobRecoveryInfo();
112
+    void removeJobRecoveryFile();
113
+  #endif
114
+
106 115
   FORCE_INLINE void pauseSDPrint() { sdprinting = false; }
107 116
   FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
108 117
   FORCE_INLINE bool eof() { return sdpos >= filesize; }
109 118
   FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
110
-  FORCE_INLINE void setIndex(long index) { sdpos = index; file.seekSet(index); }
119
+  FORCE_INLINE void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }
120
+  FORCE_INLINE uint32_t getIndex() { return sdpos; }
111 121
   FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; }
112 122
   FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; }
113 123
 
@@ -191,6 +201,10 @@ private:
191 201
   SdVolume volume;
192 202
   SdFile file;
193 203
 
204
+  #if ENABLED(POWER_LOSS_RECOVERY)
205
+    SdFile jobRecoveryFile;
206
+  #endif
207
+
194 208
   #define SD_PROCEDURE_DEPTH 1
195 209
   #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
196 210
   uint8_t file_subcall_ctr;

Loading…
Cancel
Save