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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. //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 Timestamp of the last update
  41. * @details Stores the timestamp of the last data.pritnTime update, when the
  42. * print job finishes, this will be used to calculate the exact time elapsed,
  43. * this is required due to the updateInterval cycle.
  44. */
  45. uint16_t lastUpdate;
  46. /**
  47. * @brief EEPROM address
  48. * @details Defines the start offset address where the data is stored.
  49. */
  50. const uint16_t addr = 50;
  51. /**
  52. * @brief Interval in seconds between counter updates
  53. * @details This const value defines what will be the time between each
  54. * accumulator update. This is different from the EEPROM save interval
  55. * which is user defined at the Configuration.h file.
  56. */
  57. const uint16_t updateInterval = 10;
  58. /**
  59. * @brief Interval in seconds between EEPROM saves
  60. * @details This const value defines what will be the time between each
  61. * EEPROM save cycle, the development team recommends to set this value
  62. * no lower than 3600 secs (1 hour).
  63. */
  64. const uint16_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL;
  65. /**
  66. * @brief Stats were loaded from EERPROM
  67. * @details If set to true it indicates if the statistical data was already
  68. * loaded from the EEPROM.
  69. */
  70. bool loaded = false;
  71. public:
  72. /**
  73. * @brief Class constructor
  74. */
  75. PrintCounter();
  76. /**
  77. * @brief Checks if Print Statistics has been loaded
  78. * @details Returns true if the statistical data has been loaded.
  79. * @return bool
  80. */
  81. bool isLoaded();
  82. /**
  83. * @brief Resets the Print Statistics
  84. * @details Resets the statistics to zero and saves them to EEPROM creating
  85. * also the magic header.
  86. */
  87. void initStats();
  88. /**
  89. * @brief Loads the Print Statistics
  90. * @details Loads the statistics from EEPROM
  91. */
  92. void loadStats();
  93. /**
  94. * @brief Saves the Print Statistics
  95. * @details Saves the statistics to EEPROM
  96. */
  97. void saveStats();
  98. /**
  99. * @brief Serial output the Print Statistics
  100. * @details This function may change in the future, for now it directly
  101. * prints the statistical data to serial.
  102. */
  103. void showStats();
  104. /**
  105. * @brief Loop function
  106. * @details This function should be called at loop, it will take care of
  107. * periodically save the statistical data to EEPROM and do time keeping.
  108. */
  109. void tick();
  110. /**
  111. * The following functions are being overridden
  112. */
  113. void start();
  114. void stop();
  115. void reset();
  116. #if ENABLED(DEBUG_PRINTCOUNTER)
  117. /**
  118. * @brief Prints a debug message
  119. * @details Prints a simple debug message "PrintCounter::function"
  120. */
  121. static void debug(const char func[]);
  122. #endif
  123. };
  124. #endif // PRINTCOUNTER_H