Procházet zdrojové kódy

Configure / disable PRINTCOUNTER save interval (#20856)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
ConstantijnCrijnen před 4 roky
rodič
revize
b95f5c5bea
No account linked to committer's email address

+ 3
- 0
Marlin/Configuration.h Zobrazit soubor

@@ -1754,6 +1754,9 @@
1754 1754
  * View the current statistics with M78.
1755 1755
  */
1756 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 1762
  * Password

+ 7
- 0
Marlin/src/HAL/LPC1768/inc/Conditionals_post.h Zobrazit soubor

@@ -26,3 +26,10 @@
26 26
 #elif EITHER(I2C_EEPROM, SPI_EEPROM)
27 27
   #define USE_SHARED_EEPROM 1
28 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 Zobrazit soubor

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

+ 1
- 1
Marlin/src/lcd/marlinui.cpp Zobrazit soubor

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

+ 1
- 0
Marlin/src/libs/stopwatch.h Zobrazit soubor

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

+ 23
- 16
Marlin/src/module/printcounter.cpp Zobrazit soubor

@@ -41,6 +41,10 @@ Stopwatch print_job_timer;      // Global Print Job Timer instance
41 41
   #include "../libs/buzzer.h"
42 42
 #endif
43 43
 
44
+#if PRINTCOUNTER_SYNC
45
+  #include "../module/planner.h"
46
+#endif
47
+
44 48
 // Service intervals
45 49
 #if HAS_SERVICE_INTERVALS
46 50
   #if SERVICE_INTERVAL_1 > 0
@@ -160,6 +164,8 @@ void PrintCounter::saveStats() {
160 164
   // Refuses to save data if object is not loaded
161 165
   if (!isLoaded()) return;
162 166
 
167
+  TERN_(PRINTCOUNTER_SYNC, planner.synchronize());
168
+
163 169
   // Saves the struct to EEPROM
164 170
   persistentStore.access_start();
165 171
   persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
@@ -244,11 +250,13 @@ void PrintCounter::tick() {
244 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 262
 // @Override
@@ -268,21 +276,20 @@ bool PrintCounter::start() {
268 276
   return false;
269 277
 }
270 278
 
271
-// @Override
272
-bool PrintCounter::stop() {
279
+bool PrintCounter::_stop(const bool completed) {
273 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 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 295
 // @Override

+ 13
- 8
Marlin/src/module/printcounter.h Zobrazit soubor

@@ -74,13 +74,15 @@ class PrintCounter: public Stopwatch {
74 74
      */
75 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 88
      * @brief Timestamp of the last call to deltaDuration()
@@ -173,7 +175,10 @@ class PrintCounter: public Stopwatch {
173 175
      * The following functions are being overridden
174 176
      */
175 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 182
     static void reset();
178 183
 
179 184
     #if HAS_SERVICE_INTERVALS

Loading…
Zrušit
Uložit