Skip to content

Commit bc66c69

Browse files
committed
🚸 Save Canceled Objects with Power Loss data
1 parent dacae90 commit bc66c69

File tree

9 files changed

+61
-37
lines changed

9 files changed

+61
-37
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/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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
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)
3438
#include "repeat.h"
3539
#endif
@@ -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;

Marlin/src/gcode/feature/cancel/M486.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void GcodeSuite::M486() {
4141

4242
if (parser.seen('T')) {
4343
cancelable.reset();
44-
cancelable.object_count = parser.intval('T', 1);
44+
cancelable.state.object_count = parser.intval('T', 1);
4545
}
4646

4747
if (parser.seenval('S'))

Marlin/src/gcode/gcode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void GcodeSuite::get_destination_from_command() {
165165
xyze_bool_t seen{false};
166166

167167
#if ENABLED(CANCEL_OBJECTS)
168-
const bool &skip_move = cancelable.skipping;
168+
const bool &skip_move = cancelable.state.skipping;
169169
#else
170170
constexpr bool skip_move = false;
171171
#endif

Marlin/src/lcd/menu/menu_cancelobject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ static void lcd_cancel_object_confirm() {
5353
}
5454

5555
void menu_cancelobject() {
56-
const int8_t ao = cancelable.active_object;
56+
const int8_t ao = cancelable.state.active_object;
5757

5858
START_MENU();
5959
BACK_ITEM(MSG_MAIN_MENU);
6060

6161
// Draw cancelable items in a loop
62-
for (int8_t i = -1; i < cancelable.object_count; i++) {
62+
for (int8_t i = -1; i < cancelable.state.object_count; i++) {
6363
if (i == ao) continue; // Active is drawn on -1 index
6464
const int8_t j = i < 0 ? ao : i; // Active or index item
6565
if (!cancelable.is_canceled(j)) { // Not canceled already?

Marlin/src/module/planner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,7 @@ bool Planner::buffer_segment(const abce_pos_t &abce
28672867

28682868
#if HAS_EXTRUDERS
28692869
// DRYRUN prevents E moves from taking place
2870-
if (DEBUGGING(DRYRUN) || TERN0(CANCEL_OBJECTS, cancelable.skipping)) {
2870+
if (DEBUGGING(DRYRUN) || TERN0(CANCEL_OBJECTS, cancelable.state.skipping)) {
28712871
position.e = target.e;
28722872
TERN_(HAS_POSITION_FLOAT, position_float.e = abce.e);
28732873
}

buildroot/tests/DUE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN,
4848
#
4949
restore_configs
5050
opt_set MOTHERBOARD BOARD_RAMPS4DUE_EEF LCD_LANGUAGE fi EXTRUDERS 2 TEMP_SENSOR_BED 0 NUM_SERVOS 1
51-
opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER BEEP_ON_FEEDRATE_CHANGE POWER_LOSS_RECOVERY
52-
exec_test $1 $2 "RAMPS4DUE_EEF with SWITCHING_EXTRUDER, POWER_LOSS_RECOVERY" "$3"
51+
opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER BEEP_ON_FEEDRATE_CHANGE CANCEL_OBJECTS POWER_LOSS_RECOVERY
52+
exec_test $1 $2 "RAMPS4DUE_EEF with SWITCHING_EXTRUDER, CANCEL_OBJECTS, POWER_LOSS_RECOVERY" "$3"

0 commit comments

Comments
 (0)