My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printcounter.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef PRINTCOUNTER_H
  23. #define PRINTCOUNTER_H
  24. #include "macros.h"
  25. #include "language.h"
  26. #include "stopwatch.h"
  27. // Print debug messages with M111 S2
  28. //#define DEBUG_PRINTCOUNTER
  29. struct printStatistics { // 16 bytes (20 with real doubles)
  30. //const uint8_t magic; // Magic header, it will always be 0x16
  31. uint16_t totalPrints; // Number of prints
  32. uint16_t finishedPrints; // Number of complete prints
  33. uint32_t printTime; // Accumulated printing time
  34. uint32_t longestPrint; // Longest successful print job
  35. double filamentUsed; // Accumulated filament consumed in mm
  36. };
  37. class PrintCounter: public Stopwatch {
  38. private:
  39. typedef Stopwatch super;
  40. printStatistics data;
  41. /**
  42. * @brief EEPROM address
  43. * @details Defines the start offset address where the data is stored.
  44. */
  45. #if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
  46. // round up address to next page boundary (assuming 32 byte pages)
  47. const uint32_t address = 0x40;
  48. #elif defined(CPU_32_BIT)
  49. const uint32_t address = 0x32;
  50. #else
  51. const uint16_t address = 0x32;
  52. #endif
  53. /**
  54. * @brief Interval in seconds between counter updates
  55. * @details This const value defines what will be the time between each
  56. * accumulator update. This is different from the EEPROM save interval.
  57. *
  58. * @note The max value for this option is 60(s), otherwise integer
  59. * overflow will happen.
  60. */
  61. const uint16_t updateInterval = 10;
  62. /**
  63. * @brief Interval in seconds between EEPROM saves
  64. * @details This const value defines what will be the time between each
  65. * EEPROM save cycle, the development team recommends to set this value
  66. * no lower than 3600 secs (1 hour).
  67. */
  68. const uint16_t saveInterval = 3600;
  69. /**
  70. * @brief Timestamp of the last call to deltaDuration()
  71. * @details Stores the timestamp of the last deltaDuration(), this is
  72. * required due to the updateInterval cycle.
  73. */
  74. millis_t lastDuration;
  75. /**
  76. * @brief Stats were loaded from EERPROM
  77. * @details If set to true it indicates if the statistical data was already
  78. * loaded from the EEPROM.
  79. */
  80. bool loaded = false;
  81. protected:
  82. /**
  83. * @brief dT since the last call
  84. * @details Returns the elapsed time in seconds since the last call, this is
  85. * used internally for print statistics accounting is not intended to be a
  86. * user callable function.
  87. */
  88. millis_t deltaDuration();
  89. public:
  90. /**
  91. * @brief Class constructor
  92. */
  93. PrintCounter();
  94. /**
  95. * @brief Checks if Print Statistics has been loaded
  96. * @details Returns true if the statistical data has been loaded.
  97. * @return bool
  98. */
  99. bool isLoaded();
  100. /**
  101. * @brief Increments the total filament used
  102. * @details The total filament used counter will be incremented by "amount".
  103. *
  104. * @param amount The amount of filament used in mm
  105. */
  106. void incFilamentUsed(double const &amount);
  107. /**
  108. * @brief Resets the Print Statistics
  109. * @details Resets the statistics to zero and saves them to EEPROM creating
  110. * also the magic header.
  111. */
  112. void initStats();
  113. /**
  114. * @brief Loads the Print Statistics
  115. * @details Loads the statistics from EEPROM
  116. */
  117. void loadStats();
  118. /**
  119. * @brief Saves the Print Statistics
  120. * @details Saves the statistics to EEPROM
  121. */
  122. void saveStats();
  123. /**
  124. * @brief Serial output the Print Statistics
  125. * @details This function may change in the future, for now it directly
  126. * prints the statistical data to serial.
  127. */
  128. void showStats();
  129. /**
  130. * @brief Return the currently loaded statistics
  131. * @details Return the raw data, in the same structure used internally
  132. */
  133. printStatistics getStats() { return this->data; }
  134. /**
  135. * @brief Loop function
  136. * @details This function should be called at loop, it will take care of
  137. * periodically save the statistical data to EEPROM and do time keeping.
  138. */
  139. void tick();
  140. /**
  141. * The following functions are being overridden
  142. */
  143. bool start();
  144. bool stop();
  145. void reset();
  146. #if ENABLED(DEBUG_PRINTCOUNTER)
  147. /**
  148. * @brief Prints a debug message
  149. * @details Prints a simple debug message "PrintCounter::function"
  150. */
  151. static void debug(const char func[]);
  152. #endif
  153. };
  154. #endif // PRINTCOUNTER_H