My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

stopwatch.cpp 2.5KB

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