My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

printcounter.h 4.3KB

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