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.8KB

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