🎨 MMU2 cleanup

This commit is contained in:
Scott Lahteine 2022-10-14 13:15:37 -05:00
parent 670a199575
commit 54a5bf5edf

View file

@ -54,7 +54,8 @@ MMU2 mmu2;
#define MMU_CMD_TIMEOUT 45000UL // 45s timeout for mmu commands (except P0)
#define MMU_P0_TIMEOUT 3000UL // Timeout for P0 command: 3seconds
#define MMU2_COMMAND(S) tx_str(F(S "\n"))
#define MMU2_SEND(S) tx_str(F(S "\n"))
#define MMU2_RECV(S) rx_str(F(S "\n"))
#if ENABLED(MMU_EXTRUDER_SENSOR)
uint8_t mmu_idl_sens = 0;
@ -131,7 +132,7 @@ void MMU2::reset() {
safe_delay(20);
WRITE(MMU2_RST_PIN, HIGH);
#else
MMU2_COMMAND("X0"); // Send soft reset
MMU2_SEND("X0"); // Send soft reset
#endif
}
@ -157,11 +158,9 @@ 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'");
MMU2_COMMAND("S1"); // Read Version
MMU2_SEND("S1"); // Read Version
state = -2;
}
else if (millis() > 30000) { // 30sec after reset disable MMU
@ -173,10 +172,8 @@ void MMU2::mmu_loop() {
case -2:
if (rx_ok()) {
sscanf(rx_buffer, "%huok\n", &version);
DEBUG_ECHOLNPGM("MMU => ", version, "\nMMU <= 'S2'");
MMU2_COMMAND("S2"); // Read Build Number
MMU2_SEND("S2"); // Read Build Number
state = -3;
}
break;
@ -191,14 +188,12 @@ void MMU2::mmu_loop() {
#if ENABLED(MMU2_MODE_12V)
DEBUG_ECHOLNPGM("MMU <= 'M1'");
MMU2_COMMAND("M1"); // Stealth Mode
MMU2_SEND("M1"); // Stealth Mode
state = -5;
#else
DEBUG_ECHOLNPGM("MMU <= 'P0'");
MMU2_COMMAND("P0"); // Read FINDA
MMU2_SEND("P0"); // Read FINDA
state = -4;
#endif
}
@ -209,10 +204,8 @@ void MMU2::mmu_loop() {
// response to M1
if (rx_ok()) {
DEBUG_ECHOLNPGM("MMU => ok");
DEBUG_ECHOLNPGM("MMU <= 'P0'");
MMU2_COMMAND("P0"); // Read FINDA
MMU2_SEND("P0"); // Read FINDA
state = -4;
}
break;
@ -250,14 +243,13 @@ void MMU2::mmu_loop() {
else if (cmd == MMU_CMD_C0) {
// continue loading
DEBUG_ECHOLNPGM("MMU <= 'C0'");
MMU2_COMMAND("C0");
MMU2_SEND("C0");
state = 3; // wait for response
}
else if (cmd == MMU_CMD_U0) {
// unload current
DEBUG_ECHOLNPGM("MMU <= 'U0'");
MMU2_COMMAND("U0");
MMU2_SEND("U0");
state = 3; // wait for response
}
else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E0 + EXTRUDERS - 1)) {
@ -270,7 +262,7 @@ void MMU2::mmu_loop() {
else if (cmd == MMU_CMD_R0) {
// recover after eject
DEBUG_ECHOLNPGM("MMU <= 'R0'");
MMU2_COMMAND("R0");
MMU2_SEND("R0");
state = 3; // wait for response
}
else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F0 + EXTRUDERS - 1)) {
@ -285,7 +277,7 @@ void MMU2::mmu_loop() {
cmd = MMU_CMD_NONE;
}
else if (ELAPSED(millis(), prev_P0_request + 300)) {
MMU2_COMMAND("P0"); // Read FINDA
MMU2_SEND("P0"); // Read FINDA
state = 2; // wait for response
}
@ -314,7 +306,7 @@ void MMU2::mmu_loop() {
if (mmu_idl_sens) {
if (FILAMENT_PRESENT() && mmu_loading_flag) {
DEBUG_ECHOLNPGM("MMU <= 'A'");
MMU2_COMMAND("A"); // send 'abort' request
MMU2_SEND("A"); // send 'abort' request
mmu_idl_sens = 0;
DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT");
}
@ -327,9 +319,9 @@ void MMU2::mmu_loop() {
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 => 'ok' (no filament in gears)");
DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
MMU2_COMMAND("C0");
MMU2_SEND("C0");
}
#else
constexpr bool keep_trying = false;
@ -361,7 +353,7 @@ void MMU2::mmu_loop() {
*/
bool MMU2::rx_start() {
// check for start message
return rx_str(F("start\n"));
return MMU2_RECV("start");
}
/**
@ -440,7 +432,7 @@ void MMU2::clear_rx_buffer() {
* Check if we received 'ok' from MMU
*/
bool MMU2::rx_ok() {
if (rx_str(F("ok\n"))) {
if (MMU2_RECV("ok")) {
prev_P0_request = millis();
return true;
}
@ -673,7 +665,7 @@ static void mmu2_not_responding() {
// When (T0 rx->ok) load is ready, but in fact it did not load
// successfully or an overload created pressure in the extruder.
// Send (C0) to load more and move E_AXIS a little to release pressure.
if ((fil_present = FILAMENT_PRESENT())) MMU2_COMMAND("A");
if ((fil_present = FILAMENT_PRESENT())) MMU2_SEND("A");
} while (!fil_present && PENDING(millis(), expire_ms));
stepper.disable_extruder();
manage_response(true, true);
@ -882,7 +874,7 @@ void MMU2::filament_runout() {
if (cmd == MMU_CMD_NONE && last_cmd == MMU_CMD_C0) {
if (present && !mmu2s_triggered) {
DEBUG_ECHOLNPGM("MMU <= 'A'");
tx_str(F("A\n"));
MMU2_SEND("A");
}
// Slowly spin the extruder during C0
else {