From 68e50a725a1464577a1b387822462fe67075d40a Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Sat, 27 Feb 2021 20:23:00 +0100 Subject: [PATCH] [SMUFF] Use EXTRUDERS for extended commands (#21212) --- Marlin/src/feature/mmu/mmu2.cpp | 32 +++++--------------- Marlin/src/gcode/feature/prusa_MMU2/M403.cpp | 2 +- Marlin/src/inc/Conditionals_LCD.h | 2 +- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index 7c3ab05851..a1bec36e45 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -62,29 +62,13 @@ MMU2 mmu2; #endif #define MMU_CMD_NONE 0 -#define MMU_CMD_T0 0x10 -#define MMU_CMD_T1 0x11 -#define MMU_CMD_T2 0x12 -#define MMU_CMD_T3 0x13 -#define MMU_CMD_T4 0x14 -#define MMU_CMD_L0 0x20 -#define MMU_CMD_L1 0x21 -#define MMU_CMD_L2 0x22 -#define MMU_CMD_L3 0x23 -#define MMU_CMD_L4 0x24 +#define MMU_CMD_T0 0x10 // up to supported filaments +#define MMU_CMD_L0 0x20 // up to supported filaments #define MMU_CMD_C0 0x30 #define MMU_CMD_U0 0x40 -#define MMU_CMD_E0 0x50 -#define MMU_CMD_E1 0x51 -#define MMU_CMD_E2 0x52 -#define MMU_CMD_E3 0x53 -#define MMU_CMD_E4 0x54 +#define MMU_CMD_E0 0x50 // up to supported filaments #define MMU_CMD_R0 0x60 -#define MMU_CMD_F0 0x70 -#define MMU_CMD_F1 0x71 -#define MMU_CMD_F2 0x72 -#define MMU_CMD_F3 0x73 -#define MMU_CMD_F4 0x74 +#define MMU_CMD_F0 0x70 // up to supported filaments #define MMU_REQUIRED_FW_BUILDNR TERN(MMU2_MODE_12V, 132, 126) @@ -243,7 +227,7 @@ void MMU2::mmu_loop() { case 1: if (cmd) { - if (WITHIN(cmd, MMU_CMD_T0, MMU_CMD_T4)) { + if (WITHIN(cmd, MMU_CMD_T0, MMU_CMD_T0 + EXTRUDERS - 1)) { // tool change int filament = cmd - MMU_CMD_T0; DEBUG_ECHOLNPAIR("MMU <= T", filament); @@ -251,7 +235,7 @@ void MMU2::mmu_loop() { TERN_(MMU_EXTRUDER_SENSOR, mmu_idl_sens = 1); // enable idler sensor, if any state = 3; // wait for response } - else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L4)) { + else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L0 + EXTRUDERS - 1)) { // load int filament = cmd - MMU_CMD_L0; DEBUG_ECHOLNPAIR("MMU <= L", filament); @@ -271,7 +255,7 @@ void MMU2::mmu_loop() { MMU2_COMMAND("U0"); state = 3; // wait for response } - else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) { + else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E0 + EXTRUDERS - 1)) { // eject filament int filament = cmd - MMU_CMD_E0; DEBUG_ECHOLNPAIR("MMU <= E", filament); @@ -284,7 +268,7 @@ void MMU2::mmu_loop() { MMU2_COMMAND("R0"); state = 3; // wait for response } - else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) { + else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F0 + EXTRUDERS - 1)) { // filament type int filament = cmd - MMU_CMD_F0; DEBUG_ECHOLNPAIR("MMU <= F", filament, " ", cmd_arg); diff --git a/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp b/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp index 31d076337a..bca2013e88 100644 --- a/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp +++ b/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp @@ -40,7 +40,7 @@ void GcodeSuite::M403() { int8_t index = parser.intval('E', -1), type = parser.intval('F', -1); - if (WITHIN(index, 0, 4) && WITHIN(type, 0, 2)) + if (WITHIN(index, 0, EXTRUDERS - 1) && WITHIN(type, 0, 2)) mmu2.set_filament_type(index, type); else SERIAL_ECHO_MSG("M403 - bad arguments."); diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index cff1424eb3..3e20bb90c0 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -513,7 +513,7 @@ #define HAS_PRUSA_MMU2 1 #define HAS_PRUSA_MMU2S 1 #endif - #if MMU_MODEL >= SMUFF_EMU_MMU2 + #if MMU_MODEL == SMUFF_EMU_MMU2 || MMU_MODEL == SMUFF_EMU_MMU2S #define HAS_SMUFF 1 #endif #endif