Parcourir la source

PFW-1386 Create a common function for M704 to M706

Saves 36 bytes of flash
Guðni Már Gilbert il y a 2 ans
Parent
commit
8462b38446
1 fichiers modifiés avec 30 ajouts et 25 suppressions
  1. 30 25
      Firmware/Marlin_main.cpp

+ 30 - 25
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;