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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 DEBUG_POWER_LOSS_RECOVERY
  32. //#define SAVE_EACH_CMD_MODE
  33. //#define SAVE_INFO_INTERVAL_MS 0
  34. typedef struct {
  35. uint8_t valid_head;
  36. // Machine state
  37. float current_position[NUM_AXIS];
  38. #if HAS_HOME_OFFSET
  39. float home_offset[XYZ];
  40. #endif
  41. #if HAS_POSITION_SHIFT
  42. float position_shift[XYZ];
  43. #endif
  44. uint16_t feedrate;
  45. #if EXTRUDERS > 1
  46. uint8_t active_extruder;
  47. #endif
  48. int16_t target_temperature[HOTENDS];
  49. #if HAS_HEATED_BED
  50. int16_t target_temperature_bed;
  51. #endif
  52. #if FAN_COUNT
  53. uint8_t fan_speed[FAN_COUNT];
  54. #endif
  55. #if HAS_LEVELING
  56. bool leveling;
  57. float fade;
  58. #endif
  59. #if ENABLED(FWRETRACT)
  60. float retract[EXTRUDERS], retract_hop;
  61. #endif
  62. // Mixing extruder and gradient
  63. #if ENABLED(MIXING_EXTRUDER)
  64. //uint_fast8_t selected_vtool;
  65. //mixer_comp_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
  66. #if ENABLED(GRADIENT_MIX)
  67. gradient_t gradient;
  68. #endif
  69. #endif
  70. // Relative mode
  71. bool relative_mode, relative_modes_e;
  72. // Command queue
  73. uint8_t queue_length, queue_index_r;
  74. char queue_buffer[BUFSIZE][MAX_CMD_SIZE];
  75. // SD Filename and position
  76. char sd_filename[MAXPATHNAMELENGTH];
  77. uint32_t sdpos;
  78. // Job elapsed time
  79. millis_t print_job_elapsed;
  80. uint8_t valid_foot;
  81. } job_recovery_info_t;
  82. class PrintJobRecovery {
  83. public:
  84. static SdFile file;
  85. static job_recovery_info_t info;
  86. static void init();
  87. static bool enabled;
  88. static void enable(const bool onoff);
  89. static void changed();
  90. static void check();
  91. static void resume();
  92. static inline bool exists() { return card.jobRecoverFileExists(); }
  93. static inline void open(const bool read) { card.openJobRecoveryFile(read); }
  94. static inline void close() { file.close(); }
  95. static void purge();
  96. static void load();
  97. static void save(const bool force=
  98. #if ENABLED(SAVE_EACH_CMD_MODE)
  99. true
  100. #else
  101. false
  102. #endif
  103. , const bool save_queue=true
  104. );
  105. static inline bool valid() { return info.valid_head && info.valid_head == info.valid_foot; }
  106. #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  107. static void debug(PGM_P const prefix);
  108. #else
  109. static inline void debug(PGM_P const prefix) { UNUSED(prefix); }
  110. #endif
  111. private:
  112. static void write();
  113. };
  114. extern PrintJobRecovery recovery;