My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

stopwatch.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "stopwatch.h"
  24. Stopwatch::Stopwatch() {
  25. this->reset();
  26. }
  27. bool Stopwatch::stop() {
  28. #if ENABLED(DEBUG_STOPWATCH)
  29. Stopwatch::debug(PSTR("stop"));
  30. #endif
  31. if (this->isRunning() || this->isPaused()) {
  32. this->state = STOPWATCH_STOPPED;
  33. this->stopTimestamp = millis();
  34. return true;
  35. }
  36. else return false;
  37. }
  38. bool Stopwatch::pause() {
  39. #if ENABLED(DEBUG_STOPWATCH)
  40. Stopwatch::debug(PSTR("pause"));
  41. #endif
  42. if (this->isRunning()) {
  43. this->state = STOPWATCH_PAUSED;
  44. this->stopTimestamp = millis();
  45. return true;
  46. }
  47. else return false;
  48. }
  49. bool Stopwatch::start() {
  50. #if ENABLED(DEBUG_STOPWATCH)
  51. Stopwatch::debug(PSTR("start"));
  52. #endif
  53. if (!this->isRunning()) {
  54. if (this->isPaused()) this->accumulator = this->duration();
  55. else this->reset();
  56. this->state = STOPWATCH_RUNNING;
  57. this->startTimestamp = millis();
  58. return true;
  59. }
  60. else return false;
  61. }
  62. void Stopwatch::reset() {
  63. #if ENABLED(DEBUG_STOPWATCH)
  64. Stopwatch::debug(PSTR("reset"));
  65. #endif
  66. this->state = STOPWATCH_STOPPED;
  67. this->startTimestamp = 0;
  68. this->stopTimestamp = 0;
  69. this->accumulator = 0;
  70. }
  71. bool Stopwatch::isRunning() {
  72. return (this->state == STOPWATCH_RUNNING) ? true : false;
  73. }
  74. bool Stopwatch::isPaused() {
  75. return (this->state == STOPWATCH_PAUSED) ? true : false;
  76. }
  77. millis_t Stopwatch::duration() {
  78. return (((this->isRunning()) ? millis() : this->stopTimestamp)
  79. - this->startTimestamp) / 1000UL + this->accumulator;
  80. }
  81. #if ENABLED(DEBUG_STOPWATCH)
  82. void Stopwatch::debug(const char func[]) {
  83. if (DEBUGGING(INFO)) {
  84. SERIAL_ECHOPGM("Stopwatch::");
  85. serialprintPGM(func);
  86. SERIAL_ECHOLNPGM("()");
  87. }
  88. }
  89. #endif