From 8462b38446e5b59553c4a8274966156eab3b3a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 27 Aug 2022 10:28:25 +0000 Subject: [PATCH] PFW-1386 Create a common function for M704 to M706 Saves 36 bytes of flash --- Firmware/Marlin_main.cpp | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index fc1a74df4..3c03d6023 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3711,6 +3711,33 @@ void gcode_M701(uint8_t mmuSlotIndex){ eFilamentAction = FilamentAction::None; } + +// Common gcode shared by the gcodes. This saves some flash memory +static void gcodes_M704_M705_M706(uint16_t gcode) +{ + uint8_t mmuSlotIndex = 0xffU; + if (MMU2::mmu2.Enabled() && code_seen('P')) + { + mmuSlotIndex = code_value_uint8(); + if (mmuSlotIndex < MMU_FILAMENT_COUNT) { + switch (gcode) + { + case 704: + MMU2::mmu2.load_filament(mmuSlotIndex); + break; + case 705: + MMU2::mmu2.eject_filament(mmuSlotIndex, false); + break; + case 706: + MMU2::mmu2.cut_filament(mmuSlotIndex); + break; + default: + break; + } + } + } +} + /** * @brief Get serial number from 32U2 processor * @@ -8625,14 +8652,7 @@ Sigma_Exit: */ case 704: { - uint8_t mmuSlotIndex = 0xffU; - if (MMU2::mmu2.Enabled() && code_seen('P')) - { - mmuSlotIndex = code_value_uint8(); - if (mmuSlotIndex < MMU_FILAMENT_COUNT) { - MMU2::mmu2.load_filament(mmuSlotIndex); - } - } + gcodes_M704_M705_M706(704); } break; @@ -8647,15 +8667,7 @@ Sigma_Exit: */ case 705: { - uint8_t mmuSlotIndex = 0xffU; - if (MMU2::mmu2.Enabled() && code_seen('P')) - { - mmuSlotIndex = code_value_uint8(); - if (mmuSlotIndex < MMU_FILAMENT_COUNT) { - // TODO: should recover be false? - MMU2::mmu2.eject_filament(mmuSlotIndex, false); - } - } + gcodes_M704_M705_M706(705); } break; @@ -8671,14 +8683,7 @@ Sigma_Exit: */ case 706: { - uint8_t mmuSlotIndex = 0xffU; - if (MMU2::mmu2.Enabled() && code_seen('P')) - { - mmuSlotIndex = code_value_uint8(); - if (mmuSlotIndex < MMU_FILAMENT_COUNT) { - MMU2::mmu2.cut_filament(mmuSlotIndex); - } - } + gcodes_M704_M705_M706(706); } break;