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

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