My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

stopwatch.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #pragma once
  23. // Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
  24. //#define DEBUG_STOPWATCH
  25. #include "../core/macros.h" // for FORCE_INLINE
  26. #include <stdint.h>
  27. typedef uint32_t millis_t;
  28. /**
  29. * @brief Stopwatch class
  30. * @details This class acts as a timer proving stopwatch functionality including
  31. * the ability to pause the running time counter.
  32. */
  33. class Stopwatch {
  34. private:
  35. enum State : char { STOPPED, RUNNING, PAUSED };
  36. static Stopwatch::State state;
  37. static millis_t accumulator;
  38. static millis_t startTimestamp;
  39. static millis_t stopTimestamp;
  40. public:
  41. /**
  42. * @brief Initialize the stopwatch
  43. */
  44. FORCE_INLINE static void init() { reset(); }
  45. /**
  46. * @brief Stop the stopwatch
  47. * @details Stop the running timer, it will silently ignore the request if
  48. * no timer is currently running.
  49. * @return true on success
  50. */
  51. static bool stop();
  52. /**
  53. * @brief Pause the stopwatch
  54. * @details Pause the running timer, it will silently ignore the request if
  55. * no timer is currently running.
  56. * @return true on success
  57. */
  58. static bool pause();
  59. /**
  60. * @brief Start the stopwatch
  61. * @details Start the timer, it will silently ignore the request if the
  62. * timer is already running.
  63. * @return true on success
  64. */
  65. static bool start();
  66. /**
  67. * @brief Resume the stopwatch
  68. * @details Resume a timer from a given duration
  69. */
  70. static void resume(const millis_t with_time);
  71. /**
  72. * @brief Reset the stopwatch
  73. * @details Reset all settings to their default values.
  74. */
  75. static void reset();
  76. /**
  77. * @brief Check if the timer is running
  78. * @details Return true if the timer is currently running, false otherwise.
  79. * @return true if stopwatch is running
  80. */
  81. FORCE_INLINE static bool isRunning() { return state == RUNNING; }
  82. /**
  83. * @brief Check if the timer is paused
  84. * @details Return true if the timer is currently paused, false otherwise.
  85. * @return true if stopwatch is paused
  86. */
  87. FORCE_INLINE static bool isPaused() { return state == PAUSED; }
  88. /**
  89. * @brief Get the running time
  90. * @details Return the total number of seconds the timer has been running.
  91. * @return the delta since starting the stopwatch
  92. */
  93. static millis_t duration();
  94. #ifdef DEBUG_STOPWATCH
  95. /**
  96. * @brief Print a debug message
  97. * @details Print a simple debug message "Stopwatch::function"
  98. */
  99. static void debug(const char func[]);
  100. #endif
  101. };