Skip to content

Commit 3b7aadb

Browse files
authored
🚸 Restore Object Cancel info on Power-Loss Recovery (#27501)
* 🎨 Shorten feature includes * 🚸 Save Canceled Objects with Power Loss data
1 parent 9e8d561 commit 3b7aadb

File tree

19 files changed

+73
-49
lines changed

19 files changed

+73
-49
lines changed

Marlin/src/feature/cancel_object.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,53 +30,50 @@
3030

3131
CancelObject cancelable;
3232

33-
int8_t CancelObject::object_count, // = 0
34-
CancelObject::active_object = -1;
35-
uint32_t CancelObject::canceled; // = 0x0000
36-
bool CancelObject::skipping; // = false
33+
cancel_state_t CancelObject::state;
3734

3835
void CancelObject::set_active_object(const int8_t obj) {
39-
active_object = obj;
36+
state.active_object = obj;
4037
if (WITHIN(obj, 0, 31)) {
41-
if (obj >= object_count) object_count = obj + 1;
42-
skipping = TEST(canceled, obj);
38+
if (obj >= state.object_count) state.object_count = obj + 1;
39+
state.skipping = TEST(state.canceled, obj);
4340
}
4441
else
45-
skipping = false;
42+
state.skipping = false;
4643

4744
#if ALL(HAS_STATUS_MESSAGE, CANCEL_OBJECTS_REPORTING)
48-
if (active_object >= 0)
49-
ui.set_status(MString<30>(GET_TEXT_F(MSG_PRINTING_OBJECT), ' ', active_object));
45+
if (state.active_object >= 0)
46+
ui.set_status(MString<30>(GET_TEXT_F(MSG_PRINTING_OBJECT), ' ', state.active_object));
5047
else
5148
ui.reset_status();
5249
#endif
5350
}
5451

5552
void CancelObject::cancel_object(const int8_t obj) {
5653
if (WITHIN(obj, 0, 31)) {
57-
SBI(canceled, obj);
58-
if (obj == active_object) skipping = true;
54+
SBI(state.canceled, obj);
55+
if (obj == state.active_object) state.skipping = true;
5956
}
6057
}
6158

6259
void CancelObject::uncancel_object(const int8_t obj) {
6360
if (WITHIN(obj, 0, 31)) {
64-
CBI(canceled, obj);
65-
if (obj == active_object) skipping = false;
61+
CBI(state.canceled, obj);
62+
if (obj == state.active_object) state.skipping = false;
6663
}
6764
}
6865

6966
void CancelObject::report() {
70-
if (active_object >= 0)
71-
SERIAL_ECHO_MSG("Active Object: ", active_object);
67+
if (state.active_object >= 0)
68+
SERIAL_ECHO_MSG("Active Object: ", state.active_object);
7269

73-
if (canceled) {
74-
SERIAL_ECHO_START();
75-
SERIAL_ECHOPGM("Canceled:");
76-
for (int i = 0; i < object_count; i++)
77-
if (TEST(canceled, i)) { SERIAL_CHAR(' '); SERIAL_ECHO(i); }
78-
SERIAL_EOL();
79-
}
70+
if (state.canceled == 0x0000) return;
71+
72+
SERIAL_ECHO_START();
73+
SERIAL_ECHOPGM("Canceled:");
74+
for (int i = 0; i < state.object_count; i++)
75+
if (TEST(state.canceled, i)) { SERIAL_CHAR(' '); SERIAL_ECHO(i); }
76+
SERIAL_EOL();
8077
}
8178

8279
#endif // CANCEL_OBJECTS

Marlin/src/feature/cancel_object.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@
2323

2424
#include <stdint.h>
2525

26+
typedef struct CancelState {
27+
bool skipping = false;
28+
int8_t object_count = 0, active_object = 0;
29+
uint32_t canceled = 0x0000;
30+
} cancel_state_t;
31+
2632
class CancelObject {
2733
public:
28-
static bool skipping;
29-
static int8_t object_count, active_object;
30-
static uint32_t canceled;
31-
static void set_active_object(const int8_t obj);
34+
static cancel_state_t state;
35+
static void set_active_object(const int8_t obj=state.active_object);
3236
static void cancel_object(const int8_t obj);
3337
static void uncancel_object(const int8_t obj);
3438
static void report();
35-
static bool is_canceled(const int8_t obj) { return TEST(canceled, obj); }
39+
static bool is_canceled(const int8_t obj) { return TEST(state.canceled, obj); }
3640
static void clear_active_object() { set_active_object(-1); }
37-
static void cancel_active_object() { cancel_object(active_object); }
38-
static void reset() { canceled = 0x0000; object_count = 0; clear_active_object(); }
41+
static void cancel_active_object() { cancel_object(state.active_object); }
42+
static void reset() { state.canceled = 0x0000; state.object_count = 0; clear_active_object(); }
3943
};
4044

4145
extern CancelObject cancelable;

Marlin/src/feature/encoder_i2c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "../module/stepper.h"
3737
#include "../gcode/parser.h"
3838

39-
#include "../feature/babystep.h"
39+
#include "babystep.h"
4040

4141
#include <Wire.h>
4242

Marlin/src/feature/leds/leds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "leds.h"
3232

3333
#if ANY(CASE_LIGHT_USE_RGB_LED, CASE_LIGHT_USE_NEOPIXEL)
34-
#include "../../feature/caselight.h"
34+
#include "../caselight.h"
3535
#endif
3636

3737
#if ENABLED(LED_COLOR_PRESETS)

Marlin/src/feature/mmu/mmu2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ MMU2 mmu2;
4343
#include "../../MarlinCore.h"
4444

4545
#if ENABLED(HOST_PROMPT_SUPPORT)
46-
#include "../../feature/host_actions.h"
46+
#include "../host_actions.h"
4747
#endif
4848

4949
#if ENABLED(EXTENSIBLE_UI)

Marlin/src/feature/mmu3/mmu3_fsensor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#if HAS_PRUSA_MMU3
3030

31-
#include "../../feature/runout.h"
31+
#include "../runout.h"
3232
#include "mmu3_fsensor.h"
3333

3434
namespace MMU3 {

Marlin/src/feature/mmu3/mmu3_marlin1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "../../module/planner.h"
3535
#include "../../module/temperature.h"
3636

37-
#include "../../feature/pause.h"
37+
#include "../pause.h"
3838
#include "../../libs/nozzle.h"
3939
#include "mmu3_marlin.h"
4040

Marlin/src/feature/mmu3/mmu3_reporting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#include "../../core/language.h"
4545
#include "../../gcode/gcode.h"
46-
#include "../../feature/host_actions.h"
46+
#include "../host_actions.h"
4747
#include "../../lcd/marlinui.h"
4848
#include "../../lcd/menu/menu.h"
4949
#include "../../lcd/menu/menu_item.h"

Marlin/src/feature/powerloss.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
215215
info.zraise = zraise;
216216
info.flag.raised = raised; // Was Z raised before power-off?
217217

218+
TERN_(CANCEL_OBJECTS, info.cancel_state = cancelable.state);
218219
TERN_(GCODE_REPEAT_MARKERS, info.stored_repeat = repeat);
219220
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
220221
TERN_(HAS_WORKSPACE_OFFSET, info.workspace_offset = workspace_offset);
@@ -575,6 +576,11 @@ void PrintJobRecovery::resume() {
575576
// Restore E position with G92.9
576577
PROCESS_SUBCOMMANDS_NOW(TS(F("G92.9E"), p_float_t(resume_pos.e, 3)));
577578

579+
#if ENABLED(CANCEL_OBJECTS)
580+
cancelable.state = info.cancel_state;
581+
cancelable.set_active_object(); // Sets the status message
582+
#endif
583+
578584
TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat);
579585
TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
580586
TERN_(HAS_WORKSPACE_OFFSET, workspace_offset = info.workspace_offset);
@@ -613,6 +619,14 @@ void PrintJobRecovery::resume() {
613619

614620
DEBUG_ECHOLNPGM("zraise: ", info.zraise, " ", info.flag.raised ? "(before)" : "");
615621

622+
#if ENABLED(CANCEL_OBJECTS)
623+
const cancel_state_t cs = info.cancel_state;
624+
DEBUG_ECHOPGM("Canceled:");
625+
for (int i = 0; i < cs.object_count; i++)
626+
if (TEST(cs.canceled, i)) { DEBUG_CHAR(' '); DEBUG_ECHO(i); }
627+
DEBUG_EOL();
628+
#endif
629+
616630
#if ENABLED(GCODE_REPEAT_MARKERS)
617631
const uint8_t ind = info.stored_repeat.count();
618632
DEBUG_ECHOLNPGM("repeat markers: ", ind);

Marlin/src/feature/powerloss.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@
3030

3131
#include "../inc/MarlinConfig.h"
3232

33+
#if ENABLED(CANCEL_OBJECTS)
34+
#include "cancel_object.h"
35+
#endif
36+
3337
#if ENABLED(GCODE_REPEAT_MARKERS)
34-
#include "../feature/repeat.h"
38+
#include "repeat.h"
3539
#endif
3640

3741
#if ENABLED(MIXING_EXTRUDER)
38-
#include "../feature/mixing.h"
42+
#include "mixing.h"
3943
#endif
4044

4145
#if !defined(POWER_LOSS_STATE) && PIN_EXISTS(POWER_LOSS)
@@ -64,6 +68,11 @@ typedef struct {
6468

6569
float zraise;
6670

71+
// Canceled objects
72+
#if ENABLED(CANCEL_OBJECTS)
73+
cancel_state_t cancel_state;
74+
#endif
75+
6776
// Repeat information
6877
#if ENABLED(GCODE_REPEAT_MARKERS)
6978
Repeat stored_repeat;

0 commit comments

Comments
 (0)