From 26b166d7cf1e363da2daefbc52fd097d88513807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Wed, 27 Apr 2016 02:12:08 +0100 Subject: [PATCH 01/10] Made all stopwatch::debug() calls static --- Marlin/printcounter.cpp | 109 ++++++++++++++++++++++++++++++++++++++++ Marlin/printcounter.h | 93 ++++++++++++++++++++++++++++++++++ Marlin/stopwatch.cpp | 8 +-- 3 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 Marlin/printcounter.cpp create mode 100644 Marlin/printcounter.h diff --git a/Marlin/printcounter.cpp b/Marlin/printcounter.cpp new file mode 100644 index 000000000..a8da87d33 --- /dev/null +++ b/Marlin/printcounter.cpp @@ -0,0 +1,109 @@ +/* + * Marlin 3D Printer Firmware + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "Marlin.h" +#include "printcounter.h" +#include + +PrintCounter::PrintCounter(): super() {} + +void PrintCounter::tick() { + if (!this->isRunning()) return; + + static uint32_t update_before = millis(), + eeprom_before = millis(); + + uint32_t now = millis(); + + // Trying to get the amount of calculations down to the bare min + const static uint16_t i = this->updateInterval * 1000; + + if (now - update_before >= i) { + //this->addToTimeCounter((uint16_t) (now - update_before) / 1000); + update_before = now; + PrintCounter::debug(PSTR("tick1")); + } + + // Trying to get the amount of calculations down to the bare min + const static uint16_t j = this->saveInterval * 1000; + + if (now - eeprom_before >= j) { + eeprom_before = now; + this->save(); + } +} + +void PrintCounter::load() { + uint16_t pos = this->addr; + + this->data.successPrints= eeprom_read_word ((uint16_t*) pos); + this->data.failedPrints = eeprom_read_word ((uint16_t*) pos); + this->data.printTime = eeprom_read_dword((uint32_t*) pos); + this->data.longestPrint = eeprom_read_dword((uint32_t*) pos); + + SERIAL_ECHOPGM("successPrints: "); + SERIAL_ECHOLN(this->data.successPrints); + + SERIAL_ECHOPGM("failedPrints: "); + SERIAL_ECHOLN(this->data.failedPrints); + + SERIAL_ECHOPGM("printTime: "); + SERIAL_ECHOLN(this->data.printTime); + + SERIAL_ECHOPGM("longestPrint: "); + SERIAL_ECHOLN(this->data.longestPrint); +} + +void PrintCounter::save() { + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("save")); + #endif + + uint16_t pos = this->addr; + + eeprom_write_word ((uint16_t*) pos, this->data.successPrints); + eeprom_write_word ((uint16_t*) pos, this->data.failedPrints); + eeprom_write_dword((uint32_t*) pos, this->data.printTime); + eeprom_write_dword((uint32_t*) pos, this->data.longestPrint); +} + +void PrintCounter::start() { + super::start(); + this->load(); +} + +void PrintCounter::stop() { + super::stop(); + this->save(); +} + +#if ENABLED(DEBUG_PRINTCOUNTER) + + void PrintCounter::debug(const char func[]) { + if (DEBUGGING(INFO)) { + SERIAL_ECHOPGM("PrintCounter::"); + serialprintPGM(func); + SERIAL_ECHOLNPGM("()"); + } + } + +#endif diff --git a/Marlin/printcounter.h b/Marlin/printcounter.h new file mode 100644 index 000000000..99d5b207b --- /dev/null +++ b/Marlin/printcounter.h @@ -0,0 +1,93 @@ +/* + * Marlin 3D Printer Firmware + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef PRINTCOUNTER_H +#define PRINTCOUNTER_H + +#include "macros.h" +#include "stopwatch.h" + +// Print debug messages with M111 S2 +#define DEBUG_PRINTCOUNTER + +struct printStatistics { // 12 bytes + uint16_t successPrints; // Total number of prints + uint16_t failedPrints; // Total number of aborted prints - not in use + uint32_t printTime; // Total time printing + uint32_t longestPrint; // Longest print job - not in use +}; + +class PrintCounter: public Stopwatch { + private: + typedef Stopwatch super; + + printStatistics data; + + /** + * @brief EEPROM address + * @details Defines the start offset address where the data is stored. + */ + const uint16_t addr = 60; + + /** + * @brief Interval in seconds between counter updates + * @details This const value defines what will be the time between each + * accumulator update. This is different from the EEPROM save interval + * which is user defined at the Configuration.h file. + */ + const uint16_t updateInterval = 2; + + /** + * @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). + */ + const uint16_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL; + + public: + /** + * @brief Class constructor + */ + PrintCounter(); + + void tick(); + void save(); + void load(); + void addToTimeCounter(uint16_t const &minutes); + void addToPrintCounter(uint8_t const &prints); + + void start(); + void stop(); + + #if ENABLED(DEBUG_PRINTCOUNTER) + + /** + * @brief Prints a debug message + * @details Prints a simple debug message "PrintCounter::function" + */ + static void debug(const char func[]); + + #endif +}; + +#endif // PRINTCOUNTER_H diff --git a/Marlin/stopwatch.cpp b/Marlin/stopwatch.cpp index f871af1c7..4a1344db1 100644 --- a/Marlin/stopwatch.cpp +++ b/Marlin/stopwatch.cpp @@ -29,7 +29,7 @@ Stopwatch::Stopwatch() { void Stopwatch::stop() { #if ENABLED(DEBUG_STOPWATCH) - debug(PSTR("stop")); + Stopwatch::debug(PSTR("stop")); #endif if (!this->isRunning()) return; @@ -40,7 +40,7 @@ void Stopwatch::stop() { void Stopwatch::pause() { #if ENABLED(DEBUG_STOPWATCH) - debug(PSTR("pause")); + Stopwatch::debug(PSTR("pause")); #endif if (!this->isRunning()) return; @@ -51,7 +51,7 @@ void Stopwatch::pause() { void Stopwatch::start() { #if ENABLED(DEBUG_STOPWATCH) - debug(PSTR("start")); + Stopwatch::debug(PSTR("start")); #endif if (this->isRunning()) return; @@ -65,7 +65,7 @@ void Stopwatch::start() { void Stopwatch::reset() { #if ENABLED(DEBUG_STOPWATCH) - debug(PSTR("reset")); + Stopwatch::debug(PSTR("reset")); #endif this->state = STPWTCH_STOPPED; From 4f541c5bb5318b4da52a3493c484166be60caa7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Wed, 27 Apr 2016 02:12:46 +0100 Subject: [PATCH 02/10] Added a new object: PrintCounter --- Marlin/printcounter.cpp | 171 +++++++++++++++++++++++++++++++--------- Marlin/printcounter.h | 78 +++++++++++++++--- 2 files changed, 199 insertions(+), 50 deletions(-) diff --git a/Marlin/printcounter.cpp b/Marlin/printcounter.cpp index a8da87d33..f2999fb04 100644 --- a/Marlin/printcounter.cpp +++ b/Marlin/printcounter.cpp @@ -24,7 +24,112 @@ #include "printcounter.h" #include -PrintCounter::PrintCounter(): super() {} +PrintCounter::PrintCounter(): super() { + this->loadStats(); +} + +bool PrintCounter::isLoaded() { + return this->loaded; +} + +void PrintCounter::initStats() { + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("initStats")); + #endif + + this->loaded = true; + this->data = { + 0, 0, 0, 0 + }; + + this->saveStats(); + eeprom_write_byte((uint8_t*) this->addr, 0x16); +} + +void PrintCounter::loadStats() { + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("loadStats")); + #endif + + uint16_t addr = this->addr; + + // Checks if the EEPROM block is initialized + if (eeprom_read_byte((uint8_t*) addr) != 0x16) this->initStats(); + + else { + // Skip the magic header byte + addr += sizeof(uint8_t); + + // @todo This section will need rewrite once the ConfigurationStore + // and/or PersistentStorage object comes along. + this->data.totalPrints = eeprom_read_word((uint16_t*) addr); + addr += sizeof(uint16_t); + + this->data.finishedPrints = eeprom_read_word((uint16_t*) addr); + addr += sizeof(uint16_t); + + this->data.printTime = eeprom_read_dword((uint32_t*) addr); + addr += sizeof(uint32_t); + + this->data.longestPrint = eeprom_read_dword((uint32_t*) addr); + } + + this->loaded = true; +} + +void PrintCounter::saveStats() { + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("saveStats")); + #endif + + // Refuses to save data is object is not loaded + if (!this->isLoaded()) return; + + // Skip the magic header byte + uint16_t addr = this->addr + sizeof(uint8_t); + + // @todo This section will need rewrite once the ConfigurationStore + // and/or PersistentStorage object comes along. + eeprom_write_word ((uint16_t*) addr, this->data.totalPrints); + addr += sizeof(uint16_t); + + eeprom_write_word ((uint16_t*) addr, this->data.finishedPrints); + addr += sizeof(uint16_t); + + eeprom_write_dword((uint32_t*) addr, this->data.printTime); + addr += sizeof(uint32_t); + + eeprom_write_dword((uint32_t*) addr, this->data.longestPrint); +} + +void PrintCounter::showStats() { + SERIAL_ECHOPGM("Print statistics: Total: "); + SERIAL_ECHO(this->data.totalPrints); + + SERIAL_ECHOPGM(", Finished: "); + SERIAL_ECHO(this->data.finishedPrints); + + SERIAL_ECHOPGM(", Failed: "); + SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints); + + uint32_t t = this->data.printTime /60; + SERIAL_ECHOPGM(", Total print time: "); + SERIAL_ECHO(t / 60); + + SERIAL_ECHOPGM("h "); + SERIAL_ECHO(t % 60); + + SERIAL_ECHOPGM("min"); + + #if ENABLED(DEBUG_PRINTCOUNTER) + SERIAL_ECHOPGM(" ("); + SERIAL_ECHO(this->data.printTime); + SERIAL_ECHOPGM(")"); + #endif + + // @todo longestPrint missing implementation + SERIAL_EOL; +} void PrintCounter::tick() { if (!this->isRunning()) return; @@ -38,9 +143,14 @@ void PrintCounter::tick() { const static uint16_t i = this->updateInterval * 1000; if (now - update_before >= i) { - //this->addToTimeCounter((uint16_t) (now - update_before) / 1000); + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("tick")); + #endif + + uint16_t t = this->duration();; + this->data.printTime += t - this->lastUpdate; + this->lastUpdate = t; update_before = now; - PrintCounter::debug(PSTR("tick1")); } // Trying to get the amount of calculations down to the bare min @@ -48,52 +158,37 @@ void PrintCounter::tick() { if (now - eeprom_before >= j) { eeprom_before = now; - this->save(); + this->saveStats(); } } -void PrintCounter::load() { - uint16_t pos = this->addr; - - this->data.successPrints= eeprom_read_word ((uint16_t*) pos); - this->data.failedPrints = eeprom_read_word ((uint16_t*) pos); - this->data.printTime = eeprom_read_dword((uint32_t*) pos); - this->data.longestPrint = eeprom_read_dword((uint32_t*) pos); - - SERIAL_ECHOPGM("successPrints: "); - SERIAL_ECHOLN(this->data.successPrints); - - SERIAL_ECHOPGM("failedPrints: "); - SERIAL_ECHOLN(this->data.failedPrints); - - SERIAL_ECHOPGM("printTime: "); - SERIAL_ECHOLN(this->data.printTime); - - SERIAL_ECHOPGM("longestPrint: "); - SERIAL_ECHOLN(this->data.longestPrint); -} - -void PrintCounter::save() { +void PrintCounter::start() { #if ENABLED(DEBUG_PRINTCOUNTER) - PrintCounter::debug(PSTR("save")); + PrintCounter::debug(PSTR("start")); #endif - uint16_t pos = this->addr; - - eeprom_write_word ((uint16_t*) pos, this->data.successPrints); - eeprom_write_word ((uint16_t*) pos, this->data.failedPrints); - eeprom_write_dword((uint32_t*) pos, this->data.printTime); - eeprom_write_dword((uint32_t*) pos, this->data.longestPrint); -} - -void PrintCounter::start() { + if (!this->isPaused()) this->data.totalPrints++; super::start(); - this->load(); } void PrintCounter::stop() { + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("stop")); + #endif + super::stop(); - this->save(); + this->data.finishedPrints++; + this->data.printTime += this->duration() - this->lastUpdate; + this->saveStats(); +} + +void PrintCounter::reset() { + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("stop")); + #endif + + this->lastUpdate = 0; + super::reset(); } #if ENABLED(DEBUG_PRINTCOUNTER) diff --git a/Marlin/printcounter.h b/Marlin/printcounter.h index 99d5b207b..e2410104b 100644 --- a/Marlin/printcounter.h +++ b/Marlin/printcounter.h @@ -29,11 +29,12 @@ // Print debug messages with M111 S2 #define DEBUG_PRINTCOUNTER -struct printStatistics { // 12 bytes - uint16_t successPrints; // Total number of prints - uint16_t failedPrints; // Total number of aborted prints - not in use - uint32_t printTime; // Total time printing - uint32_t longestPrint; // Longest print job - not in use +struct printStatistics { // 13 bytes + //uint8_t magic; // Magic header, it will always be 0x16 + uint16_t totalPrints; // Number of prints + uint16_t finishedPrints; // Number of complete prints + uint32_t printTime; // Total printing time + uint32_t longestPrint; // Longest print job - not in use }; class PrintCounter: public Stopwatch { @@ -42,11 +43,19 @@ class PrintCounter: public Stopwatch { printStatistics data; + /** + * @brief Timestamp of the last update + * @details Stores the timestamp of the last data.pritnTime update, when the + * print job finishes, this will be used to calculate the exact time elapsed, + * this is required due to the updateInterval cycle. + */ + uint16_t lastUpdate; + /** * @brief EEPROM address * @details Defines the start offset address where the data is stored. */ - const uint16_t addr = 60; + const uint16_t addr = 50; /** * @brief Interval in seconds between counter updates @@ -54,7 +63,7 @@ class PrintCounter: public Stopwatch { * accumulator update. This is different from the EEPROM save interval * which is user defined at the Configuration.h file. */ - const uint16_t updateInterval = 2; + const uint16_t updateInterval = 10; /** * @brief Interval in seconds between EEPROM saves @@ -64,20 +73,65 @@ class PrintCounter: public Stopwatch { */ const uint16_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL; + /** + * @brief Stats were loaded from EERPROM + * @details If set to true it indicates if the statistical data was already + * loaded from the EEPROM. + */ + bool loaded = false; + public: /** * @brief Class constructor */ PrintCounter(); - void tick(); - void save(); - void load(); - void addToTimeCounter(uint16_t const &minutes); - void addToPrintCounter(uint8_t const &prints); + /** + * @brief Checks if Print Statistics has been loaded + * @details Returns true if the statistical data has been loaded. + * @return bool + */ + bool isLoaded(); + /** + * @brief Resets the Print Statistics + * @details Resets the statistics to zero and saves them to EEPROM creating + * also the magic header. + */ + void initStats(); + + /** + * @brief Loads the Print Statistics + * @details Loads the statistics from EEPROM + */ + void loadStats(); + + /** + * @brief Saves the Print Statistics + * @details Saves the statistics to EEPROM + */ + void saveStats(); + + /** + * @brief Serial output the Print Statistics + * @details This function may change in the future, for now it directly + * prints the statistical data to serial. + */ + void showStats(); + + /** + * @brief Loop function + * @details This function should be called at loop, it will take care of + * periodically save the statistical data to EEPROM and do time keeping. + */ + void tick(); + + /** + * The following functions are being overridden + */ void start(); void stop(); + void reset(); #if ENABLED(DEBUG_PRINTCOUNTER) From d6cfcc9c8bed6c81222e6f64ea09d1a670e7de04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Wed, 27 Apr 2016 02:13:27 +0100 Subject: [PATCH 03/10] Added new G-Code: M78 --- Marlin/Marlin.h | 12 ++++++++++-- Marlin/Marlin_main.cpp | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index cc08d724b..9cd13c90e 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -65,7 +65,11 @@ typedef unsigned long millis_t; #include "WString.h" -#include "stopwatch.h" +#if ENABLED(PRINTCOUNTER) + #include "printcounter.h" +#else + #include "stopwatch.h" +#endif #ifdef USBCON #if ENABLED(BLUETOOTH) @@ -364,7 +368,11 @@ extern bool axis_homed[3]; // axis[n].is_homed #endif // Print job timer -extern Stopwatch print_job_timer; +#if ENABLED(PRINTCOUNTER) + extern PrintCounter print_job_timer; +#else + extern Stopwatch print_job_timer; +#endif // Handling multiple extruders pins extern uint8_t active_extruder; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 17d51f06f..2ddb33096 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -327,7 +327,11 @@ static millis_t max_inactive_time = 0; static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL; // Print Job Timer -Stopwatch print_job_timer = Stopwatch(); +#if ENABLED(PRINTCOUNTER) + PrintCounter print_job_timer = PrintCounter(); +#else + Stopwatch print_job_timer = Stopwatch(); +#endif static uint8_t target_extruder; @@ -4252,6 +4256,15 @@ inline void gcode_M77() { print_job_timer.stop(); } +#if ENABLED(PRINTCOUNTER) + /*+ + * M78: Show print statistics + */ + inline void gcode_M78() { + print_job_timer.showStats(); + } +#endif + /** * M104: Set hot end temperature */ @@ -6636,6 +6649,12 @@ void process_next_command() { gcode_M77(); break; + #if ENABLED(PRINTCOUNTER) + case 78: // Show print statistics + gcode_M78(); + break; + #endif + #if ENABLED(M100_FREE_MEMORY_WATCHER) case 100: gcode_M100(); @@ -7750,6 +7769,9 @@ void idle( ); host_keepalive(); lcd_update(); + #if ENABLED(PRINTCOUNTER) + print_job_timer.tick(); + #endif } /** From e2da7e5000c64e2179bb2748dfa96d45f9f0a4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Wed, 27 Apr 2016 02:27:23 +0100 Subject: [PATCH 04/10] Updated the default configuration and fixed a printcounter.h typo --- Marlin/Configuration.h | 13 +++++++++++++ Marlin/printcounter.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index edbeb44ab..c9a6245e9 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -757,6 +757,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 110 #define ABS_PREHEAT_FAN_SPEED 0 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/printcounter.h b/Marlin/printcounter.h index e2410104b..6a4e4c784 100644 --- a/Marlin/printcounter.h +++ b/Marlin/printcounter.h @@ -71,7 +71,7 @@ class PrintCounter: public Stopwatch { * EEPROM save cycle, the development team recommends to set this value * no lower than 3600 secs (1 hour). */ - const uint16_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL; + const uint16_t saveInterval = 3600; /** * @brief Stats were loaded from EERPROM From 484de24e2214c09b97f8e269c64b3c89c4302907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Wed, 27 Apr 2016 02:32:23 +0100 Subject: [PATCH 05/10] Updated travis to test for PRINTCOUNTER --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a2e58f228..fecb82a8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -139,7 +139,7 @@ script: ### I2C PANELS ### # # LCD_I2C_SAINSMART_YWROBOT - # Failing at the moment needs different library + # Failing at the moment needs different library #- restore_configs #- opt_enable LCD_I2C_SAINSMART_YWROBOT #- build_marlin @@ -199,6 +199,12 @@ script: - opt_set_adv Z2_MAX_PIN 2 - build_marlin # + # Test PRINTCOUNTER + # + - restore_configs + - opt_enable PRINTCOUNTER + - build_marlin + # # ######## Example Configurations ############## # From 9589e51810c55403ab4a3f164bb23e31d710c627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Wed, 27 Apr 2016 02:55:22 +0100 Subject: [PATCH 06/10] Disable DEBUG_PRINTCOUNTER --- Marlin/printcounter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/printcounter.h b/Marlin/printcounter.h index 6a4e4c784..9dbae6de2 100644 --- a/Marlin/printcounter.h +++ b/Marlin/printcounter.h @@ -27,7 +27,7 @@ #include "stopwatch.h" // Print debug messages with M111 S2 -#define DEBUG_PRINTCOUNTER +//#define DEBUG_PRINTCOUNTER struct printStatistics { // 13 bytes //uint8_t magic; // Magic header, it will always be 0x16 From 8fb23e899fc6bb74ecd88f1403b8e26846416c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Thu, 28 Apr 2016 02:30:07 +0100 Subject: [PATCH 07/10] PrintCounter EEPROM read/write optimizations --- Marlin/printcounter.cpp | 63 +++++++++++++---------------------------- Marlin/printcounter.h | 26 +++++++++++------ 2 files changed, 36 insertions(+), 53 deletions(-) diff --git a/Marlin/printcounter.cpp b/Marlin/printcounter.cpp index f2999fb04..c29cc8fb2 100644 --- a/Marlin/printcounter.cpp +++ b/Marlin/printcounter.cpp @@ -28,6 +28,16 @@ PrintCounter::PrintCounter(): super() { this->loadStats(); } +uint16_t PrintCounter::deltaDuration() { + #if ENABLED(DEBUG_PRINTCOUNTER) + PrintCounter::debug(PSTR("deltaDuration")); + #endif + + uint16_t tmp = this->lastDuration; + this->lastDuration = this->duration(); + return this->lastDuration - tmp; +} + bool PrintCounter::isLoaded() { return this->loaded; } @@ -38,9 +48,7 @@ void PrintCounter::initStats() { #endif this->loaded = true; - this->data = { - 0, 0, 0, 0 - }; + this->data = { 0, 0, 0, 0 }; this->saveStats(); eeprom_write_byte((uint8_t*) this->addr, 0x16); @@ -51,28 +59,9 @@ void PrintCounter::loadStats() { PrintCounter::debug(PSTR("loadStats")); #endif - uint16_t addr = this->addr; - // Checks if the EEPROM block is initialized - if (eeprom_read_byte((uint8_t*) addr) != 0x16) this->initStats(); - - else { - // Skip the magic header byte - addr += sizeof(uint8_t); - - // @todo This section will need rewrite once the ConfigurationStore - // and/or PersistentStorage object comes along. - this->data.totalPrints = eeprom_read_word((uint16_t*) addr); - addr += sizeof(uint16_t); - - this->data.finishedPrints = eeprom_read_word((uint16_t*) addr); - addr += sizeof(uint16_t); - - this->data.printTime = eeprom_read_dword((uint32_t*) addr); - addr += sizeof(uint32_t); - - this->data.longestPrint = eeprom_read_dword((uint32_t*) addr); - } + if (eeprom_read_byte((uint8_t*) this->addr) != 0x16) this->initStats(); + else eeprom_read_block(&this->data, (void *)(this->addr + sizeof(uint8_t)), sizeof(printStatistics)); this->loaded = true; } @@ -85,21 +74,7 @@ void PrintCounter::saveStats() { // Refuses to save data is object is not loaded if (!this->isLoaded()) return; - // Skip the magic header byte - uint16_t addr = this->addr + sizeof(uint8_t); - - // @todo This section will need rewrite once the ConfigurationStore - // and/or PersistentStorage object comes along. - eeprom_write_word ((uint16_t*) addr, this->data.totalPrints); - addr += sizeof(uint16_t); - - eeprom_write_word ((uint16_t*) addr, this->data.finishedPrints); - addr += sizeof(uint16_t); - - eeprom_write_dword((uint32_t*) addr, this->data.printTime); - addr += sizeof(uint32_t); - - eeprom_write_dword((uint32_t*) addr, this->data.longestPrint); + eeprom_write_block(&this->data, (void *)(this->addr + sizeof(uint8_t)), sizeof(printStatistics)); } void PrintCounter::showStats() { @@ -110,7 +85,8 @@ void PrintCounter::showStats() { SERIAL_ECHO(this->data.finishedPrints); SERIAL_ECHOPGM(", Failed: "); - SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints); + SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints + - (this->isRunning() || this->isPaused()) ? 1 : 0); // Removes 1 from failures with an active counter uint32_t t = this->data.printTime /60; SERIAL_ECHOPGM(", Total print time: "); @@ -148,8 +124,7 @@ void PrintCounter::tick() { #endif uint16_t t = this->duration();; - this->data.printTime += t - this->lastUpdate; - this->lastUpdate = t; + this->data.printTime += this->deltaDuration(); update_before = now; } @@ -178,7 +153,7 @@ void PrintCounter::stop() { super::stop(); this->data.finishedPrints++; - this->data.printTime += this->duration() - this->lastUpdate; + this->data.printTime += this->deltaDuration(); this->saveStats(); } @@ -187,7 +162,7 @@ void PrintCounter::reset() { PrintCounter::debug(PSTR("stop")); #endif - this->lastUpdate = 0; + this->lastDuration = 0; super::reset(); } diff --git a/Marlin/printcounter.h b/Marlin/printcounter.h index 9dbae6de2..05f704a5b 100644 --- a/Marlin/printcounter.h +++ b/Marlin/printcounter.h @@ -30,7 +30,7 @@ //#define DEBUG_PRINTCOUNTER struct printStatistics { // 13 bytes - //uint8_t magic; // Magic header, it will always be 0x16 + //const uint8_t magic; // Magic header, it will always be 0x16 uint16_t totalPrints; // Number of prints uint16_t finishedPrints; // Number of complete prints uint32_t printTime; // Total printing time @@ -43,14 +43,6 @@ class PrintCounter: public Stopwatch { printStatistics data; - /** - * @brief Timestamp of the last update - * @details Stores the timestamp of the last data.pritnTime update, when the - * print job finishes, this will be used to calculate the exact time elapsed, - * this is required due to the updateInterval cycle. - */ - uint16_t lastUpdate; - /** * @brief EEPROM address * @details Defines the start offset address where the data is stored. @@ -73,6 +65,13 @@ class PrintCounter: public Stopwatch { */ const uint16_t saveInterval = 3600; + /** + * @brief Timestamp of the last call to deltaDuration() + * @details Stores the timestamp of the last deltaDuration(), this is + * required due to the updateInterval cycle. + */ + uint16_t lastDuration; + /** * @brief Stats were loaded from EERPROM * @details If set to true it indicates if the statistical data was already @@ -80,6 +79,15 @@ class PrintCounter: public Stopwatch { */ bool loaded = false; + protected: + /** + * @brief dT since the last call + * @details Returns the elapsed time in seconds since the last call, this is + * used internally for print statistics accounting is not intended to be a + * user callable function. + */ + uint16_t deltaDuration(); + public: /** * @brief Class constructor From 27088e356f68d6ef684c001d3b0293ce6105bc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Thu, 28 Apr 2016 02:36:38 +0100 Subject: [PATCH 08/10] Updated example configuration files --- .../example_configurations/Felix/Configuration.h | 13 +++++++++++++ .../Hephestos/Configuration.h | 13 +++++++++++++ .../Hephestos_2/Configuration.h | 13 +++++++++++++ .../example_configurations/K8200/Configuration.h | 13 +++++++++++++ .../RepRapWorld/Megatronics/Configuration.h | 13 +++++++++++++ .../RigidBot/Configuration.h | 15 ++++++++++++++- .../example_configurations/SCARA/Configuration.h | 13 +++++++++++++ .../example_configurations/TAZ4/Configuration.h | 13 +++++++++++++ .../example_configurations/WITBOX/Configuration.h | 13 +++++++++++++ .../adafruit/ST7565/Configuration.h | 13 +++++++++++++ .../delta/biv2.5/Configuration.h | 13 +++++++++++++ .../delta/generic/Configuration.h | 13 +++++++++++++ .../delta/kossel_mini/Configuration.h | 13 +++++++++++++ .../delta/kossel_pro/Configuration.h | 13 +++++++++++++ .../delta/kossel_xl/Configuration.h | 13 +++++++++++++ .../makibox/Configuration.h | 13 +++++++++++++ .../tvrrug/Round2/Configuration.h | 13 +++++++++++++ 17 files changed, 222 insertions(+), 1 deletion(-) diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index 1cdefc2bc..719018da9 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -739,6 +739,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/Hephestos/Configuration.h b/Marlin/example_configurations/Hephestos/Configuration.h index 395bb8e76..ae2c8d9be 100644 --- a/Marlin/example_configurations/Hephestos/Configuration.h +++ b/Marlin/example_configurations/Hephestos/Configuration.h @@ -748,6 +748,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/Hephestos_2/Configuration.h b/Marlin/example_configurations/Hephestos_2/Configuration.h index 0dbb1d763..2e665e413 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration.h @@ -750,6 +750,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 110 #define ABS_PREHEAT_FAN_SPEED 0 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/K8200/Configuration.h b/Marlin/example_configurations/K8200/Configuration.h index 0d43cd2c3..c5412f494 100644 --- a/Marlin/example_configurations/K8200/Configuration.h +++ b/Marlin/example_configurations/K8200/Configuration.h @@ -773,6 +773,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 60 // K8200: set back to 110 if you have an upgraded heatbed power supply #define ABS_PREHEAT_FAN_SPEED 0 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h index 3f6208345..40ff70b53 100644 --- a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h +++ b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h @@ -756,6 +756,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 110 #define ABS_PREHEAT_FAN_SPEED 0 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/RigidBot/Configuration.h b/Marlin/example_configurations/RigidBot/Configuration.h index 82b66ef9d..47d643363 100644 --- a/Marlin/example_configurations/RigidBot/Configuration.h +++ b/Marlin/example_configurations/RigidBot/Configuration.h @@ -1,4 +1,4 @@ -/** +f/** * Marlin 3D Printer Firmware * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * @@ -751,6 +751,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 110 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/SCARA/Configuration.h b/Marlin/example_configurations/SCARA/Configuration.h index 808bf7e62..098608e0f 100644 --- a/Marlin/example_configurations/SCARA/Configuration.h +++ b/Marlin/example_configurations/SCARA/Configuration.h @@ -764,6 +764,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/TAZ4/Configuration.h b/Marlin/example_configurations/TAZ4/Configuration.h index 6c8165ea0..cacd13390 100644 --- a/Marlin/example_configurations/TAZ4/Configuration.h +++ b/Marlin/example_configurations/TAZ4/Configuration.h @@ -777,6 +777,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 110 #define ABS_PREHEAT_FAN_SPEED 0 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/WITBOX/Configuration.h b/Marlin/example_configurations/WITBOX/Configuration.h index 434143e38..9808e8560 100644 --- a/Marlin/example_configurations/WITBOX/Configuration.h +++ b/Marlin/example_configurations/WITBOX/Configuration.h @@ -748,6 +748,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/adafruit/ST7565/Configuration.h b/Marlin/example_configurations/adafruit/ST7565/Configuration.h index f941bb0d1..ffe72ebea 100644 --- a/Marlin/example_configurations/adafruit/ST7565/Configuration.h +++ b/Marlin/example_configurations/adafruit/ST7565/Configuration.h @@ -756,6 +756,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 110 #define ABS_PREHEAT_FAN_SPEED 0 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration.h b/Marlin/example_configurations/delta/biv2.5/Configuration.h index 40d6e9af8..ed5e5dc86 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration.h @@ -885,6 +885,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/delta/generic/Configuration.h b/Marlin/example_configurations/delta/generic/Configuration.h index c492573f5..3f9a20dd8 100644 --- a/Marlin/example_configurations/delta/generic/Configuration.h +++ b/Marlin/example_configurations/delta/generic/Configuration.h @@ -885,6 +885,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration.h b/Marlin/example_configurations/delta/kossel_mini/Configuration.h index e77eb3379..f2cbba422 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration.h @@ -889,6 +889,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration.h b/Marlin/example_configurations/delta/kossel_pro/Configuration.h index b5c9c76c6..dc759e69a 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration.h @@ -882,6 +882,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration.h b/Marlin/example_configurations/delta/kossel_xl/Configuration.h index 943443fb4..f26762fba 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration.h @@ -890,6 +890,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/makibox/Configuration.h b/Marlin/example_configurations/makibox/Configuration.h index 2b414100f..456c34f8c 100644 --- a/Marlin/example_configurations/makibox/Configuration.h +++ b/Marlin/example_configurations/makibox/Configuration.h @@ -759,6 +759,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration.h b/Marlin/example_configurations/tvrrug/Round2/Configuration.h index 59cfe714d..c57dbad8b 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration.h @@ -750,6 +750,19 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo #define ABS_PREHEAT_HPB_TEMP 100 #define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +// +// Print Counter +// +// When enabled Marlin will keep track of some print statistical data such as: +// - Total print jobs +// - Total successfull print jobs +// - Total failed print jobs +// - Total time printing +// +// This information can be viewed by the M78 command. +//#define PRINTCOUNTER + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= From 1491d682fbf25dd97a683fe6ac24bafe10c72a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Thu, 28 Apr 2016 15:40:24 +0100 Subject: [PATCH 09/10] Miscellaneous tweaks on PrintCounter --- Marlin/Marlin_main.cpp | 4 ++++ Marlin/printcounter.cpp | 8 ++++---- Marlin/printcounter.h | 5 ++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 2ddb33096..b0e576969 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -137,6 +137,10 @@ * M33 - Get the longname version of a path * M42 - Change pin status via gcode Use M42 Px Sy to set pin x to value y, when omitting Px the onboard led will be used. * M48 - Measure Z_Probe repeatability. M48 [P # of points] [X position] [Y position] [V_erboseness #] [E_ngage Probe] [L # of legs of travel] + * M75 - Start the print job timer + * M76 - Pause the print job timer + * M77 - Stop the print job timer + * M78 - Show statistical information about the print jobs * M80 - Turn on Power Supply * M81 - Turn off Power Supply * M82 - Set E codes absolute (default) diff --git a/Marlin/printcounter.cpp b/Marlin/printcounter.cpp index c29cc8fb2..59b8bc3e3 100644 --- a/Marlin/printcounter.cpp +++ b/Marlin/printcounter.cpp @@ -51,7 +51,7 @@ void PrintCounter::initStats() { this->data = { 0, 0, 0, 0 }; this->saveStats(); - eeprom_write_byte((uint8_t*) this->addr, 0x16); + eeprom_write_byte((uint8_t *) this->address, 0x16); } void PrintCounter::loadStats() { @@ -60,8 +60,8 @@ void PrintCounter::loadStats() { #endif // Checks if the EEPROM block is initialized - if (eeprom_read_byte((uint8_t*) this->addr) != 0x16) this->initStats(); - else eeprom_read_block(&this->data, (void *)(this->addr + sizeof(uint8_t)), sizeof(printStatistics)); + if (eeprom_read_byte((uint8_t *) this->address) != 0x16) this->initStats(); + else eeprom_read_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics)); this->loaded = true; } @@ -74,7 +74,7 @@ void PrintCounter::saveStats() { // Refuses to save data is object is not loaded if (!this->isLoaded()) return; - eeprom_write_block(&this->data, (void *)(this->addr + sizeof(uint8_t)), sizeof(printStatistics)); + eeprom_update_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics)); } void PrintCounter::showStats() { diff --git a/Marlin/printcounter.h b/Marlin/printcounter.h index 05f704a5b..b44caeefd 100644 --- a/Marlin/printcounter.h +++ b/Marlin/printcounter.h @@ -47,13 +47,12 @@ class PrintCounter: public Stopwatch { * @brief EEPROM address * @details Defines the start offset address where the data is stored. */ - const uint16_t addr = 50; + const uint16_t address = 0x32; /** * @brief Interval in seconds between counter updates * @details This const value defines what will be the time between each - * accumulator update. This is different from the EEPROM save interval - * which is user defined at the Configuration.h file. + * accumulator update. This is different from the EEPROM save interval. */ const uint16_t updateInterval = 10; From e34f4653ef8f762686bce7c5c0a406dc0fb902c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Br=C3=A1zio?= Date: Fri, 29 Apr 2016 23:13:10 +0100 Subject: [PATCH 10/10] Fixed a typo on the configuration files --- Marlin/Configuration.h | 2 +- Marlin/example_configurations/Felix/Configuration.h | 2 +- Marlin/example_configurations/Hephestos/Configuration.h | 2 +- Marlin/example_configurations/Hephestos_2/Configuration.h | 2 +- Marlin/example_configurations/K8200/Configuration.h | 2 +- .../RepRapWorld/Megatronics/Configuration.h | 2 +- Marlin/example_configurations/RigidBot/Configuration.h | 2 +- Marlin/example_configurations/SCARA/Configuration.h | 2 +- Marlin/example_configurations/TAZ4/Configuration.h | 2 +- Marlin/example_configurations/WITBOX/Configuration.h | 2 +- Marlin/example_configurations/adafruit/ST7565/Configuration.h | 2 +- Marlin/example_configurations/delta/biv2.5/Configuration.h | 2 +- Marlin/example_configurations/delta/generic/Configuration.h | 2 +- Marlin/example_configurations/delta/kossel_mini/Configuration.h | 2 +- Marlin/example_configurations/delta/kossel_pro/Configuration.h | 2 +- Marlin/example_configurations/delta/kossel_xl/Configuration.h | 2 +- Marlin/example_configurations/makibox/Configuration.h | 2 +- Marlin/example_configurations/tvrrug/Round2/Configuration.h | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c9a6245e9..49b31d406 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -763,7 +763,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index 719018da9..39f89f330 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -745,7 +745,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/Hephestos/Configuration.h b/Marlin/example_configurations/Hephestos/Configuration.h index ae2c8d9be..d1ddfa2b1 100644 --- a/Marlin/example_configurations/Hephestos/Configuration.h +++ b/Marlin/example_configurations/Hephestos/Configuration.h @@ -754,7 +754,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/Hephestos_2/Configuration.h b/Marlin/example_configurations/Hephestos_2/Configuration.h index 2e665e413..7a3264b26 100644 --- a/Marlin/example_configurations/Hephestos_2/Configuration.h +++ b/Marlin/example_configurations/Hephestos_2/Configuration.h @@ -756,7 +756,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/K8200/Configuration.h b/Marlin/example_configurations/K8200/Configuration.h index c5412f494..c800fa00f 100644 --- a/Marlin/example_configurations/K8200/Configuration.h +++ b/Marlin/example_configurations/K8200/Configuration.h @@ -779,7 +779,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h index 40ff70b53..6d41b7e97 100644 --- a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h +++ b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h @@ -762,7 +762,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/RigidBot/Configuration.h b/Marlin/example_configurations/RigidBot/Configuration.h index 47d643363..d0e47bd66 100644 --- a/Marlin/example_configurations/RigidBot/Configuration.h +++ b/Marlin/example_configurations/RigidBot/Configuration.h @@ -757,7 +757,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/SCARA/Configuration.h b/Marlin/example_configurations/SCARA/Configuration.h index 098608e0f..79f68392f 100644 --- a/Marlin/example_configurations/SCARA/Configuration.h +++ b/Marlin/example_configurations/SCARA/Configuration.h @@ -770,7 +770,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/TAZ4/Configuration.h b/Marlin/example_configurations/TAZ4/Configuration.h index cacd13390..135185861 100644 --- a/Marlin/example_configurations/TAZ4/Configuration.h +++ b/Marlin/example_configurations/TAZ4/Configuration.h @@ -783,7 +783,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/WITBOX/Configuration.h b/Marlin/example_configurations/WITBOX/Configuration.h index 9808e8560..0e9cfd36b 100644 --- a/Marlin/example_configurations/WITBOX/Configuration.h +++ b/Marlin/example_configurations/WITBOX/Configuration.h @@ -754,7 +754,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/adafruit/ST7565/Configuration.h b/Marlin/example_configurations/adafruit/ST7565/Configuration.h index ffe72ebea..111f5797e 100644 --- a/Marlin/example_configurations/adafruit/ST7565/Configuration.h +++ b/Marlin/example_configurations/adafruit/ST7565/Configuration.h @@ -762,7 +762,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration.h b/Marlin/example_configurations/delta/biv2.5/Configuration.h index ed5e5dc86..4a31e15cc 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration.h @@ -891,7 +891,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/delta/generic/Configuration.h b/Marlin/example_configurations/delta/generic/Configuration.h index 3f9a20dd8..c3d7b149c 100644 --- a/Marlin/example_configurations/delta/generic/Configuration.h +++ b/Marlin/example_configurations/delta/generic/Configuration.h @@ -891,7 +891,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration.h b/Marlin/example_configurations/delta/kossel_mini/Configuration.h index f2cbba422..fb38d6e0a 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration.h @@ -895,7 +895,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration.h b/Marlin/example_configurations/delta/kossel_pro/Configuration.h index dc759e69a..5236cf5cb 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration.h @@ -888,7 +888,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/delta/kossel_xl/Configuration.h b/Marlin/example_configurations/delta/kossel_xl/Configuration.h index f26762fba..1c14c3f05 100644 --- a/Marlin/example_configurations/delta/kossel_xl/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_xl/Configuration.h @@ -896,7 +896,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/makibox/Configuration.h b/Marlin/example_configurations/makibox/Configuration.h index 456c34f8c..17da23c62 100644 --- a/Marlin/example_configurations/makibox/Configuration.h +++ b/Marlin/example_configurations/makibox/Configuration.h @@ -765,7 +765,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing // diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration.h b/Marlin/example_configurations/tvrrug/Round2/Configuration.h index c57dbad8b..22b890865 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration.h @@ -756,7 +756,7 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = true; // set to true to invert the lo // // When enabled Marlin will keep track of some print statistical data such as: // - Total print jobs -// - Total successfull print jobs +// - Total successful print jobs // - Total failed print jobs // - Total time printing //