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.

stopwatch.cpp 2.3KB

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