My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

stopwatch.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef STOPWATCH_H
  23. #define STOPWATCH_H
  24. #include "macros.h"
  25. // Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
  26. //#define DEBUG_STOPWATCH
  27. enum StopwatchState {
  28. STPWTCH_STOPPED,
  29. STPWTCH_RUNNING,
  30. STPWTCH_PAUSED
  31. };
  32. /**
  33. * @brief Stopwatch class
  34. * @details This class acts as a timer proving stopwatch functionality including
  35. * the ability to pause the running time counter.
  36. */
  37. class Stopwatch {
  38. private:
  39. StopwatchState state;
  40. uint16_t accumulator;
  41. uint32_t startTimestamp;
  42. uint32_t stopTimestamp;
  43. public:
  44. /**
  45. * @brief Class constructor
  46. */
  47. Stopwatch();
  48. /**
  49. * @brief Stops the stopwatch
  50. * @details Stops the running timer, it will silently ignore the request if
  51. * no timer is currently running.
  52. */
  53. void stop();
  54. /**
  55. * @brief Pauses the stopwatch
  56. * @details Pauses the running timer, it will silently ignore the request if
  57. * no timer is currently running.
  58. */
  59. void pause();
  60. /**
  61. * @brief Starts the stopwatch
  62. * @details Starts the timer, it will silently ignore the request if the
  63. * timer is already running.
  64. */
  65. void start();
  66. /**
  67. * @brief Resets the stopwatch
  68. * @details Resets all settings to their default values.
  69. */
  70. void reset();
  71. /**
  72. * @brief Checks if the timer is running
  73. * @details Returns true if the timer is currently running, false otherwise.
  74. * @return bool
  75. */
  76. bool isRunning();
  77. /**
  78. * @brief Checks if the timer is paused
  79. * @details Returns true if the timer is currently paused, false otherwise.
  80. * @return bool
  81. */
  82. bool isPaused();
  83. /**
  84. * @brief Gets the running time
  85. * @details Returns the total number of seconds the timer has been running.
  86. * @return uint16_t
  87. */
  88. uint16_t duration();
  89. #if ENABLED(DEBUG_STOPWATCH)
  90. /**
  91. * @brief Prints a debug message
  92. * @details Prints a simple debug message "Stopwatch::function"
  93. */
  94. static void debug(const char func[]);
  95. #endif
  96. };
  97. #endif //STOPWATCH_H