Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMU2 fixes #20794

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions Marlin/src/feature/mmu/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ void MMU2::mmu_loop() {

case -1:
if (rx_start()) {
prev_P0_request = millis(); // Initialize finda sensor timeout

DEBUG_ECHOLNPGM("MMU => 'start'");
DEBUG_ECHOLNPGM("MMU <= 'S1'");

Expand Down Expand Up @@ -311,7 +313,7 @@ void MMU2::mmu_loop() {
// if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);

if (!finda && finda_runout_valid) filament_runout();
if (cmd == 0) ready = true;
if (cmd == MMU_CMD_NONE) ready = true;
state = 1;
}
else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
Expand All @@ -333,18 +335,20 @@ void MMU2::mmu_loop() {
#endif

if (rx_ok()) {
// Response to C0 mmu command in MMU2S model
bool can_reset = true;
#if HAS_PRUSA_MMU2S
if (!mmu2s_triggered && last_cmd == MMU_CMD_C0) {
can_reset = false;
// Respond to C0 MMU command in MMU2S model
const bool keep_trying = !mmu2s_triggered && last_cmd == MMU_CMD_C0;
if (keep_trying) {
// MMU ok received but filament sensor not triggered, retrying...
DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
MMU2_COMMAND("C0");
}
#else
constexpr bool keep_trying = false;
#endif
if (can_reset) {

if (!keep_trying) {
DEBUG_ECHOLNPGM("MMU => 'ok'");
ready = true;
state = 1;
Expand All @@ -370,11 +374,7 @@ void MMU2::mmu_loop() {
*/
bool MMU2::rx_start() {
// check for start message
if (rx_str_P(PSTR("start\n"))) {
prev_P0_request = millis();
return true;
}
return false;
return rx_str_P(PSTR("start\n"));
}

/**
Expand All @@ -385,13 +385,13 @@ bool MMU2::rx_str_P(const char* str) {

while (MMU2_SERIAL.available()) {
rx_buffer[i++] = MMU2_SERIAL.read();
rx_buffer[i] = '\0';

if (i == sizeof(rx_buffer) - 1) {
DEBUG_ECHOLNPGM("rx buffer overrun");
break;
}
}
rx_buffer[i] = '\0';

uint8_t len = strlen_P(str);

Expand All @@ -416,7 +416,6 @@ void MMU2::tx_str_P(const char* str) {
clear_rx_buffer();
uint8_t len = strlen_P(str);
LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++));
rx_buffer[0] = '\0';
prev_request = millis();
}

Expand All @@ -427,7 +426,6 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
clear_rx_buffer();
uint8_t len = sprintf_P(tx_buffer, format, argument);
LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
rx_buffer[0] = '\0';
prev_request = millis();
}

Expand All @@ -438,7 +436,6 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
clear_rx_buffer();
uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
rx_buffer[0] = '\0';
prev_request = millis();
}

Expand Down Expand Up @@ -570,7 +567,7 @@ static void mmu2_not_responding() {

case 'c': {
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 @@ -791,7 +788,7 @@ bool MMU2::get_response() {
}

/**
* Wait for response and deal with timeout if nexcessary
* Wait for response and deal with timeout if necessary
*/
void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {

Expand Down Expand Up @@ -917,6 +914,7 @@ void MMU2::filament_runout() {
// Load filament into MMU2
void MMU2::load_filament(const uint8_t index) {
if (!enabled) return;

command(MMU_CMD_L0 + index);
manage_response(false, false);
BUZZ(200, 404);
Expand All @@ -935,6 +933,7 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
return false;
}

DISABLE_AXIS_E0();
command(MMU_CMD_T0 + index);
manage_response(true, true);

Expand All @@ -957,7 +956,6 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
* filament to nozzle.
*/
void MMU2::load_to_nozzle() {
if (!enabled) return;
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
}

Expand Down Expand Up @@ -1020,7 +1018,8 @@ bool MMU2::unload() {
return false;
}

filament_ramming();
// 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));

command(MMU_CMD_U0);
manage_response(false, true);
Expand All @@ -1035,13 +1034,6 @@ bool MMU2::unload() {
return true;
}

/**
* Unload sequence to optimize shape of the tip of the unloaded filament
*/
void MMU2::filament_ramming() {
execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step));
}

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

planner.synchronize();
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/feature/mmu/mmu2.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class MMU2 {
static void manage_response(const bool move_axes, const bool turn_off_nozzle);

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

static void filament_runout();
Expand Down
19 changes: 8 additions & 11 deletions Marlin/src/lcd/menu/menu_mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@
// Load Filament
//

void _mmu2_load_filamentToNozzle(uint8_t index) {
inline void action_mmu2_load_filament_to_nozzle(const uint8_t tool) {
ui.reset_status();
ui.return_to_status();
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
if (mmu2.load_filament_to_nozzle(index)) ui.reset_status();
}

inline void action_mmu2_load_filament_to_nozzle(const uint8_t tool) {
_mmu2_load_filamentToNozzle(tool);
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(tool + 1));
if (mmu2.load_filament_to_nozzle(tool))
ui.reset_status();
ui.return_to_status();
}

Expand All @@ -59,14 +56,14 @@ void menu_mmu2_load_filament() {
START_MENU();
BACK_ITEM(MSG_MMU2_MENU);
ACTION_ITEM(MSG_MMU2_ALL, action_mmu2_load_all);
LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); });
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); });
END_MENU();
}

void menu_mmu2_load_to_nozzle() {
START_MENU();
BACK_ITEM(MSG_MMU2_MENU);
LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); });
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); });
END_MENU();
}

Expand All @@ -92,7 +89,7 @@ void action_mmu2_unload_filament() {
void menu_mmu2_eject_filament() {
START_MENU();
BACK_ITEM(MSG_MMU2_MENU);
LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); });
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); });
END_MENU();
}

Expand Down Expand Up @@ -133,7 +130,7 @@ void menu_mmu2_choose_filament() {
#if LCD_HEIGHT > 2
STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_DEFAULT|SS_INVERT);
#endif
LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); });
LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); });
END_MENU();
}

Expand Down