Browse Source

Configure / disable PRINTCOUNTER save interval (#20856)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
vanilla_fb_2.0.x
ConstantijnCrijnen 4 years ago
committed by Scott Lahteine
parent
commit
cdefc19129
  1. 3
      Marlin/Configuration.h
  2. 7
      Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
  3. 3
      Marlin/src/MarlinCore.cpp
  4. 2
      Marlin/src/lcd/marlinui.cpp
  5. 1
      Marlin/src/libs/stopwatch.h
  6. 29
      Marlin/src/module/printcounter.cpp
  7. 9
      Marlin/src/module/printcounter.h

3
Marlin/Configuration.h

@ -1754,6 +1754,9 @@
* View the current statistics with M78. * View the current statistics with M78.
*/ */
//#define PRINTCOUNTER //#define PRINTCOUNTER
#if ENABLED(PRINTCOUNTER)
#define PRINTCOUNTER_SAVE_INTERVAL 60 // (minutes) EEPROM save interval during print
#endif
/** /**
* Password * Password

7
Marlin/src/HAL/LPC1768/inc/Conditionals_post.h

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

3
Marlin/src/MarlinCore.cpp

@ -365,7 +365,8 @@ void startOrResumeJob() {
queue.clear(); queue.clear();
quickstop_stepper(); quickstop_stepper();
print_job_timer.stop();
print_job_timer.abort();
IF_DISABLED(SD_ABORT_NO_COOLDOWN, thermalManager.disable_all_heaters()); IF_DISABLED(SD_ABORT_NO_COOLDOWN, thermalManager.disable_all_heaters());

2
Marlin/src/lcd/marlinui.cpp

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

1
Marlin/src/libs/stopwatch.h

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

29
Marlin/src/module/printcounter.cpp

@ -41,6 +41,10 @@ Stopwatch print_job_timer; // Global Print Job Timer instance
#include "../libs/buzzer.h" #include "../libs/buzzer.h"
#endif #endif
#if PRINTCOUNTER_SYNC
#include "../module/planner.h"
#endif
// Service intervals // Service intervals
#if HAS_SERVICE_INTERVALS #if HAS_SERVICE_INTERVALS
#if SERVICE_INTERVAL_1 > 0 #if SERVICE_INTERVAL_1 > 0
@ -160,6 +164,8 @@ void PrintCounter::saveStats() {
// Refuses to save data if object is not loaded // Refuses to save data if object is not loaded
if (!isLoaded()) return; if (!isLoaded()) return;
TERN_(PRINTCOUNTER_SYNC, planner.synchronize());
// Saves the struct to EEPROM // Saves the struct to EEPROM
persistentStore.access_start(); persistentStore.access_start();
persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics)); persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
@ -244,11 +250,13 @@ void PrintCounter::tick() {
#endif #endif
} }
static uint32_t eeprom_next; // = 0 #if PRINTCOUNTER_SAVE_INTERVAL > 0
static millis_t eeprom_next; // = 0
if (ELAPSED(now, eeprom_next)) { if (ELAPSED(now, eeprom_next)) {
eeprom_next = now + saveInterval * 1000; eeprom_next = now + saveInterval;
saveStats(); saveStats();
} }
#endif
} }
// @Override // @Override
@ -268,21 +276,20 @@ bool PrintCounter::start() {
return false; return false;
} }
// @Override bool PrintCounter::_stop(const bool completed) {
bool PrintCounter::stop() {
TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("stop"))); TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("stop")));
if (super::stop()) { const bool did_stop = super::stop();
data.finishedPrints++; if (did_stop) {
data.printTime += deltaDuration(); data.printTime += deltaDuration();
if (completed) {
data.finishedPrints++;
if (duration() > data.longestPrint) if (duration() > data.longestPrint)
data.longestPrint = duration(); data.longestPrint = duration();
saveStats();
return true;
} }
else return false; }
saveStats();
return did_stop;
} }
// @Override // @Override

9
Marlin/src/module/printcounter.h

@ -74,13 +74,15 @@ class PrintCounter: public Stopwatch {
*/ */
static constexpr millis_t updateInterval = SEC_TO_MS(10); static constexpr millis_t updateInterval = SEC_TO_MS(10);
#if PRINTCOUNTER_SAVE_INTERVAL > 0
/** /**
* @brief Interval in seconds between EEPROM saves * @brief Interval in seconds between EEPROM saves
* @details This const value defines what will be the time between each * @details This const value defines what will be the time between each
* EEPROM save cycle, the development team recommends to set this value * EEPROM save cycle, the development team recommends to set this value
* no lower than 3600 secs (1 hour). * no lower than 3600 secs (1 hour).
*/ */
static constexpr uint16_t saveInterval = 3600; static constexpr millis_t saveInterval = MIN_TO_MS(PRINTCOUNTER_SAVE_INTERVAL);
#endif
/** /**
* @brief Timestamp of the last call to deltaDuration() * @brief Timestamp of the last call to deltaDuration()
@ -173,7 +175,10 @@ class PrintCounter: public Stopwatch {
* The following functions are being overridden * The following functions are being overridden
*/ */
static bool start(); static bool start();
static bool stop(); static bool _stop(const bool completed);
static inline bool stop() { return _stop(true); }
static inline bool abort() { return _stop(false); }
static void reset(); static void reset();
#if HAS_SERVICE_INTERVALS #if HAS_SERVICE_INTERVALS

Loading…
Cancel
Save