Skip to content

Commit

Permalink
MMU2 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 30, 2022
1 parent 6542f61 commit 78b94b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
30 changes: 13 additions & 17 deletions Marlin/src/feature/mmu/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ struct E_Step {
feedRate_t feedRate; //!< feed rate in mm/s
};

static constexpr E_Step
ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE }
, load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE }
#if HAS_PRUSA_MMU2S
, can_load_sequence[] PROGMEM = { MMU2_CAN_LOAD_SEQUENCE }
, can_load_increment_sequence[] PROGMEM = { MMU2_CAN_LOAD_INCREMENT_SEQUENCE }
#endif
;

MMU2::MMU2() {
rx_buffer[0] = '\0';
}
Expand Down Expand Up @@ -645,7 +636,7 @@ static void mmu2_not_responding() {
case 'c': {
DEBUG_ECHOLNPGM("case c\n");
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
load_to_nozzle();
} break;
}

Expand Down Expand Up @@ -738,7 +729,7 @@ static void mmu2_not_responding() {
case 'c': {
DEBUG_ECHOLNPGM("case c\n");
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
load_to_nozzle();
} break;
}

Expand Down Expand Up @@ -875,13 +866,16 @@ void MMU2::filament_runout() {
}

bool MMU2::can_load() {
execute_extruder_sequence((const E_Step *)can_load_sequence, COUNT(can_load_sequence));
static constexpr E_Step can_load_sequence[] PROGMEM = { MMU2_CAN_LOAD_SEQUENCE },
can_load_increment_sequence[] PROGMEM = { MMU2_CAN_LOAD_INCREMENT_SEQUENCE };

execute_extruder_sequence(can_load_sequence, COUNT(can_load_sequence));

int filament_detected_count = 0;
const int steps = (MMU2_CAN_LOAD_RETRACT) / (MMU2_CAN_LOAD_INCREMENT);
DEBUG_ECHOLNPGM("MMU can_load:");
LOOP_L_N(i, steps) {
execute_extruder_sequence((const E_Step *)can_load_increment_sequence, COUNT(can_load_increment_sequence));
execute_extruder_sequence(can_load_increment_sequence, COUNT(can_load_increment_sequence));
check_filament(); // Don't trust the idle function
DEBUG_CHAR(mmu2s_triggered ? 'O' : 'o');
if (mmu2s_triggered) ++filament_detected_count;
Expand Down Expand Up @@ -943,7 +937,8 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
* filament to nozzle.
*/
void MMU2::load_to_nozzle() {
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
static constexpr E_Step load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE };
execute_extruder_sequence(load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
}

bool MMU2::eject_filament(const uint8_t index, const bool recover) {
Expand Down Expand Up @@ -1005,7 +1000,8 @@ bool MMU2::unload() {
}

// Unload sequence to optimize shape of the tip of the unloaded filament
execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step));
static constexpr E_Step ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE };
execute_extruder_sequence(ramming_sequence, COUNT(ramming_sequence));

command(MMU_CMD_U0);
manage_response(false, true);
Expand All @@ -1020,12 +1016,12 @@ bool MMU2::unload() {
return true;
}

void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
void MMU2::execute_extruder_sequence(const E_Step * const sequence, const uint8_t steps) {

planner.synchronize();
stepper.enable_extruder();

const E_Step* step = sequence;
const E_Step *step = sequence;

LOOP_L_N(i, steps) {
const float es = pgm_read_float(&(step->extrude));
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/mmu/mmu2.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MMU2 {
static void manage_response(const bool move_axes, const bool turn_off_nozzle);

static void load_to_nozzle();
static void execute_extruder_sequence(const E_Step * sequence, int steps);
static void execute_extruder_sequence(const E_Step * const sequence, const uint8_t steps);

static void filament_runout();

Expand Down

0 comments on commit 78b94b8

Please sign in to comment.