Skip to content

Commit

Permalink
🚸 Save Canceled Objects with Power Loss data
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 28, 2024
1 parent dacae90 commit 13cd5ee
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 34 deletions.
43 changes: 20 additions & 23 deletions Marlin/src/feature/cancel_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,50 @@

CancelObject cancelable;

int8_t CancelObject::object_count, // = 0
CancelObject::active_object = -1;
uint32_t CancelObject::canceled; // = 0x0000
bool CancelObject::skipping; // = false
cancel_state_t CancelObject::state;

void CancelObject::set_active_object(const int8_t obj) {
active_object = obj;
state.active_object = obj;
if (WITHIN(obj, 0, 31)) {
if (obj >= object_count) object_count = obj + 1;
skipping = TEST(canceled, obj);
if (obj >= state.object_count) state.object_count = obj + 1;
state.skipping = TEST(state.canceled, obj);
}
else
skipping = false;
state.skipping = false;

#if ALL(HAS_STATUS_MESSAGE, CANCEL_OBJECTS_REPORTING)
if (active_object >= 0)
ui.set_status(MString<30>(GET_TEXT_F(MSG_PRINTING_OBJECT), ' ', active_object));
if (state.active_object >= 0)
ui.set_status(MString<30>(GET_TEXT_F(MSG_PRINTING_OBJECT), ' ', state.active_object));
else
ui.reset_status();
#endif
}

void CancelObject::cancel_object(const int8_t obj) {
if (WITHIN(obj, 0, 31)) {
SBI(canceled, obj);
if (obj == active_object) skipping = true;
SBI(state.canceled, obj);
if (obj == state.active_object) state.skipping = true;
}
}

void CancelObject::uncancel_object(const int8_t obj) {
if (WITHIN(obj, 0, 31)) {
CBI(canceled, obj);
if (obj == active_object) skipping = false;
CBI(state.canceled, obj);
if (obj == state.active_object) state.skipping = false;
}
}

void CancelObject::report() {
if (active_object >= 0)
SERIAL_ECHO_MSG("Active Object: ", active_object);
if (state.active_object >= 0)
SERIAL_ECHO_MSG("Active Object: ", state.active_object);

if (canceled) {
SERIAL_ECHO_START();
SERIAL_ECHOPGM("Canceled:");
for (int i = 0; i < object_count; i++)
if (TEST(canceled, i)) { SERIAL_CHAR(' '); SERIAL_ECHO(i); }
SERIAL_EOL();
}
if (state.canceled == 0x0000) return;

SERIAL_ECHO_START();
SERIAL_ECHOPGM("Canceled:");
for (int i = 0; i < state.object_count; i++)
if (TEST(state.canceled, i)) { SERIAL_CHAR(' '); SERIAL_ECHO(i); }
SERIAL_EOL();
}

#endif // CANCEL_OBJECTS
18 changes: 11 additions & 7 deletions Marlin/src/feature/cancel_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@

#include <stdint.h>

typedef struct CancelState {
bool skipping = false;
int8_t object_count = 0, active_object = 0;
uint32_t canceled = 0x0000;
} cancel_state_t;

class CancelObject {
public:
static bool skipping;
static int8_t object_count, active_object;
static uint32_t canceled;
static void set_active_object(const int8_t obj);
static cancel_state_t state;
static void set_active_object(const int8_t obj=state.active_object);
static void cancel_object(const int8_t obj);
static void uncancel_object(const int8_t obj);
static void report();
static bool is_canceled(const int8_t obj) { return TEST(canceled, obj); }
static bool is_canceled(const int8_t obj) { return TEST(state.canceled, obj); }
static void clear_active_object() { set_active_object(-1); }
static void cancel_active_object() { cancel_object(active_object); }
static void reset() { canceled = 0x0000; object_count = 0; clear_active_object(); }
static void cancel_active_object() { cancel_object(state.active_object); }
static void reset() { state.canceled = 0x0000; state.object_count = 0; clear_active_object(); }
};

extern CancelObject cancelable;
14 changes: 14 additions & 0 deletions Marlin/src/feature/powerloss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
info.zraise = zraise;
info.flag.raised = raised; // Was Z raised before power-off?

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

#if ENABLED(CANCEL_OBJECTS)
cancelable.state = info.cancel_state;
cancelable.set_active_object(); // Sets the status message
#endif

TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat);
TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
TERN_(HAS_WORKSPACE_OFFSET, workspace_offset = info.workspace_offset);
Expand Down Expand Up @@ -613,6 +619,14 @@ void PrintJobRecovery::resume() {

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

#if ENABLED(CANCEL_OBJECTS)
const cancel_state_t cs = info.cancel_state;
DEBUG_ECHOPGM("Canceled:");
for (int i = 0; i < cs.object_count; i++)
if (TEST(cs.canceled, i)) { DEBUG_CHAR(' '); DEBUG_ECHO(i); }
DEBUG_EOL();
#endif

#if ENABLED(GCODE_REPEAT_MARKERS)
const uint8_t ind = info.stored_repeat.count();
DEBUG_ECHOLNPGM("repeat markers: ", ind);
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/feature/powerloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "repeat.h"
#endif

#if ENABLED(CANCEL_OBJECTS)
#include "cancel_object.h"
#endif

#if ENABLED(MIXING_EXTRUDER)
#include "mixing.h"
#endif
Expand Down Expand Up @@ -69,6 +73,11 @@ typedef struct {
Repeat stored_repeat;
#endif

// Canceled objects
#if ENABLED(CANCEL_OBJECTS)
cancel_state_t cancel_state;
#endif

#if HAS_HOME_OFFSET
xyz_pos_t home_offset;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void GcodeSuite::get_destination_from_command() {
xyze_bool_t seen{false};

#if ENABLED(CANCEL_OBJECTS)
const bool &skip_move = cancelable.skipping;
const bool &skip_move = cancelable.state.skipping;
#else
constexpr bool skip_move = false;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2867,7 +2867,7 @@ bool Planner::buffer_segment(const abce_pos_t &abce

#if HAS_EXTRUDERS
// DRYRUN prevents E moves from taking place
if (DEBUGGING(DRYRUN) || TERN0(CANCEL_OBJECTS, cancelable.skipping)) {
if (DEBUGGING(DRYRUN) || TERN0(CANCEL_OBJECTS, cancelable.state.skipping)) {
position.e = target.e;
TERN_(HAS_POSITION_FLOAT, position_float.e = abce.e);
}
Expand Down
4 changes: 2 additions & 2 deletions buildroot/tests/DUE
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN,
#
restore_configs
opt_set MOTHERBOARD BOARD_RAMPS4DUE_EEF LCD_LANGUAGE fi EXTRUDERS 2 TEMP_SENSOR_BED 0 NUM_SERVOS 1
opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER BEEP_ON_FEEDRATE_CHANGE POWER_LOSS_RECOVERY
exec_test $1 $2 "RAMPS4DUE_EEF with SWITCHING_EXTRUDER, POWER_LOSS_RECOVERY" "$3"
opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER BEEP_ON_FEEDRATE_CHANGE CANCEL_OBJECTS POWER_LOSS_RECOVERY
exec_test $1 $2 "RAMPS4DUE_EEF with SWITCHING_EXTRUDER, CANCEL_OBJECTS, POWER_LOSS_RECOVERY" "$3"

0 comments on commit 13cd5ee

Please sign in to comment.