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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <https://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. Stopwatch::debug(PSTR("stop"));
  33. if (isRunning() || isPaused()) {
  34. TERN_(EXTENSIBLE_UI, ExtUI::onPrintTimerStopped());
  35. state = STOPPED;
  36. stopTimestamp = millis();
  37. return true;
  38. }
  39. else return false;
  40. }
  41. bool Stopwatch::pause() {
  42. Stopwatch::debug(PSTR("pause"));
  43. if (isRunning()) {
  44. TERN_(EXTENSIBLE_UI, ExtUI::onPrintTimerPaused());
  45. state = PAUSED;
  46. stopTimestamp = millis();
  47. return true;
  48. }
  49. else return false;
  50. }
  51. bool Stopwatch::start() {
  52. Stopwatch::debug(PSTR("start"));
  53. TERN_(EXTENSIBLE_UI, ExtUI::onPrintTimerStarted());
  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. Stopwatch::debug(PSTR("resume"));
  65. reset();
  66. if ((accumulator = with_time)) state = RUNNING;
  67. }
  68. void Stopwatch::reset() {
  69. Stopwatch::debug(PSTR("reset"));
  70. state = STOPPED;
  71. startTimestamp = 0;
  72. stopTimestamp = 0;
  73. accumulator = 0;
  74. }
  75. millis_t Stopwatch::duration() {
  76. return accumulator + MS_TO_SEC((isRunning() ? millis() : stopTimestamp) - startTimestamp);
  77. }
  78. #if ENABLED(DEBUG_STOPWATCH)
  79. void Stopwatch::debug(const char func[]) {
  80. if (DEBUGGING(INFO)) {
  81. SERIAL_ECHOPGM("Stopwatch::");
  82. serialprintPGM(func);
  83. SERIAL_ECHOLNPGM("()");
  84. }
  85. }
  86. #endif