瀏覽代碼

Configure / disable PRINTCOUNTER save interval (#20856)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
ConstantijnCrijnen 4 年之前
父節點
當前提交
b95f5c5bea
沒有連結到貢獻者的電子郵件帳戶。

+ 3
- 0
Marlin/Configuration.h 查看文件

1754
  * View the current statistics with M78.
1754
  * View the current statistics with M78.
1755
  */
1755
  */
1756
 //#define PRINTCOUNTER
1756
 //#define PRINTCOUNTER
1757
+#if ENABLED(PRINTCOUNTER)
1758
+  #define PRINTCOUNTER_SAVE_INTERVAL 60 // (minutes) EEPROM save interval during print
1759
+#endif
1757
 
1760
 
1758
 /**
1761
 /**
1759
  * Password
1762
  * Password

+ 7
- 0
Marlin/src/HAL/LPC1768/inc/Conditionals_post.h 查看文件

26
 #elif EITHER(I2C_EEPROM, SPI_EEPROM)
26
 #elif EITHER(I2C_EEPROM, SPI_EEPROM)
27
   #define USE_SHARED_EEPROM 1
27
   #define USE_SHARED_EEPROM 1
28
 #endif
28
 #endif
29
+
30
+// LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785)
31
+// TODO: Which other boards are incompatible?
32
+#if defined(MCU_LPC1768) && PRINTCOUNTER_SAVE_INTERVAL > 0
33
+  #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save."
34
+  #define PRINTCOUNTER_SYNC 1
35
+#endif

+ 2
- 1
Marlin/src/MarlinCore.cpp 查看文件

365
 
365
 
366
     queue.clear();
366
     queue.clear();
367
     quickstop_stepper();
367
     quickstop_stepper();
368
-    print_job_timer.stop();
368
+
369
+    print_job_timer.abort();
369
 
370
 
370
     IF_DISABLED(SD_ABORT_NO_COOLDOWN, thermalManager.disable_all_heaters());
371
     IF_DISABLED(SD_ABORT_NO_COOLDOWN, thermalManager.disable_all_heaters());
371
 
372
 

+ 1
- 1
Marlin/src/lcd/marlinui.cpp 查看文件

1495
     #ifdef ACTION_ON_CANCEL
1495
     #ifdef ACTION_ON_CANCEL
1496
       host_action_cancel();
1496
       host_action_cancel();
1497
     #endif
1497
     #endif
1498
+    IF_DISABLED(SDSUPPORT, print_job_timer.stop());
1498
     TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR));
1499
     TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR));
1499
-    print_job_timer.stop();
1500
     LCD_MESSAGEPGM(MSG_PRINT_ABORTED);
1500
     LCD_MESSAGEPGM(MSG_PRINT_ABORTED);
1501
     TERN_(HAS_LCD_MENU, return_to_status());
1501
     TERN_(HAS_LCD_MENU, return_to_status());
1502
   }
1502
   }

+ 1
- 0
Marlin/src/libs/stopwatch.h 查看文件

56
      * @return true on success
56
      * @return true on success
57
      */
57
      */
58
     static bool stop();
58
     static bool stop();
59
+    static inline bool abort() { return stop(); } // Alias by default
59
 
60
 
60
     /**
61
     /**
61
      * @brief Pause the stopwatch
62
      * @brief Pause the stopwatch

+ 23
- 16
Marlin/src/module/printcounter.cpp 查看文件

41
   #include "../libs/buzzer.h"
41
   #include "../libs/buzzer.h"
42
 #endif
42
 #endif
43
 
43
 
44
+#if PRINTCOUNTER_SYNC
45
+  #include "../module/planner.h"
46
+#endif
47
+
44
 // Service intervals
48
 // Service intervals
45
 #if HAS_SERVICE_INTERVALS
49
 #if HAS_SERVICE_INTERVALS
46
   #if SERVICE_INTERVAL_1 > 0
50
   #if SERVICE_INTERVAL_1 > 0
160
   // Refuses to save data if object is not loaded
164
   // Refuses to save data if object is not loaded
161
   if (!isLoaded()) return;
165
   if (!isLoaded()) return;
162
 
166
 
167
+  TERN_(PRINTCOUNTER_SYNC, planner.synchronize());
168
+
163
   // Saves the struct to EEPROM
169
   // Saves the struct to EEPROM
164
   persistentStore.access_start();
170
   persistentStore.access_start();
165
   persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
171
   persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
244
     #endif
250
     #endif
245
   }
251
   }
246
 
252
 
247
-  static uint32_t eeprom_next; // = 0
248
-  if (ELAPSED(now, eeprom_next)) {
249
-    eeprom_next = now + saveInterval * 1000;
250
-    saveStats();
251
-  }
253
+  #if PRINTCOUNTER_SAVE_INTERVAL > 0
254
+    static millis_t eeprom_next; // = 0
255
+    if (ELAPSED(now, eeprom_next)) {
256
+      eeprom_next = now + saveInterval;
257
+      saveStats();
258
+    }
259
+  #endif
252
 }
260
 }
253
 
261
 
254
 // @Override
262
 // @Override
268
   return false;
276
   return false;
269
 }
277
 }
270
 
278
 
271
-// @Override
272
-bool PrintCounter::stop() {
279
+bool PrintCounter::_stop(const bool completed) {
273
   TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("stop")));
280
   TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("stop")));
274
 
281
 
275
-  if (super::stop()) {
276
-    data.finishedPrints++;
282
+  const bool did_stop = super::stop();
283
+  if (did_stop) {
277
     data.printTime += deltaDuration();
284
     data.printTime += deltaDuration();
278
-
279
-    if (duration() > data.longestPrint)
280
-      data.longestPrint = duration();
281
-
282
-    saveStats();
283
-    return true;
285
+    if (completed) {
286
+      data.finishedPrints++;
287
+      if (duration() > data.longestPrint)
288
+        data.longestPrint = duration();
289
+    }
284
   }
290
   }
285
-  else return false;
291
+  saveStats();
292
+  return did_stop;
286
 }
293
 }
287
 
294
 
288
 // @Override
295
 // @Override

+ 13
- 8
Marlin/src/module/printcounter.h 查看文件

74
      */
74
      */
75
     static constexpr millis_t updateInterval = SEC_TO_MS(10);
75
     static constexpr millis_t updateInterval = SEC_TO_MS(10);
76
 
76
 
77
-    /**
78
-     * @brief Interval in seconds between EEPROM saves
79
-     * @details This const value defines what will be the time between each
80
-     * EEPROM save cycle, the development team recommends to set this value
81
-     * no lower than 3600 secs (1 hour).
82
-     */
83
-    static constexpr uint16_t saveInterval = 3600;
77
+    #if PRINTCOUNTER_SAVE_INTERVAL > 0
78
+      /**
79
+       * @brief Interval in seconds between EEPROM saves
80
+       * @details This const value defines what will be the time between each
81
+       * EEPROM save cycle, the development team recommends to set this value
82
+       * no lower than 3600 secs (1 hour).
83
+       */
84
+      static constexpr millis_t saveInterval = MIN_TO_MS(PRINTCOUNTER_SAVE_INTERVAL);
85
+    #endif
84
 
86
 
85
     /**
87
     /**
86
      * @brief Timestamp of the last call to deltaDuration()
88
      * @brief Timestamp of the last call to deltaDuration()
173
      * The following functions are being overridden
175
      * The following functions are being overridden
174
      */
176
      */
175
     static bool start();
177
     static bool start();
176
-    static bool stop();
178
+    static bool _stop(const bool completed);
179
+    static inline bool stop()  { return _stop(true);  }
180
+    static inline bool abort() { return _stop(false); }
181
+
177
     static void reset();
182
     static void reset();
178
 
183
 
179
     #if HAS_SERVICE_INTERVALS
184
     #if HAS_SERVICE_INTERVALS

Loading…
取消
儲存