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 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "stopwatch.h"
  26. // Print debug messages with M111 S2
  27. //#define DEBUG_PRINTCOUNTER
  28. struct printStatistics { // 13 bytes
  29. //const uint8_t magic; // Magic header, it will always be 0x16
  30. uint16_t totalPrints; // Number of prints
  31. uint16_t finishedPrints; // Number of complete prints
  32. uint32_t printTime; // Total printing time
  33. uint32_t longestPrint; // Longest print job - not in use
  34. };
  35. class PrintCounter: public Stopwatch {
  36. private:
  37. typedef Stopwatch super;
  38. printStatistics data;
  39. /**
  40. * @brief EEPROM address
  41. * @details Defines the start offset address where the data is stored.
  42. */
  43. const uint16_t address = 0x32;
  44. /**
  45. * @brief Interval in seconds between counter updates
  46. * @details This const value defines what will be the time between each
  47. * accumulator update. This is different from the EEPROM save interval.
  48. */
  49. const uint16_t updateInterval = 10;
  50. /**
  51. * @brief Interval in seconds between EEPROM saves
  52. * @details This const value defines what will be the time between each
  53. * EEPROM save cycle, the development team recommends to set this value
  54. * no lower than 3600 secs (1 hour).
  55. */
  56. const uint16_t saveInterval = 3600;
  57. /**
  58. * @brief Timestamp of the last call to deltaDuration()
  59. * @details Stores the timestamp of the last deltaDuration(), this is
  60. * required due to the updateInterval cycle.
  61. */
  62. uint16_t lastDuration;
  63. /**
  64. * @brief Stats were loaded from EERPROM
  65. * @details If set to true it indicates if the statistical data was already
  66. * loaded from the EEPROM.
  67. */
  68. bool loaded = false;
  69. protected:
  70. /**
  71. * @brief dT since the last call
  72. * @details Returns the elapsed time in seconds since the last call, this is
  73. * used internally for print statistics accounting is not intended to be a
  74. * user callable function.
  75. */
  76. uint16_t deltaDuration();
  77. public:
  78. /**
  79. * @brief Class constructor
  80. */
  81. PrintCounter();
  82. /**
  83. * @brief Checks if Print Statistics has been loaded
  84. * @details Returns true if the statistical data has been loaded.
  85. * @return bool
  86. */
  87. bool isLoaded();
  88. /**
  89. * @brief Resets the Print Statistics
  90. * @details Resets the statistics to zero and saves them to EEPROM creating
  91. * also the magic header.
  92. */
  93. void initStats();
  94. /**
  95. * @brief Loads the Print Statistics
  96. * @details Loads the statistics from EEPROM
  97. */
  98. void loadStats();
  99. /**
  100. * @brief Saves the Print Statistics
  101. * @details Saves the statistics to EEPROM
  102. */
  103. void saveStats();
  104. /**
  105. * @brief Serial output the Print Statistics
  106. * @details This function may change in the future, for now it directly
  107. * prints the statistical data to serial.
  108. */
  109. void showStats();
  110. /**
  111. * @brief Loop function
  112. * @details This function should be called at loop, it will take care of
  113. * periodically save the statistical data to EEPROM and do time keeping.
  114. */
  115. void tick();
  116. /**
  117. * The following functions are being overridden
  118. */
  119. void start();
  120. void stop();
  121. void reset();
  122. #if ENABLED(DEBUG_PRINTCOUNTER)
  123. /**
  124. * @brief Prints a debug message
  125. * @details Prints a simple debug message "PrintCounter::function"
  126. */
  127. static void debug(const char func[]);
  128. #endif
  129. };
  130. #endif // PRINTCOUNTER_H