|
|
|
@ -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'");
|
|
|
|
|
|
|
|
|
@ -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)
|
|
|
|
@ -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;
|
|
|
|
@ -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"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -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);
|
|
|
|
|
|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -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) {
|
|
|
|
|
|
|
|
|
@ -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);
|
|
|
|
@ -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);
|
|
|
|
|
|
|
|
|
@ -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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -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);
|
|
|
|
@ -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();
|
|
|
|
|