ソースを参照

PFW-1397 Implement new function increment_tool_change_counter()

Reduces flash consumption by 44 bytes
Guðni Már Gilbert 2 年 前
コミット
3120bf0aa2
2 ファイル変更12 行追加11 行削除
  1. 9 11
      Firmware/mmu2.cpp
  2. 3 0
      Firmware/mmu2.h

+ 9 - 11
Firmware/mmu2.cpp

@@ -301,6 +301,12 @@ void MMU2::DecrementRetryAttempts(){
     }
     }
 }
 }
 
 
+void MMU2::increment_tool_change_counter()
+{
+    uint32_t toolchanges = eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT);
+    eeprom_write_dword((uint32_t *)EEPROM_TOTAL_TOOLCHANGE_COUNT, ++toolchanges);
+}
+
 bool MMU2::tool_change(uint8_t index) {
 bool MMU2::tool_change(uint8_t index) {
     if( ! WaitForMMUReady())
     if( ! WaitForMMUReady())
         return false;
         return false;
@@ -331,10 +337,7 @@ bool MMU2::tool_change(uint8_t index) {
         // @@TODO really report onto the serial? May be for the Octoprint? Not important now
         // @@TODO really report onto the serial? May be for the Octoprint? Not important now
         //        SERIAL_ECHO_START();
         //        SERIAL_ECHO_START();
         //        SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(extruder));
         //        SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(extruder));
-        
+        increment_tool_change_counter();
-        // Update toolchange counter
-        uint32_t toolchanges = eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT);
-        eeprom_write_dword((uint32_t *)EEPROM_TOTAL_TOOLCHANGE_COUNT, ++toolchanges);
     }
     }
     return true;
     return true;
 }
 }
@@ -365,9 +368,7 @@ bool MMU2::tool_change(char code, uint8_t slot) {
         extruder = slot;
         extruder = slot;
         SpoolJoin::spooljoin.setSlot(slot);
         SpoolJoin::spooljoin.setSlot(slot);
         set_extrude_min_temp(EXTRUDE_MINTEMP);
         set_extrude_min_temp(EXTRUDE_MINTEMP);
-        // Update toolchange counter
+        increment_tool_change_counter();
-        uint32_t toolchanges = eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT);
-        eeprom_write_dword((uint32_t *)EEPROM_TOTAL_TOOLCHANGE_COUNT, ++toolchanges);
     } break;
     } break;
 
 
     case 'c': {
     case 'c': {
@@ -518,10 +519,7 @@ bool MMU2::load_filament_to_nozzle(uint8_t index) {
         SpoolJoin::spooljoin.setSlot(index);
         SpoolJoin::spooljoin.setSlot(index);
 
 
         Sound_MakeSound(e_SOUND_TYPE_StandardConfirm);
         Sound_MakeSound(e_SOUND_TYPE_StandardConfirm);
-
+        increment_tool_change_counter();
-        // Update toolchange count
-        uint32_t toolchanges = eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT);
-        eeprom_write_dword((uint32_t *)EEPROM_TOTAL_TOOLCHANGE_COUNT, ++toolchanges);
     }
     }
     lcd_update_enable(true);
     lcd_update_enable(true);
     return true;
     return true;

+ 3 - 0
Firmware/mmu2.h

@@ -194,6 +194,9 @@ public:
     void DecrementRetryAttempts();
     void DecrementRetryAttempts();
 
 
 private:
 private:
+    /// increments tool change counter in EEPROM
+    void increment_tool_change_counter();
+
     /// Reset the retryAttempts back to the default value
     /// Reset the retryAttempts back to the default value
     void ResetRetryAttempts();
     void ResetRetryAttempts();
     /// Perform software self-reset of the MMU (sends an X0 command)
     /// Perform software self-reset of the MMU (sends an X0 command)