My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

power_loss_recovery.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 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. #pragma once
  23. /**
  24. * power_loss_recovery.h - Resume an SD print after power-loss
  25. */
  26. #include "../sd/cardreader.h"
  27. #include "../inc/MarlinConfigPre.h"
  28. #if ENABLED(MIXING_EXTRUDER)
  29. #include "../feature/mixing.h"
  30. #endif
  31. #define SAVE_INFO_INTERVAL_MS 0
  32. //#define SAVE_EACH_CMD_MODE
  33. //#define DEBUG_POWER_LOSS_RECOVERY
  34. typedef struct {
  35. uint8_t valid_head;
  36. // Machine state
  37. float current_position[NUM_AXIS];
  38. uint16_t feedrate;
  39. #if HOTENDS > 1
  40. uint8_t active_hotend;
  41. #endif
  42. int16_t target_temperature[HOTENDS];
  43. #if HAS_HEATED_BED
  44. int16_t target_temperature_bed;
  45. #endif
  46. #if FAN_COUNT
  47. uint8_t fan_speed[FAN_COUNT];
  48. #endif
  49. #if HAS_LEVELING
  50. bool leveling;
  51. float fade;
  52. #endif
  53. #if ENABLED(FWRETRACT)
  54. float retract[EXTRUDERS], retract_hop;
  55. #endif
  56. // Mixing extruder and gradient
  57. #if ENABLED(MIXING_EXTRUDER)
  58. //uint_fast8_t selected_vtool;
  59. //mixer_comp_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
  60. #if ENABLED(GRADIENT_MIX)
  61. gradient_t gradient;
  62. #endif
  63. #endif
  64. // Relative mode
  65. bool relative_mode, relative_modes_e;
  66. // Command queue
  67. uint8_t commands_in_queue, cmd_queue_index_r;
  68. char command_queue[BUFSIZE][MAX_CMD_SIZE];
  69. // SD Filename and position
  70. char sd_filename[MAXPATHNAMELENGTH];
  71. uint32_t sdpos;
  72. // Job elapsed time
  73. millis_t print_job_elapsed;
  74. uint8_t valid_foot;
  75. } job_recovery_info_t;
  76. class PrintJobRecovery {
  77. public:
  78. static SdFile file;
  79. static job_recovery_info_t info;
  80. static void init();
  81. static bool enabled;
  82. static void enable(const bool onoff);
  83. static void changed();
  84. static void check();
  85. static void resume();
  86. static inline bool exists() { return card.jobRecoverFileExists(); }
  87. static inline void open(const bool read) { card.openJobRecoveryFile(read); }
  88. static inline void close() { file.close(); }
  89. static void purge();
  90. static void load();
  91. static void save(const bool force=
  92. #if ENABLED(SAVE_EACH_CMD_MODE)
  93. true
  94. #else
  95. false
  96. #endif
  97. , const bool save_queue=true
  98. );
  99. static inline bool valid() { return info.valid_head && info.valid_head == info.valid_foot; }
  100. #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  101. static void debug(PGM_P const prefix);
  102. #else
  103. static inline void debug(PGM_P const prefix) {}
  104. #endif
  105. private:
  106. static void write();
  107. };
  108. extern PrintJobRecovery recovery;