|
@@ -29,247 +29,145 @@
|
29
|
29
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
30
|
30
|
|
31
|
31
|
#include "power_loss_recovery.h"
|
|
32
|
+#include "../core/macros.h"
|
32
|
33
|
|
|
34
|
+bool PrintJobRecovery::enabled; // Initialized by settings.load()
|
|
35
|
+
|
|
36
|
+SdFile PrintJobRecovery::file;
|
|
37
|
+job_recovery_info_t PrintJobRecovery::info;
|
|
38
|
+
|
|
39
|
+#include "../sd/cardreader.h"
|
33
|
40
|
#include "../lcd/ultralcd.h"
|
34
|
41
|
#include "../gcode/queue.h"
|
|
42
|
+#include "../gcode/gcode.h"
|
35
|
43
|
#include "../module/motion.h"
|
36
|
44
|
#include "../module/planner.h"
|
37
|
45
|
#include "../module/printcounter.h"
|
38
|
46
|
#include "../module/temperature.h"
|
39
|
|
-#include "../sd/cardreader.h"
|
40
|
47
|
#include "../core/serial.h"
|
41
|
48
|
|
42
|
49
|
#if ENABLED(FWRETRACT)
|
43
|
50
|
#include "fwretract.h"
|
44
|
51
|
#endif
|
45
|
52
|
|
46
|
|
-// Recovery data
|
47
|
|
-job_recovery_info_t job_recovery_info;
|
48
|
|
-JobRecoveryPhase job_recovery_phase = JOB_RECOVERY_IDLE;
|
49
|
|
-uint8_t job_recovery_commands_count; //=0
|
50
|
|
-char job_recovery_commands[BUFSIZE + APPEND_CMD_COUNT][MAX_CMD_SIZE];
|
51
|
|
-
|
52
|
|
-extern uint8_t commands_in_queue, cmd_queue_index_r;
|
53
|
|
-
|
54
|
|
-#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
55
|
|
- void debug_print_job_recovery(const bool recovery) {
|
56
|
|
- SERIAL_PROTOCOLLNPGM("---- Job Recovery Info ----");
|
57
|
|
- SERIAL_PROTOCOLPAIR("valid_head:", int(job_recovery_info.valid_head));
|
58
|
|
- SERIAL_PROTOCOLLNPAIR(" valid_foot:", int(job_recovery_info.valid_foot));
|
59
|
|
- if (job_recovery_info.valid_head) {
|
60
|
|
- if (job_recovery_info.valid_head == job_recovery_info.valid_foot) {
|
61
|
|
- SERIAL_PROTOCOLPGM("current_position: ");
|
62
|
|
- LOOP_XYZE(i) {
|
63
|
|
- SERIAL_PROTOCOL(job_recovery_info.current_position[i]);
|
64
|
|
- if (i < E_AXIS) SERIAL_CHAR(',');
|
65
|
|
- }
|
66
|
|
- SERIAL_EOL();
|
67
|
|
- SERIAL_PROTOCOLLNPAIR("feedrate: ", job_recovery_info.feedrate);
|
|
53
|
+PrintJobRecovery recovery;
|
68
|
54
|
|
69
|
|
- #if HOTENDS > 1
|
70
|
|
- SERIAL_PROTOCOLLNPAIR("active_hotend: ", int(job_recovery_info.active_hotend));
|
71
|
|
- #endif
|
72
|
|
-
|
73
|
|
- SERIAL_PROTOCOLPGM("target_temperature: ");
|
74
|
|
- HOTEND_LOOP() {
|
75
|
|
- SERIAL_PROTOCOL(job_recovery_info.target_temperature[e]);
|
76
|
|
- if (e < HOTENDS - 1) SERIAL_CHAR(',');
|
77
|
|
- }
|
78
|
|
- SERIAL_EOL();
|
79
|
|
-
|
80
|
|
- #if HAS_HEATED_BED
|
81
|
|
- SERIAL_PROTOCOLLNPAIR("target_temperature_bed: ", job_recovery_info.target_temperature_bed);
|
82
|
|
- #endif
|
|
55
|
+/**
|
|
56
|
+ * Clear the recovery info
|
|
57
|
+ */
|
|
58
|
+void PrintJobRecovery::init() { memset(&info, 0, sizeof(info)); }
|
83
|
59
|
|
84
|
|
- #if FAN_COUNT
|
85
|
|
- SERIAL_PROTOCOLPGM("fan_speed: ");
|
86
|
|
- for (int8_t i = 0; i < FAN_COUNT; i++) {
|
87
|
|
- SERIAL_PROTOCOL(job_recovery_info.fan_speed[i]);
|
88
|
|
- if (i < FAN_COUNT - 1) SERIAL_CHAR(',');
|
89
|
|
- }
|
90
|
|
- SERIAL_EOL();
|
91
|
|
- #endif
|
|
60
|
+/**
|
|
61
|
+ * Enable or disable then call changed()
|
|
62
|
+ */
|
|
63
|
+void PrintJobRecovery::enable(const bool onoff) {
|
|
64
|
+ enabled = onoff;
|
|
65
|
+ changed();
|
|
66
|
+}
|
92
|
67
|
|
93
|
|
- #if HAS_LEVELING
|
94
|
|
- SERIAL_PROTOCOLPAIR("leveling: ", int(job_recovery_info.leveling));
|
95
|
|
- SERIAL_PROTOCOLLNPAIR(" fade: ", int(job_recovery_info.fade));
|
96
|
|
- #endif
|
97
|
|
- #if ENABLED(FWRETRACT)
|
98
|
|
- SERIAL_PROTOCOLPGM("retract: ");
|
99
|
|
- for (int8_t e = 0; e < EXTRUDERS; e++) {
|
100
|
|
- SERIAL_PROTOCOL(job_recovery_info.retract[e]);
|
101
|
|
- if (e < EXTRUDERS - 1) SERIAL_CHAR(',');
|
102
|
|
- }
|
103
|
|
- SERIAL_EOL();
|
104
|
|
- SERIAL_PROTOCOLLNPAIR("retract_hop: ", job_recovery_info.retract_hop);
|
105
|
|
- #endif
|
106
|
|
- SERIAL_PROTOCOLLNPAIR("cmd_queue_index_r: ", int(job_recovery_info.cmd_queue_index_r));
|
107
|
|
- SERIAL_PROTOCOLLNPAIR("commands_in_queue: ", int(job_recovery_info.commands_in_queue));
|
108
|
|
- if (recovery)
|
109
|
|
- for (uint8_t i = 0; i < job_recovery_commands_count; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_commands[i]);
|
110
|
|
- else
|
111
|
|
- for (uint8_t i = 0; i < job_recovery_info.commands_in_queue; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_info.command_queue[i]);
|
112
|
|
- SERIAL_PROTOCOLLNPAIR("sd_filename: ", job_recovery_info.sd_filename);
|
113
|
|
- SERIAL_PROTOCOLLNPAIR("sdpos: ", job_recovery_info.sdpos);
|
114
|
|
- SERIAL_PROTOCOLLNPAIR("print_job_elapsed: ", job_recovery_info.print_job_elapsed);
|
115
|
|
- }
|
116
|
|
- else
|
117
|
|
- SERIAL_PROTOCOLLNPGM("INVALID DATA");
|
118
|
|
- }
|
119
|
|
- SERIAL_PROTOCOLLNPGM("---------------------------");
|
120
|
|
- }
|
121
|
|
-#endif // DEBUG_POWER_LOSS_RECOVERY
|
|
68
|
+/**
|
|
69
|
+ * The enabled state was changed:
|
|
70
|
+ * - Enabled: Purge the job recovery file
|
|
71
|
+ * - Disabled: Write the job recovery file
|
|
72
|
+ */
|
|
73
|
+void PrintJobRecovery::changed() {
|
|
74
|
+ if (!enabled)
|
|
75
|
+ purge();
|
|
76
|
+ else if (IS_SD_PRINTING())
|
|
77
|
+ save(true);
|
|
78
|
+}
|
122
|
79
|
|
123
|
80
|
/**
|
124
|
81
|
* Check for Print Job Recovery during setup()
|
125
|
82
|
*
|
126
|
|
- * If a saved state exists, populate job_recovery_commands with
|
127
|
|
- * commands to restore the machine state and continue the file.
|
|
83
|
+ * If a saved state exists send 'M1000 S' to initiate job recovery.
|
128
|
84
|
*/
|
129
|
|
-void check_print_job_recovery() {
|
130
|
|
- memset(&job_recovery_info, 0, sizeof(job_recovery_info));
|
131
|
|
- ZERO(job_recovery_commands);
|
132
|
|
-
|
133
|
|
- if (!card.cardOK) card.initsd();
|
134
|
|
-
|
135
|
|
- if (card.cardOK) {
|
136
|
|
-
|
137
|
|
- #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
138
|
|
- SERIAL_PROTOCOLLNPAIR("Init job recovery info. Size: ", int(sizeof(job_recovery_info)));
|
139
|
|
- #endif
|
140
|
|
-
|
141
|
|
- if (card.jobRecoverFileExists()) {
|
142
|
|
- card.openJobRecoveryFile(true);
|
143
|
|
- card.loadJobRecoveryInfo();
|
144
|
|
- card.closeJobRecoveryFile();
|
145
|
|
- //card.removeJobRecoveryFile();
|
146
|
|
-
|
147
|
|
- if (job_recovery_info.valid_head && job_recovery_info.valid_head == job_recovery_info.valid_foot) {
|
148
|
|
-
|
149
|
|
- uint8_t ind = 0;
|
150
|
|
-
|
151
|
|
- #if HAS_LEVELING
|
152
|
|
- strcpy_P(job_recovery_commands[ind++], PSTR("M420 S0 Z0")); // Leveling off before G92 or G28
|
153
|
|
- #endif
|
154
|
|
-
|
155
|
|
- strcpy_P(job_recovery_commands[ind++], PSTR("G92.0 Z0")); // Ensure Z is equal to 0
|
156
|
|
- strcpy_P(job_recovery_commands[ind++], PSTR("G1 Z2")); // Raise Z by 2mm (we hope!)
|
157
|
|
- strcpy_P(job_recovery_commands[ind++], PSTR("G28 R0"
|
158
|
|
- #if ENABLED(MARLIN_DEV_MODE)
|
159
|
|
- " S"
|
160
|
|
- #elif !IS_KINEMATIC
|
161
|
|
- " X Y" // Home X and Y for Cartesian
|
162
|
|
- #endif
|
163
|
|
- ));
|
164
|
|
-
|
165
|
|
- char str_1[16], str_2[16];
|
166
|
|
-
|
167
|
|
- #if HAS_LEVELING
|
168
|
|
- if (job_recovery_info.fade || job_recovery_info.leveling) {
|
169
|
|
- // Restore leveling state before G92 sets Z
|
170
|
|
- // This ensures the steppers correspond to the native Z
|
171
|
|
- dtostrf(job_recovery_info.fade, 1, 1, str_1);
|
172
|
|
- sprintf_P(job_recovery_commands[ind++], PSTR("M420 S%i Z%s"), int(job_recovery_info.leveling), str_1);
|
173
|
|
- }
|
174
|
|
- #endif
|
175
|
|
-
|
176
|
|
- #if ENABLED(FWRETRACT)
|
177
|
|
- for (uint8_t e = 0; e < EXTRUDERS; e++) {
|
178
|
|
- if (job_recovery_info.retract[e] != 0.0)
|
179
|
|
- fwretract.current_retract[e] = job_recovery_info.retract[e];
|
180
|
|
- fwretract.retracted[e] = true;
|
181
|
|
- }
|
182
|
|
- fwretract.current_hop = job_recovery_info.retract_hop;
|
183
|
|
- #endif
|
184
|
|
-
|
185
|
|
- dtostrf(job_recovery_info.current_position[Z_AXIS] + 2, 1, 3, str_1);
|
186
|
|
- dtostrf(job_recovery_info.current_position[E_AXIS]
|
187
|
|
- #if ENABLED(SAVE_EACH_CMD_MODE)
|
188
|
|
- - 5
|
189
|
|
- #endif
|
190
|
|
- , 1, 3, str_2
|
191
|
|
- );
|
192
|
|
- sprintf_P(job_recovery_commands[ind++], PSTR("G92.0 Z%s E%s"), str_1, str_2); // Current Z + 2 and E
|
193
|
|
-
|
194
|
|
- uint8_t r = job_recovery_info.cmd_queue_index_r, c = job_recovery_info.commands_in_queue;
|
195
|
|
- while (c--) {
|
196
|
|
- strcpy(job_recovery_commands[ind++], job_recovery_info.command_queue[r]);
|
197
|
|
- r = (r + 1) % BUFSIZE;
|
198
|
|
- }
|
199
|
|
-
|
200
|
|
- if (job_recovery_info.sd_filename[0] == '/') job_recovery_info.sd_filename[0] = ' ';
|
201
|
|
- sprintf_P(job_recovery_commands[ind++], PSTR("M23 %s"), job_recovery_info.sd_filename);
|
202
|
|
- sprintf_P(job_recovery_commands[ind++], PSTR("M24 S%ld T%ld"), job_recovery_info.sdpos, job_recovery_info.print_job_elapsed);
|
|
85
|
+void PrintJobRecovery::check() {
|
|
86
|
+ if (enabled) {
|
|
87
|
+ if (!card.cardOK) card.initsd();
|
|
88
|
+ if (card.cardOK) {
|
|
89
|
+ load();
|
|
90
|
+ if (!valid()) return purge();
|
|
91
|
+ enqueue_and_echo_commands_P(PSTR("M1000 S"));
|
|
92
|
+ }
|
|
93
|
+ }
|
|
94
|
+}
|
203
|
95
|
|
204
|
|
- job_recovery_commands_count = ind;
|
|
96
|
+/**
|
|
97
|
+ * Delete the recovery file and clear the recovery data
|
|
98
|
+ */
|
|
99
|
+void PrintJobRecovery::purge() {
|
|
100
|
+ init();
|
|
101
|
+ card.removeJobRecoveryFile();
|
|
102
|
+}
|
205
|
103
|
|
206
|
|
- #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
207
|
|
- debug_print_job_recovery(true);
|
208
|
|
- #endif
|
209
|
|
- }
|
210
|
|
- else {
|
211
|
|
- if (job_recovery_info.valid_head != job_recovery_info.valid_foot)
|
212
|
|
- LCD_ALERTMESSAGEPGM("INVALID DATA");
|
213
|
|
- memset(&job_recovery_info, 0, sizeof(job_recovery_info));
|
214
|
|
- }
|
215
|
|
- }
|
|
104
|
+/**
|
|
105
|
+ * Load the recovery data, if it exists
|
|
106
|
+ */
|
|
107
|
+void PrintJobRecovery::load() {
|
|
108
|
+ if (exists()) {
|
|
109
|
+ open(true);
|
|
110
|
+ (void)file.read(&info, sizeof(info));
|
|
111
|
+ close();
|
216
|
112
|
}
|
|
113
|
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
|
114
|
+ debug(PSTR("Load"));
|
|
115
|
+ #endif
|
217
|
116
|
}
|
218
|
117
|
|
219
|
118
|
/**
|
220
|
119
|
* Save the current machine state to the power-loss recovery file
|
221
|
120
|
*/
|
222
|
|
-void save_job_recovery_info() {
|
|
121
|
+void PrintJobRecovery::save(const bool force/*=false*/) {
|
|
122
|
+
|
223
|
123
|
#if SAVE_INFO_INTERVAL_MS > 0
|
224
|
|
- static millis_t next_save_ms; // = 0; // Init on reset
|
|
124
|
+ static millis_t next_save_ms; // = 0
|
225
|
125
|
millis_t ms = millis();
|
226
|
126
|
#endif
|
227
|
|
- if (
|
228
|
|
- // Save on every command
|
229
|
|
- #if ENABLED(SAVE_EACH_CMD_MODE)
|
230
|
|
- true
|
231
|
|
- #else
|
232
|
|
- // Save if power loss pin is triggered
|
233
|
|
- #if PIN_EXISTS(POWER_LOSS)
|
234
|
|
- READ(POWER_LOSS_PIN) == POWER_LOSS_STATE ||
|
|
127
|
+
|
|
128
|
+ if (force
|
|
129
|
+ #if DISABLED(SAVE_EACH_CMD_MODE) // Always save state when enabled
|
|
130
|
+ #if PIN_EXISTS(POWER_LOSS) // Save if power loss pin is triggered
|
|
131
|
+ || READ(POWER_LOSS_PIN) == POWER_LOSS_STATE
|
235
|
132
|
#endif
|
236
|
|
- // Save if interval is elapsed
|
237
|
|
- #if SAVE_INFO_INTERVAL_MS > 0
|
238
|
|
- ELAPSED(ms, next_save_ms) ||
|
|
133
|
+ #if SAVE_INFO_INTERVAL_MS > 0 // Save if interval is elapsed
|
|
134
|
+ || ELAPSED(ms, next_save_ms)
|
239
|
135
|
#endif
|
240
|
|
- // Save on every new Z height
|
241
|
|
- (current_position[Z_AXIS] > 0 && current_position[Z_AXIS] > job_recovery_info.current_position[Z_AXIS])
|
|
136
|
+ // Save every time Z is higher than the last call
|
|
137
|
+ || current_position[Z_AXIS] > info.current_position[Z_AXIS]
|
242
|
138
|
#endif
|
243
|
139
|
) {
|
|
140
|
+
|
244
|
141
|
#if SAVE_INFO_INTERVAL_MS > 0
|
245
|
142
|
next_save_ms = ms + SAVE_INFO_INTERVAL_MS;
|
246
|
143
|
#endif
|
247
|
144
|
|
248
|
|
- // Head and foot will match if valid data was saved
|
249
|
|
- if (!++job_recovery_info.valid_head) ++job_recovery_info.valid_head; // non-zero in sequence
|
250
|
|
- job_recovery_info.valid_foot = job_recovery_info.valid_head;
|
|
145
|
+ // Set Head and Foot to matching non-zero values
|
|
146
|
+ if (!++info.valid_head) ++info.valid_head; // non-zero in sequence
|
|
147
|
+ //if (!IS_SD_PRINTING()) info.valid_head = 0;
|
|
148
|
+ info.valid_foot = info.valid_head;
|
251
|
149
|
|
252
|
150
|
// Machine state
|
253
|
|
- COPY(job_recovery_info.current_position, current_position);
|
254
|
|
- job_recovery_info.feedrate = feedrate_mm_s;
|
|
151
|
+ COPY(info.current_position, current_position);
|
|
152
|
+ info.feedrate = uint16_t(feedrate_mm_s * 60.0f);
|
255
|
153
|
|
256
|
154
|
#if HOTENDS > 1
|
257
|
|
- job_recovery_info.active_hotend = active_extruder;
|
|
155
|
+ info.active_hotend = active_extruder;
|
258
|
156
|
#endif
|
259
|
157
|
|
260
|
|
- COPY(job_recovery_info.target_temperature, thermalManager.target_temperature);
|
|
158
|
+ COPY(info.target_temperature, thermalManager.target_temperature);
|
261
|
159
|
|
262
|
160
|
#if HAS_HEATED_BED
|
263
|
|
- job_recovery_info.target_temperature_bed = thermalManager.target_temperature_bed;
|
|
161
|
+ info.target_temperature_bed = thermalManager.target_temperature_bed;
|
264
|
162
|
#endif
|
265
|
163
|
|
266
|
164
|
#if FAN_COUNT
|
267
|
|
- COPY(job_recovery_info.fan_speed, fan_speed);
|
|
165
|
+ COPY(info.fan_speed, fan_speed);
|
268
|
166
|
#endif
|
269
|
167
|
|
270
|
168
|
#if HAS_LEVELING
|
271
|
|
- job_recovery_info.leveling = planner.leveling_active;
|
272
|
|
- job_recovery_info.fade = (
|
|
169
|
+ info.leveling = planner.leveling_active;
|
|
170
|
+ info.fade = (
|
273
|
171
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
274
|
172
|
planner.z_fade_height
|
275
|
173
|
#else
|
|
@@ -279,35 +177,238 @@ void save_job_recovery_info() {
|
279
|
177
|
#endif
|
280
|
178
|
|
281
|
179
|
#if ENABLED(FWRETRACT)
|
282
|
|
- COPY(job_recovery_info.retract, fwretract.current_retract);
|
283
|
|
- job_recovery_info.retract_hop = fwretract.current_hop;
|
|
180
|
+ COPY(info.retract, fwretract.current_retract);
|
|
181
|
+ info.retract_hop = fwretract.current_hop;
|
284
|
182
|
#endif
|
285
|
183
|
|
286
|
184
|
// Commands in the queue
|
287
|
|
- job_recovery_info.cmd_queue_index_r = cmd_queue_index_r;
|
288
|
|
- job_recovery_info.commands_in_queue = commands_in_queue;
|
289
|
|
- COPY(job_recovery_info.command_queue, command_queue);
|
|
185
|
+ info.cmd_queue_index_r = cmd_queue_index_r;
|
|
186
|
+ info.commands_in_queue = commands_in_queue;
|
|
187
|
+ COPY(info.command_queue, command_queue);
|
290
|
188
|
|
291
|
189
|
// Elapsed print job time
|
292
|
|
- job_recovery_info.print_job_elapsed = print_job_timer.duration();
|
|
190
|
+ info.print_job_elapsed = print_job_timer.duration();
|
293
|
191
|
|
294
|
192
|
// SD file position
|
295
|
|
- card.getAbsFilename(job_recovery_info.sd_filename);
|
296
|
|
- job_recovery_info.sdpos = card.getIndex();
|
|
193
|
+ card.getAbsFilename(info.sd_filename);
|
|
194
|
+ info.sdpos = card.getIndex();
|
|
195
|
+
|
|
196
|
+ write();
|
297
|
197
|
|
298
|
|
- #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
299
|
|
- SERIAL_PROTOCOLLNPGM("Saving...");
|
300
|
|
- debug_print_job_recovery(false);
|
|
198
|
+ // KILL now if the power-loss pin was triggered
|
|
199
|
+ #if PIN_EXISTS(POWER_LOSS)
|
|
200
|
+ if (READ(POWER_LOSS_PIN) == POWER_LOSS_STATE) kill(MSG_OUTAGE_RECOVERY);
|
301
|
201
|
#endif
|
|
202
|
+ }
|
|
203
|
+}
|
302
|
204
|
|
303
|
|
- card.openJobRecoveryFile(false);
|
304
|
|
- (void)card.saveJobRecoveryInfo();
|
|
205
|
+/**
|
|
206
|
+ * Save the recovery info the recovery file
|
|
207
|
+ */
|
|
208
|
+void PrintJobRecovery::write() {
|
305
|
209
|
|
306
|
|
- // If power-loss pin was triggered, write just once then kill
|
307
|
|
- #if PIN_EXISTS(POWER_LOSS)
|
308
|
|
- if (READ(POWER_LOSS_PIN) == POWER_LOSS_STATE) kill(MSG_POWER_LOSS_RECOVERY);
|
|
210
|
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
|
211
|
+ debug(PSTR("Write"));
|
|
212
|
+ #endif
|
|
213
|
+
|
|
214
|
+ open(false);
|
|
215
|
+ file.seekSet(0);
|
|
216
|
+ const int16_t ret = file.write(&info, sizeof(info));
|
|
217
|
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
|
218
|
+ if (ret == -1) SERIAL_ECHOLNPGM("Power-loss file write failed.");
|
|
219
|
+ #endif
|
|
220
|
+}
|
|
221
|
+
|
|
222
|
+/**
|
|
223
|
+ * Resume the saved print job
|
|
224
|
+ */
|
|
225
|
+void PrintJobRecovery::resume() {
|
|
226
|
+
|
|
227
|
+ #define RECOVERY_ZRAISE 2
|
|
228
|
+
|
|
229
|
+ #if HAS_LEVELING
|
|
230
|
+ // Make sure leveling is off before any G92 and G28
|
|
231
|
+ gcode.process_subcommands_now_P(PSTR("M420 S0 Z0"));
|
|
232
|
+ #endif
|
|
233
|
+
|
|
234
|
+ // Set Z to 0, raise Z by 2mm, and Home (XY only for Cartesian) with no raise
|
|
235
|
+ // (Only do simulated homing in Marlin Dev Mode.)
|
|
236
|
+ gcode.process_subcommands_now_P(PSTR("G92.0 Z0|G1 Z" STRINGIFY(RECOVERY_ZRAISE) "|G28 R0"
|
|
237
|
+ #if ENABLED(MARLIN_DEV_MODE)
|
|
238
|
+ " S"
|
|
239
|
+ #elif !IS_KINEMATIC
|
|
240
|
+ " X Y"
|
309
|
241
|
#endif
|
|
242
|
+ ));
|
|
243
|
+
|
|
244
|
+ // Pretend that all axes are homed
|
|
245
|
+ axis_homed = axis_known_position = xyz_bits;
|
|
246
|
+
|
|
247
|
+ char cmd[40], str_1[16], str_2[16];
|
|
248
|
+
|
|
249
|
+ // Select the previously active tool (with no_move)
|
|
250
|
+ #if EXTRUDERS > 1
|
|
251
|
+ sprintf_P(cmd, PSTR("T%i S"), info.active_hotend);
|
|
252
|
+ gcode.process_subcommands_now(cmd);
|
|
253
|
+ #endif
|
|
254
|
+
|
|
255
|
+ #if HAS_HEATED_BED
|
|
256
|
+ const int16_t bt = info.target_temperature_bed;
|
|
257
|
+ if (bt) {
|
|
258
|
+ // Restore the bed temperature
|
|
259
|
+ sprintf_P(cmd, PSTR("M190 S%i"), bt);
|
|
260
|
+ gcode.process_subcommands_now(cmd);
|
|
261
|
+ }
|
|
262
|
+ #endif
|
|
263
|
+
|
|
264
|
+ // Restore all hotend temperatures
|
|
265
|
+ HOTEND_LOOP() {
|
|
266
|
+ const int16_t et = info.target_temperature[e];
|
|
267
|
+ if (et) {
|
|
268
|
+ #if HOTENDS > 1
|
|
269
|
+ sprintf_P(cmd, PSTR("T%i"), e);
|
|
270
|
+ gcode.process_subcommands_now(cmd);
|
|
271
|
+ #endif
|
|
272
|
+ sprintf_P(cmd, PSTR("M109 S%i"), et);
|
|
273
|
+ gcode.process_subcommands_now(cmd);
|
|
274
|
+ }
|
310
|
275
|
}
|
|
276
|
+
|
|
277
|
+ // Restore print cooling fan speeds
|
|
278
|
+ for (uint8_t i = 0; i < FAN_COUNT; i++) {
|
|
279
|
+ uint8_t f = info.fan_speed[i];
|
|
280
|
+ if (f) {
|
|
281
|
+ sprintf_P(cmd, PSTR("M106 P%i S%i"), i, f);
|
|
282
|
+ gcode.process_subcommands_now(cmd);
|
|
283
|
+ }
|
|
284
|
+ }
|
|
285
|
+
|
|
286
|
+ // Restore retract and hop state
|
|
287
|
+ #if ENABLED(FWRETRACT)
|
|
288
|
+ for (uint8_t e = 0; e < EXTRUDERS; e++) {
|
|
289
|
+ if (info.retract[e] != 0.0)
|
|
290
|
+ fwretract.current_retract[e] = info.retract[e];
|
|
291
|
+ fwretract.retracted[e] = true;
|
|
292
|
+ }
|
|
293
|
+ fwretract.current_hop = info.retract_hop;
|
|
294
|
+ #endif
|
|
295
|
+
|
|
296
|
+ #if HAS_LEVELING
|
|
297
|
+ // Restore leveling state before 'G92 Z' to ensure
|
|
298
|
+ // the Z stepper count corresponds to the native Z.
|
|
299
|
+ if (info.fade || info.leveling) {
|
|
300
|
+ dtostrf(info.fade, 1, 1, str_1);
|
|
301
|
+ sprintf_P(cmd, PSTR("M420 S%i Z%s"), int(info.leveling), str_1);
|
|
302
|
+ gcode.process_subcommands_now(cmd);
|
|
303
|
+ }
|
|
304
|
+ #endif
|
|
305
|
+
|
|
306
|
+ // Restore Z (plus raise) and E positions with G92.0
|
|
307
|
+ dtostrf(info.current_position[Z_AXIS] + RECOVERY_ZRAISE, 1, 3, str_1);
|
|
308
|
+ dtostrf(info.current_position[E_AXIS]
|
|
309
|
+ #if ENABLED(SAVE_EACH_CMD_MODE)
|
|
310
|
+ - 5 // Extra extrusion on restart
|
|
311
|
+ #endif
|
|
312
|
+ , 1, 3, str_2
|
|
313
|
+ );
|
|
314
|
+ sprintf_P(cmd, PSTR("G92.0 Z%s E%s"), str_1, str_2);
|
|
315
|
+ gcode.process_subcommands_now(cmd);
|
|
316
|
+
|
|
317
|
+ // Move back to the saved XY
|
|
318
|
+ dtostrf(info.current_position[X_AXIS], 1, 3, str_1);
|
|
319
|
+ dtostrf(info.current_position[Y_AXIS], 1, 3, str_2);
|
|
320
|
+ sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"), str_1, str_2);
|
|
321
|
+ gcode.process_subcommands_now(cmd);
|
|
322
|
+
|
|
323
|
+ // Move back to the saved Z
|
|
324
|
+ dtostrf(info.current_position[Z_AXIS], 1, 3, str_1);
|
|
325
|
+ sprintf_P(cmd, PSTR("G1 Z%s F200"), str_1);
|
|
326
|
+ gcode.process_subcommands_now(cmd);
|
|
327
|
+
|
|
328
|
+ // Restore the feedrate
|
|
329
|
+ sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate);
|
|
330
|
+ gcode.process_subcommands_now(cmd);
|
|
331
|
+
|
|
332
|
+ // Process commands from the old pending queue
|
|
333
|
+ uint8_t r = info.cmd_queue_index_r, c = info.commands_in_queue;
|
|
334
|
+ for (; c--; r = (r + 1) % BUFSIZE)
|
|
335
|
+ gcode.process_subcommands_now(info.command_queue[r]);
|
|
336
|
+
|
|
337
|
+ // Resume the SD file from the last position
|
|
338
|
+ char *fn = info.sd_filename;
|
|
339
|
+ while (*fn == '/') fn++;
|
|
340
|
+ sprintf_P(cmd, PSTR("M23 %s"), fn);
|
|
341
|
+ gcode.process_subcommands_now(cmd);
|
|
342
|
+ sprintf_P(cmd, PSTR("M24 S%ld T%ld"), info.sdpos, info.print_job_elapsed);
|
|
343
|
+ gcode.process_subcommands_now(cmd);
|
311
|
344
|
}
|
312
|
345
|
|
|
346
|
+#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
|
|
347
|
+
|
|
348
|
+ void PrintJobRecovery::debug(PGM_P const prefix) {
|
|
349
|
+ serialprintPGM(prefix);
|
|
350
|
+ SERIAL_ECHOPAIR(" Job Recovery Info...\nvalid_head:", int(info.valid_head));
|
|
351
|
+ SERIAL_ECHOLNPAIR(" valid_foot:", int(info.valid_foot));
|
|
352
|
+ if (info.valid_head) {
|
|
353
|
+ if (info.valid_head == info.valid_foot) {
|
|
354
|
+ SERIAL_ECHOPGM("current_position: ");
|
|
355
|
+ LOOP_XYZE(i) {
|
|
356
|
+ SERIAL_ECHO(info.current_position[i]);
|
|
357
|
+ if (i < E_AXIS) SERIAL_CHAR(',');
|
|
358
|
+ }
|
|
359
|
+ SERIAL_EOL();
|
|
360
|
+ SERIAL_ECHOLNPAIR("feedrate: ", info.feedrate);
|
|
361
|
+
|
|
362
|
+ #if HOTENDS > 1
|
|
363
|
+ SERIAL_ECHOLNPAIR("active_hotend: ", int(info.active_hotend));
|
|
364
|
+ #endif
|
|
365
|
+
|
|
366
|
+ SERIAL_ECHOPGM("target_temperature: ");
|
|
367
|
+ HOTEND_LOOP() {
|
|
368
|
+ SERIAL_ECHO(info.target_temperature[e]);
|
|
369
|
+ if (e < HOTENDS - 1) SERIAL_CHAR(',');
|
|
370
|
+ }
|
|
371
|
+ SERIAL_EOL();
|
|
372
|
+
|
|
373
|
+ #if HAS_HEATED_BED
|
|
374
|
+ SERIAL_ECHOLNPAIR("target_temperature_bed: ", info.target_temperature_bed);
|
|
375
|
+ #endif
|
|
376
|
+
|
|
377
|
+ #if FAN_COUNT
|
|
378
|
+ SERIAL_ECHOPGM("fan_speed: ");
|
|
379
|
+ for (int8_t i = 0; i < FAN_COUNT; i++) {
|
|
380
|
+ SERIAL_ECHO(int(info.fan_speed[i]));
|
|
381
|
+ if (i < FAN_COUNT - 1) SERIAL_CHAR(',');
|
|
382
|
+ }
|
|
383
|
+ SERIAL_EOL();
|
|
384
|
+ #endif
|
|
385
|
+
|
|
386
|
+ #if HAS_LEVELING
|
|
387
|
+ SERIAL_ECHOPAIR("leveling: ", int(info.leveling));
|
|
388
|
+ SERIAL_ECHOLNPAIR(" fade: ", int(info.fade));
|
|
389
|
+ #endif
|
|
390
|
+ #if ENABLED(FWRETRACT)
|
|
391
|
+ SERIAL_ECHOPGM("retract: ");
|
|
392
|
+ for (int8_t e = 0; e < EXTRUDERS; e++) {
|
|
393
|
+ SERIAL_ECHO(info.retract[e]);
|
|
394
|
+ if (e < EXTRUDERS - 1) SERIAL_CHAR(',');
|
|
395
|
+ }
|
|
396
|
+ SERIAL_EOL();
|
|
397
|
+ SERIAL_ECHOLNPAIR("retract_hop: ", info.retract_hop);
|
|
398
|
+ #endif
|
|
399
|
+ SERIAL_ECHOLNPAIR("cmd_queue_index_r: ", int(info.cmd_queue_index_r));
|
|
400
|
+ SERIAL_ECHOLNPAIR("commands_in_queue: ", int(info.commands_in_queue));
|
|
401
|
+ for (uint8_t i = 0; i < info.commands_in_queue; i++) SERIAL_ECHOLNPAIR("> ", info.command_queue[i]);
|
|
402
|
+ SERIAL_ECHOLNPAIR("sd_filename: ", info.sd_filename);
|
|
403
|
+ SERIAL_ECHOLNPAIR("sdpos: ", info.sdpos);
|
|
404
|
+ SERIAL_ECHOLNPAIR("print_job_elapsed: ", info.print_job_elapsed);
|
|
405
|
+ }
|
|
406
|
+ else
|
|
407
|
+ SERIAL_ECHOLNPGM("INVALID DATA");
|
|
408
|
+ }
|
|
409
|
+ SERIAL_ECHOLNPGM("---");
|
|
410
|
+ }
|
|
411
|
+
|
|
412
|
+#endif // DEBUG_POWER_LOSS_RECOVERY
|
|
413
|
+
|
313
|
414
|
#endif // POWER_LOSS_RECOVERY
|