My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

printcounter.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "Marlin.h"
  23. #include "printcounter.h"
  24. #include <avr/eeprom.h>
  25. PrintCounter::PrintCounter(): super() {}
  26. void PrintCounter::tick() {
  27. if (!this->isRunning()) return;
  28. static uint32_t update_before = millis(),
  29. eeprom_before = millis();
  30. uint32_t now = millis();
  31. // Trying to get the amount of calculations down to the bare min
  32. const static uint16_t i = this->updateInterval * 1000;
  33. if (now - update_before >= i) {
  34. //this->addToTimeCounter((uint16_t) (now - update_before) / 1000);
  35. update_before = now;
  36. PrintCounter::debug(PSTR("tick1"));
  37. }
  38. // Trying to get the amount of calculations down to the bare min
  39. const static uint16_t j = this->saveInterval * 1000;
  40. if (now - eeprom_before >= j) {
  41. eeprom_before = now;
  42. this->save();
  43. }
  44. }
  45. void PrintCounter::load() {
  46. uint16_t pos = this->addr;
  47. this->data.successPrints= eeprom_read_word ((uint16_t*) pos);
  48. this->data.failedPrints = eeprom_read_word ((uint16_t*) pos);
  49. this->data.printTime = eeprom_read_dword((uint32_t*) pos);
  50. this->data.longestPrint = eeprom_read_dword((uint32_t*) pos);
  51. SERIAL_ECHOPGM("successPrints: ");
  52. SERIAL_ECHOLN(this->data.successPrints);
  53. SERIAL_ECHOPGM("failedPrints: ");
  54. SERIAL_ECHOLN(this->data.failedPrints);
  55. SERIAL_ECHOPGM("printTime: ");
  56. SERIAL_ECHOLN(this->data.printTime);
  57. SERIAL_ECHOPGM("longestPrint: ");
  58. SERIAL_ECHOLN(this->data.longestPrint);
  59. }
  60. void PrintCounter::save() {
  61. #if ENABLED(DEBUG_PRINTCOUNTER)
  62. PrintCounter::debug(PSTR("save"));
  63. #endif
  64. uint16_t pos = this->addr;
  65. eeprom_write_word ((uint16_t*) pos, this->data.successPrints);
  66. eeprom_write_word ((uint16_t*) pos, this->data.failedPrints);
  67. eeprom_write_dword((uint32_t*) pos, this->data.printTime);
  68. eeprom_write_dword((uint32_t*) pos, this->data.longestPrint);
  69. }
  70. void PrintCounter::start() {
  71. super::start();
  72. this->load();
  73. }
  74. void PrintCounter::stop() {
  75. super::stop();
  76. this->save();
  77. }
  78. #if ENABLED(DEBUG_PRINTCOUNTER)
  79. void PrintCounter::debug(const char func[]) {
  80. if (DEBUGGING(INFO)) {
  81. SERIAL_ECHOPGM("PrintCounter::");
  82. serialprintPGM(func);
  83. SERIAL_ECHOLNPGM("()");
  84. }
  85. }
  86. #endif