|
@@ -66,12 +66,16 @@ PrintJobRecovery recovery;
|
66
|
66
|
#ifndef POWER_LOSS_PURGE_LEN
|
67
|
67
|
#define POWER_LOSS_PURGE_LEN 0
|
68
|
68
|
#endif
|
|
69
|
+#ifndef POWER_LOSS_ZRAISE
|
|
70
|
+ #define POWER_LOSS_ZRAISE 2 // Move on loss with backup power, or on resume without it
|
|
71
|
+#endif
|
|
72
|
+
|
|
73
|
+#if DISABLED(BACKUP_POWER_SUPPLY)
|
|
74
|
+ #undef POWER_LOSS_RETRACT_LEN // No retract at outage without backup power
|
|
75
|
+#endif
|
69
|
76
|
#ifndef POWER_LOSS_RETRACT_LEN
|
70
|
77
|
#define POWER_LOSS_RETRACT_LEN 0
|
71
|
78
|
#endif
|
72
|
|
-#ifndef POWER_LOSS_ZRAISE
|
73
|
|
- #define POWER_LOSS_ZRAISE 2
|
74
|
|
-#endif
|
75
|
79
|
|
76
|
80
|
/**
|
77
|
81
|
* Clear the recovery info
|
|
@@ -144,7 +148,7 @@ void PrintJobRecovery::prepare() {
|
144
|
148
|
/**
|
145
|
149
|
* Save the current machine state to the power-loss recovery file
|
146
|
150
|
*/
|
147
|
|
-void PrintJobRecovery::save(const bool force/*=false*/) {
|
|
151
|
+void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/) {
|
148
|
152
|
|
149
|
153
|
#if SAVE_INFO_INTERVAL_MS > 0
|
150
|
154
|
static millis_t next_save_ms; // = 0
|
|
@@ -177,6 +181,7 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
|
177
|
181
|
|
178
|
182
|
// Machine state
|
179
|
183
|
info.current_position = current_position;
|
|
184
|
+ info.zraise = zraise;
|
180
|
185
|
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
|
181
|
186
|
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
|
182
|
187
|
info.feedrate = uint16_t(feedrate_mm_s * 60.0f);
|
|
@@ -228,30 +233,73 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
|
228
|
233
|
|
229
|
234
|
#if PIN_EXISTS(POWER_LOSS)
|
230
|
235
|
|
|
236
|
+ #if ENABLED(BACKUP_POWER_SUPPLY)
|
|
237
|
+
|
|
238
|
+ void PrintJobRecovery::retract_and_lift(const float &zraise) {
|
|
239
|
+ #if POWER_LOSS_RETRACT_LEN || POWER_LOSS_ZRAISE
|
|
240
|
+
|
|
241
|
+ gcode.set_relative_mode(true); // Use relative coordinates
|
|
242
|
+
|
|
243
|
+ #if POWER_LOSS_RETRACT_LEN
|
|
244
|
+ // Retract filament now
|
|
245
|
+ gcode.process_subcommands_now_P(PSTR("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
|
|
246
|
+ #endif
|
|
247
|
+
|
|
248
|
+ #if POWER_LOSS_ZRAISE
|
|
249
|
+ // Raise the Z axis now
|
|
250
|
+ if (zraise) {
|
|
251
|
+ char cmd[20], str_1[16];
|
|
252
|
+ sprintf_P(cmd, PSTR("G0 Z%s"), dtostrf(zraise, 1, 3, str_1));
|
|
253
|
+ gcode.process_subcommands_now(cmd);
|
|
254
|
+ }
|
|
255
|
+ #else
|
|
256
|
+ UNUSED(zraise);
|
|
257
|
+ #endif
|
|
258
|
+
|
|
259
|
+ //gcode.axis_relative = info.axis_relative;
|
|
260
|
+ planner.synchronize();
|
|
261
|
+ #endif
|
|
262
|
+ }
|
|
263
|
+
|
|
264
|
+ #endif
|
|
265
|
+
|
|
266
|
+ /**
|
|
267
|
+ * An outage was detected by a sensor pin.
|
|
268
|
+ * - If not SD printing, let the machine turn off on its own with no "KILL" screen
|
|
269
|
+ * - Disable all heaters first to save energy
|
|
270
|
+ * - Save the recovery data for the current instant
|
|
271
|
+ * - If backup power is available Retract E and Raise Z
|
|
272
|
+ * - Go to the KILL screen
|
|
273
|
+ */
|
231
|
274
|
void PrintJobRecovery::_outage() {
|
232
|
275
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
233
|
276
|
static bool lock = false;
|
234
|
|
- if (lock) return; // No re-entrance from idle() during raise_z()
|
|
277
|
+ if (lock) return; // No re-entrance from idle() during retract_and_lift()
|
235
|
278
|
lock = true;
|
236
|
279
|
#endif
|
237
|
|
- if (IS_SD_PRINTING()) save(true);
|
238
|
|
- TERN_(BACKUP_POWER_SUPPLY, raise_z());
|
239
|
280
|
|
240
|
|
- kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
|
241
|
|
- }
|
|
281
|
+ #if POWER_LOSS_ZRAISE
|
|
282
|
+ // Get the limited Z-raise to do now or on resume
|
|
283
|
+ const float zraise = _MAX(0, _MIN(current_position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - current_position.z);
|
|
284
|
+ #else
|
|
285
|
+ constexpr float zraise = 0;
|
|
286
|
+ #endif
|
242
|
287
|
|
243
|
|
- #if ENABLED(BACKUP_POWER_SUPPLY)
|
|
288
|
+ // Save, including the limited Z raise
|
|
289
|
+ if (IS_SD_PRINTING()) save(true, zraise);
|
|
290
|
+
|
|
291
|
+ // Disable all heaters to reduce power loss
|
|
292
|
+ thermalManager.disable_all_heaters();
|
244
|
293
|
|
245
|
|
- void PrintJobRecovery::raise_z() {
|
246
|
|
- // Disable all heaters to reduce power loss
|
247
|
|
- thermalManager.disable_all_heaters();
|
|
294
|
+ #if ENABLED(BACKUP_POWER_SUPPLY)
|
|
295
|
+ // Do a hard-stop of the steppers (with possibly a loud thud)
|
248
|
296
|
quickstop_stepper();
|
249
|
|
- // Raise Z axis
|
250
|
|
- gcode.process_subcommands_now_P(PSTR("G91\nG0 Z" STRINGIFY(POWER_LOSS_ZRAISE)));
|
251
|
|
- planner.synchronize();
|
252
|
|
- }
|
|
297
|
+ // With backup power a retract and raise can be done now
|
|
298
|
+ retract_and_lift(zraise);
|
|
299
|
+ #endif
|
253
|
300
|
|
254
|
|
- #endif
|
|
301
|
+ kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
|
|
302
|
+ }
|
255
|
303
|
|
256
|
304
|
#endif
|
257
|
305
|
|
|
@@ -274,6 +322,8 @@ void PrintJobRecovery::write() {
|
274
|
322
|
*/
|
275
|
323
|
void PrintJobRecovery::resume() {
|
276
|
324
|
|
|
325
|
+ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
|
|
326
|
+
|
277
|
327
|
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
|
278
|
328
|
|
279
|
329
|
#if HAS_LEVELING
|
|
@@ -282,52 +332,46 @@ void PrintJobRecovery::resume() {
|
282
|
332
|
#endif
|
283
|
333
|
|
284
|
334
|
// Reset E, raise Z, home XY...
|
285
|
|
- gcode.process_subcommands_now_P(PSTR("G92.9 E0"
|
286
|
|
- #if Z_HOME_DIR > 0
|
|
335
|
+ #if Z_HOME_DIR > 0
|
287
|
336
|
|
288
|
|
- // If Z homing goes to max, just reset E and home all
|
289
|
|
- "\n"
|
290
|
|
- "G28R0"
|
291
|
|
- TERN_(MARLIN_DEV_MODE, "S")
|
|
337
|
+ // If Z homing goes to max, just reset E and home all
|
|
338
|
+ gcode.process_subcommands_now_P(PSTR(
|
|
339
|
+ "G92.9 E0\n"
|
|
340
|
+ "G28R0" TERN_(MARLIN_DEV_MODE, "S")
|
|
341
|
+ ));
|
292
|
342
|
|
293
|
|
- #else // "G92.9 E0 ..."
|
|
343
|
+ #else // "G92.9 E0 ..."
|
294
|
344
|
|
295
|
|
- // Set Z to 0, raise Z by RECOVERY_ZRAISE, and Home (XY only for Cartesian)
|
296
|
|
- // with no raise. (Only do simulated homing in Marlin Dev Mode.)
|
297
|
|
- #if ENABLED(BACKUP_POWER_SUPPLY)
|
298
|
|
- "Z" STRINGIFY(POWER_LOSS_ZRAISE) // Z-axis was already raised at outage
|
299
|
|
- #else
|
300
|
|
- "Z0\n" // Set Z=0
|
301
|
|
- "G1Z" STRINGIFY(POWER_LOSS_ZRAISE) // Raise Z
|
302
|
|
- #endif
|
303
|
|
- "\n"
|
|
345
|
+ // Set Z to 0, raise Z by info.zraise, and Home (XY only for Cartesian)
|
|
346
|
+ // with no raise. (Only do simulated homing in Marlin Dev Mode.)
|
304
|
347
|
|
305
|
|
- "G28R0"
|
306
|
|
- #if ENABLED(MARLIN_DEV_MODE)
|
307
|
|
- "S"
|
308
|
|
- #elif !IS_KINEMATIC
|
309
|
|
- "XY"
|
310
|
|
- #endif
|
311
|
|
- #endif
|
312
|
|
- ));
|
313
|
|
-
|
314
|
|
- // Pretend that all axes are homed
|
315
|
|
- axis_homed = axis_known_position = xyz_bits;
|
|
348
|
+ sprintf_P(cmd, PSTR("G92.9 E0 "
|
|
349
|
+ #if ENABLED(BACKUP_POWER_SUPPLY)
|
|
350
|
+ "Z%s" // Z was already raised at outage
|
|
351
|
+ #else
|
|
352
|
+ "Z0\nG1Z%s" // Set Z=0 and Raise Z now
|
|
353
|
+ #endif
|
|
354
|
+ ),
|
|
355
|
+ dtostrf(info.zraise, 1, 3, str_1)
|
|
356
|
+ );
|
|
357
|
+ gcode.process_subcommands_now(cmd);
|
316
|
358
|
|
317
|
|
- char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
|
|
359
|
+ gcode.process_subcommands_now_P(PSTR(
|
|
360
|
+ "G28R0" // No raise during G28
|
|
361
|
+ TERN_(MARLIN_DEV_MODE, "S") // Simulated Homing
|
|
362
|
+ TERN_(IS_CARTESIAN, "XY") // Don't home Z on Cartesian
|
|
363
|
+ ));
|
318
|
364
|
|
319
|
|
- // Select the previously active tool (with no_move)
|
320
|
|
- #if EXTRUDERS > 1
|
321
|
|
- sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
|
322
|
|
- gcode.process_subcommands_now(cmd);
|
323
|
365
|
#endif
|
324
|
366
|
|
|
367
|
+ // Pretend that all axes are homed
|
|
368
|
+ axis_homed = axis_known_position = xyz_bits;
|
|
369
|
+
|
325
|
370
|
// Recover volumetric extrusion state
|
326
|
371
|
#if DISABLED(NO_VOLUMETRICS)
|
327
|
372
|
#if EXTRUDERS > 1
|
328
|
373
|
for (int8_t e = 0; e < EXTRUDERS; e++) {
|
329
|
|
- dtostrf(info.filament_size[e], 1, 3, str_1);
|
330
|
|
- sprintf_P(cmd, PSTR("M200 T%i D%s"), e, str_1);
|
|
374
|
+ sprintf_P(cmd, PSTR("M200 T%i D%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1));
|
331
|
375
|
gcode.process_subcommands_now(cmd);
|
332
|
376
|
}
|
333
|
377
|
if (!info.volumetric_enabled) {
|
|
@@ -336,8 +380,7 @@ void PrintJobRecovery::resume() {
|
336
|
380
|
}
|
337
|
381
|
#else
|
338
|
382
|
if (info.volumetric_enabled) {
|
339
|
|
- dtostrf(info.filament_size[0], 1, 3, str_1);
|
340
|
|
- sprintf_P(cmd, PSTR("M200 D%s"), str_1);
|
|
383
|
+ sprintf_P(cmd, PSTR("M200 D%s"), dtostrf(info.filament_size[0], 1, 3, str_1));
|
341
|
384
|
gcode.process_subcommands_now(cmd);
|
342
|
385
|
}
|
343
|
386
|
#endif
|
|
@@ -358,7 +401,7 @@ void PrintJobRecovery::resume() {
|
358
|
401
|
const int16_t et = info.target_temperature[e];
|
359
|
402
|
if (et) {
|
360
|
403
|
#if HAS_MULTI_HOTEND
|
361
|
|
- sprintf_P(cmd, PSTR("T%i"), e);
|
|
404
|
+ sprintf_P(cmd, PSTR("T%i S"), e);
|
362
|
405
|
gcode.process_subcommands_now(cmd);
|
363
|
406
|
#endif
|
364
|
407
|
sprintf_P(cmd, PSTR("M109 S%i"), et);
|
|
@@ -367,6 +410,12 @@ void PrintJobRecovery::resume() {
|
367
|
410
|
}
|
368
|
411
|
#endif
|
369
|
412
|
|
|
413
|
+ // Select the previously active tool (with no_move)
|
|
414
|
+ #if EXTRUDERS > 1
|
|
415
|
+ sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
|
|
416
|
+ gcode.process_subcommands_now(cmd);
|
|
417
|
+ #endif
|
|
418
|
+
|
370
|
419
|
// Restore print cooling fan speeds
|
371
|
420
|
FANS_LOOP(i) {
|
372
|
421
|
uint8_t f = info.fan_speed[i];
|
|
@@ -400,18 +449,21 @@ void PrintJobRecovery::resume() {
|
400
|
449
|
memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient));
|
401
|
450
|
#endif
|
402
|
451
|
|
403
|
|
- // Extrude and retract to clean the nozzle
|
404
|
|
- #if POWER_LOSS_PURGE_LEN
|
405
|
|
- //sprintf_P(cmd, PSTR("G1 E%d F200"), POWER_LOSS_PURGE_LEN);
|
406
|
|
- //gcode.process_subcommands_now(cmd);
|
407
|
|
- gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_PURGE_LEN) " F200"));
|
|
452
|
+ // Un-retract if there was a retract at outage
|
|
453
|
+ #if POWER_LOSS_RETRACT_LEN
|
|
454
|
+ gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_RETRACT_LEN) " F3000"));
|
408
|
455
|
#endif
|
409
|
456
|
|
410
|
|
- #if POWER_LOSS_RETRACT_LEN
|
411
|
|
- sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN - (POWER_LOSS_RETRACT_LEN));
|
|
457
|
+ // Additional purge if configured
|
|
458
|
+ #if POWER_LOSS_PURGE_LEN
|
|
459
|
+ sprintf_P(cmd, PSTR("G1 E%d F200"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
|
412
|
460
|
gcode.process_subcommands_now(cmd);
|
413
|
461
|
#endif
|
414
|
462
|
|
|
463
|
+ #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
464
|
+ gcode.process_subcommands_now_P(PSTR("G12"));
|
|
465
|
+ #endif
|
|
466
|
+
|
415
|
467
|
// Move back to the saved XY
|
416
|
468
|
sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"),
|
417
|
469
|
dtostrf(info.current_position.x, 1, 3, str_1),
|
|
@@ -429,13 +481,6 @@ void PrintJobRecovery::resume() {
|
429
|
481
|
#endif
|
430
|
482
|
gcode.process_subcommands_now(cmd);
|
431
|
483
|
|
432
|
|
- // Un-retract
|
433
|
|
- #if POWER_LOSS_PURGE_LEN
|
434
|
|
- //sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN);
|
435
|
|
- //gcode.process_subcommands_now(cmd);
|
436
|
|
- gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_PURGE_LEN) " F3000"));
|
437
|
|
- #endif
|
438
|
|
-
|
439
|
484
|
// Restore the feedrate
|
440
|
485
|
sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate);
|
441
|
486
|
gcode.process_subcommands_now(cmd);
|
|
@@ -476,6 +521,8 @@ void PrintJobRecovery::resume() {
|
476
|
521
|
}
|
477
|
522
|
DEBUG_EOL();
|
478
|
523
|
|
|
524
|
+ DEBUG_ECHOLNPAIR("zraise: ", info.zraise);
|
|
525
|
+
|
479
|
526
|
#if HAS_HOME_OFFSET
|
480
|
527
|
DEBUG_ECHOPGM("home_offset: ");
|
481
|
528
|
LOOP_XYZ(i) {
|