Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to configure or disable PRINTCOUNTER save interval #20856

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8a32cb
Printcounter Fix (issue #20785)
ConstantijnCrijnen Jan 21, 2021
671cfe6
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into PRR/Printco…
sjasonsmith Jan 24, 2021
7c675fa
Add pc.abort method
thinkyhead Jan 25, 2021
2e3ab97
fixups
thinkyhead Jan 25, 2021
977eaa0
comments
thinkyhead Jan 25, 2021
2bf7c36
fixups
thinkyhead Jan 25, 2021
a0a94d3
synchronize is not sensible here
thinkyhead Jan 25, 2021
75c65df
Apply SEC_TO_MS
thinkyhead Jan 25, 2021
f6d2847
Use original save interval
thinkyhead Jan 25, 2021
71a4294
Longer interval
thinkyhead Jan 25, 2021
fd903e4
better
thinkyhead Jan 25, 2021
211aeb8
sync instead of disabling
thinkyhead Jan 25, 2021
2ac4108
.stop needed for non-sd
thinkyhead Jan 25, 2021
9e61b9a
Sync on any write
thinkyhead Jan 25, 2021
f39e2d9
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/20856
thinkyhead Jan 25, 2021
02d267f
etc
thinkyhead Jan 25, 2021
07c701b
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/20856
thinkyhead Jan 25, 2021
a5571df
Merge branch 'Printcounter-Fix-(issue-#20785)' of https://github.com/…
ConstantijnCrijnen Jan 25, 2021
57a6665
Revert "Merge branch 'Printcounter-Fix-(issue-#20785)' of https://git…
ConstantijnCrijnen Jan 25, 2021
8533b62
Merge branch 'bugfix-2.0.x' into Printcounter-Fix-(issue-#20785)
thinkyhead Jan 26, 2021
47b7dcb
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/20856
thinkyhead Jan 26, 2021
051944f
Update Configuration.h
thinkyhead Jan 26, 2021
6b9482d
fix spacing
thinkyhead Jan 26, 2021
112568a
Get back to known good state
thinkyhead Jan 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,9 @@
* View the current statistics with M78.
*/
//#define PRINTCOUNTER
#if ENABLED(PRINTCOUNTER)
#define PRINTCOUNTER_SAVE_INTERVAL 1 // (seconds) EEPROM save interval during print
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#endif

/**
* Password
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@
#elif EITHER(I2C_EEPROM, SPI_EEPROM)
#define USE_SHARED_EEPROM 1
#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
#undef PRINTCOUNTER_SAVE_INTERVAL
#warning "PRINTCOUNTER_SAVE_INTERVAL causes print artifacts! Disabling auto-save."
#endif
6 changes: 4 additions & 2 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void startOrResumeJob() {
card.endFilePrint(TERN_(SD_RESORT, true));
queue.clear();
quickstop_stepper();
print_job_timer.stop();
print_job_timer.abort();
#if DISABLED(SD_ABORT_NO_COOLDOWN)
thermalManager.disable_all_heaters();
#endif
Expand Down Expand Up @@ -783,7 +783,9 @@ void minkill(const bool steppers_off/*=false*/) {
*/
void stop() {
thermalManager.disable_all_heaters(); // 'unpause' taken care of in here
print_job_timer.stop();

planner.synchronize();
print_job_timer.stop(); // Wait for planner before calling

#if ENABLED(PROBING_FANS_OFF)
if (thermalManager.fans_paused) thermalManager.set_fans_paused(false); // put things back the way they were
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
#define _DO_12(W,C,A,V...) (_##W##_1(A) C _DO_11(W,C,V))
#define _DO_13(W,C,A,V...) (_##W##_1(A) C _DO_12(W,C,V))
#define _DO_14(W,C,A,V...) (_##W##_1(A) C _DO_13(W,C,V))
#define _DO_15(W,C,A,V...) (_##W##_1(A) C _DO_14(W,C,V))
#define __DO_N(W,C,N,V...) _DO_##N(W,C,V)
#define _DO_N(W,C,N,V...) __DO_N(W,C,N,V)
#define DO(W,C,V...) (_DO_N(W,C,NUM_ARGS(V),V))
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/gcode/control/M80_M81.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@
*/
void GcodeSuite::M81() {
thermalManager.disable_all_heaters();
print_job_timer.stop();
planner.finish_and_disable();

print_job_timer.stop(); // Wait for planner before calling

#if HAS_FAN
thermalManager.zero_fan_speeds();
#if ENABLED(PROBING_FANS_OFF)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/L6470/M916-918.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void GcodeSuite::M916() {
M91x_counter_max = 256; // KVAL_HOLD is 8 bits

uint8_t M91x_delay_s = parser.byteval('D'); // get delay in seconds
millis_t M91x_delay_ms = M91x_delay_s * 60 * 1000;
millis_t M91x_delay_ms = SEC_TO_MS(M91x_delay_s * 60);
millis_t M91x_delay_end;

DEBUG_ECHOLNPGM(".\n.");
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class GCodeParser {

// Code value for use as time
static inline millis_t value_millis() { return value_ulong(); }
static inline millis_t value_millis_from_seconds() { return (millis_t)(value_float() * 1000); }
static inline millis_t value_millis_from_seconds() { return (millis_t)SEC_TO_MS(value_float()); }

// Reduce to fewer bits
static inline int16_t value_int() { return (int16_t)value_long(); }
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,6 @@ void MarlinUI::update() {
host_action_cancel();
#endif
TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR));
print_job_timer.stop();
LCD_MESSAGEPGM(MSG_PRINT_ABORTED);
TERN_(HAS_LCD_MENU, return_to_status());
}
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/libs/stopwatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Stopwatch {
* @return true on success
*/
static bool stop();
static inline bool abort() { return stop(); } // Alias by default

/**
* @brief Pause the stopwatch
Expand Down
40 changes: 21 additions & 19 deletions Marlin/src/module/printcounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,12 @@ void PrintCounter::tick() {

millis_t now = millis();

static uint32_t update_next; // = 0
static millis_t update_next; // = 0
if (ELAPSED(now, update_next)) {
update_next = now + updateInterval;

TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("tick")));

millis_t delta = deltaDuration();
data.printTime += delta;

Expand All @@ -239,15 +242,15 @@ void PrintCounter::tick() {
#if SERVICE_INTERVAL_3 > 0
data.nextService3 -= _MIN(delta, data.nextService3);
#endif

update_next = now + updateInterval * 1000;
}

static uint32_t eeprom_next; // = 0
if (ELAPSED(now, eeprom_next)) {
eeprom_next = now + saveInterval * 1000;
saveStats();
}
#if PRINTCOUNTER_SAVE_INTERVAL > 0
static millis_t eeprom_next; // = 0
if (ELAPSED(now, eeprom_next)) {
eeprom_next = now + saveInterval;
saveStats();
}
#endif
}

// @Override
Expand All @@ -267,21 +270,20 @@ bool PrintCounter::start() {
return false;
}

// @Override
bool PrintCounter::stop() {
bool PrintCounter::_stop(const bool completed) {
TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("stop")));

if (super::stop()) {
data.finishedPrints++;
const bool did_stop = super::stop();
if (did_stop) {
data.printTime += deltaDuration();

if (duration() > data.longestPrint)
data.longestPrint = duration();

saveStats();
return true;
if (completed) {
data.finishedPrints++;
if (duration() > data.longestPrint)
data.longestPrint = duration();
}
}
else return false;
saveStats();
return did_stop;
}

// @Override
Expand Down
23 changes: 14 additions & 9 deletions Marlin/src/module/printcounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ class PrintCounter: public Stopwatch {
* @note The max value for this option is 60(s), otherwise integer
* overflow will happen.
*/
static constexpr uint16_t updateInterval = 10;
static constexpr millis_t updateInterval = SEC_TO_MS(10);

/**
* @brief Interval in seconds between EEPROM saves
* @details This const value defines what will be the time between each
* EEPROM save cycle, the development team recommends to set this value
* no lower than 3600 secs (1 hour).
*/
static constexpr uint16_t saveInterval = 3600;
#if PRINTCOUNTER_SAVE_INTERVAL > 0
/**
* @brief Interval in seconds between EEPROM saves
* @details This const value defines what will be the time between each
* EEPROM save cycle, the development team recommends to set this value
* no lower than 3600 secs (1 hour).
*/
static constexpr millis_t saveInterval = SEC_TO_MS(PRINTCOUNTER_SAVE_INTERVAL);
#endif

/**
* @brief Timestamp of the last call to deltaDuration()
Expand Down Expand Up @@ -176,7 +178,10 @@ class PrintCounter: public Stopwatch {
* The following functions are being overridden
*/
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();

#if HAS_SERVICE_INTERVALS
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,6 @@ void Temperature::disable_all_heaters() {

#endif


#if ENABLED(PROBING_HEATERS_OFF)

void Temperature::pause(const bool p) {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
// Cool down with fan
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
gcode.dwell(toolchange_settings.fan_time * 1000);
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
#endif

Expand Down Expand Up @@ -1102,7 +1102,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
// Cool down with fan
#if HAS_FAN && TOOLCHANGE_FS_FAN >= 0
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed;
gcode.dwell(toolchange_settings.fan_time * 1000);
gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time));
thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/lpc1768/pins_MKS_SBASE.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#if defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1769)
#error "Oops! Make sure you have the LPC1769 environment selected in your IDE."
#elif NOT_TARGET(MKS_HAS_LPC1769, MCU_LPC1768)
#elif !defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1768)
#error "Oops! Make sure you have the LPC1768 environment selected in your IDE."
#endif

Expand Down