Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PRINTCOUNTER errors due to no extruder
Browse files Browse the repository at this point in the history
CAP1Sup committed Apr 20, 2022
1 parent 3e1dd0d commit 0a7306d
Showing 3 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
@@ -210,7 +210,7 @@ void GcodeSuite::get_destination_from_command() {
if (parser.floatval('F') > 0)
feedrate_mm_s = parser.value_feedrate();

#if ENABLED(PRINTCOUNTER)
#if (ENABLED(PRINTCOUNTER) && HAS_EXTRUDERS)
if (!DEBUGGING(DRYRUN) && !skip_move)
print_job_timer.incFilamentUsed(destination.e - current_position.e);
#endif
27 changes: 18 additions & 9 deletions Marlin/src/module/printcounter.cpp
Original file line number Diff line number Diff line change
@@ -80,20 +80,26 @@ millis_t PrintCounter::deltaDuration() {
return lastDuration - tmp;
}

void PrintCounter::incFilamentUsed(float const &amount) {
TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("incFilamentUsed")));
#if HAS_EXTRUDERS
void PrintCounter::incFilamentUsed(float const &amount) {
TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("incFilamentUsed")));

// Refuses to update data if object is not loaded
if (!isLoaded()) return;
// Refuses to update data if object is not loaded
if (!isLoaded()) return;

data.filamentUsed += amount; // mm
}
data.filamentUsed += amount; // mm
}
#endif

void PrintCounter::initStats() {
TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("initStats")));

loaded = true;
data = { 0, 0, 0, 0, 0.0
data = { 0, 0, 0, 0
#if HAS_EXTRUDERS
, 0.0
#endif

#if HAS_SERVICE_INTERVALS
#if SERVICE_INTERVAL_1 > 0
, SERVICE_INTERVAL_SEC_1
@@ -210,8 +216,11 @@ void PrintCounter::showStats() {
SERIAL_CHAR(')');
#endif

SERIAL_ECHOPGM("\n" STR_STATS "Filament used: ", data.filamentUsed / 1000);
SERIAL_CHAR('m');
#if HAS_EXTRUDERS
SERIAL_ECHOPGM("\n" STR_STATS "Filament used: ", data.filamentUsed / 1000);
SERIAL_CHAR('m');
#endif

SERIAL_EOL();

#if SERVICE_INTERVAL_1 > 0
22 changes: 14 additions & 8 deletions Marlin/src/module/printcounter.h
Original file line number Diff line number Diff line change
@@ -37,7 +37,11 @@ struct printStatistics { // 16 bytes
uint16_t finishedPrints; // Number of complete prints
uint32_t printTime; // Accumulated printing time
uint32_t longestPrint; // Longest successful print job
float filamentUsed; // Accumulated filament consumed in mm

#if HAS_EXTRUDERS
float filamentUsed; // Accumulated filament consumed in mm
#endif

#if SERVICE_INTERVAL_1 > 0
uint32_t nextService1; // Service intervals (or placeholders)
#endif
@@ -124,13 +128,15 @@ class PrintCounter: public Stopwatch {
*/
FORCE_INLINE static bool isLoaded() { return loaded; }

/**
* @brief Increment the total filament used
* @details The total filament used counter will be incremented by "amount".
*
* @param amount The amount of filament used in mm
*/
static void incFilamentUsed(float const &amount);
#if HAS_EXTRUDERS
/**
* @brief Increment the total filament used
* @details The total filament used counter will be incremented by "amount".
*
* @param amount The amount of filament used in mm
*/
static void incFilamentUsed(float const &amount);
#endif

/**
* @brief Reset the Print Statistics

0 comments on commit 0a7306d

Please sign in to comment.