소스 검색

Add Stopwatch::resume method

Scott Lahteine 7 년 전
부모
커밋
2f4b4d6076
2개의 변경된 파일26개의 추가작업 그리고 19개의 파일을 삭제
  1. 10
    9
      Marlin/src/libs/stopwatch.cpp
  2. 16
    10
      Marlin/src/libs/stopwatch.h

+ 10
- 9
Marlin/src/libs/stopwatch.cpp 파일 보기

@@ -71,6 +71,15 @@ bool Stopwatch::start() {
71 71
   else return false;
72 72
 }
73 73
 
74
+void Stopwatch::resume(const millis_t duration) {
75
+  #if ENABLED(DEBUG_STOPWATCH)
76
+    Stopwatch::debug(PSTR("resume"));
77
+  #endif
78
+
79
+  reset();
80
+  if ((accumulator = duration)) state = RUNNING;
81
+}
82
+
74 83
 void Stopwatch::reset() {
75 84
   #if ENABLED(DEBUG_STOPWATCH)
76 85
     Stopwatch::debug(PSTR("reset"));
@@ -82,16 +91,8 @@ void Stopwatch::reset() {
82 91
   accumulator = 0;
83 92
 }
84 93
 
85
-bool Stopwatch::isRunning() {
86
-  return (state == RUNNING) ? true : false;
87
-}
88
-
89
-bool Stopwatch::isPaused() {
90
-  return (state == PAUSED) ? true : false;
91
-}
92
-
93 94
 millis_t Stopwatch::duration() {
94
-  return (((isRunning()) ? millis() : stopTimestamp)
95
+  return ((isRunning() ? millis() : stopTimestamp)
95 96
           - startTimestamp) / 1000UL + accumulator;
96 97
 }
97 98
 

+ 16
- 10
Marlin/src/libs/stopwatch.h 파일 보기

@@ -54,30 +54,36 @@ class Stopwatch {
54 54
     FORCE_INLINE static void init() { reset(); }
55 55
 
56 56
     /**
57
-     * @brief Stops the stopwatch
58
-     * @details Stops the running timer, it will silently ignore the request if
59
-     * no timer is currently running.
60
-     * @return true is method was successful
57
+     * @brief Stop the stopwatch
58
+     * @details Stop the running timer, it will silently ignore the request if
59
+     *          no timer is currently running.
60
+     * @return true on success
61 61
      */
62 62
     static bool stop();
63 63
 
64 64
     /**
65 65
      * @brief Pause the stopwatch
66 66
      * @details Pause the running timer, it will silently ignore the request if
67
-     * no timer is currently running.
68
-     * @return true is method was successful
67
+     *          no timer is currently running.
68
+     * @return true on success
69 69
      */
70 70
     static bool pause();
71 71
 
72 72
     /**
73 73
      * @brief Start the stopwatch
74 74
      * @details Start the timer, it will silently ignore the request if the
75
-     * timer is already running.
76
-     * @return true is method was successful
75
+     *          timer is already running.
76
+     * @return true on success
77 77
      */
78 78
     static bool start();
79 79
 
80 80
     /**
81
+     * @brief Resume the stopwatch
82
+     * @details Resume a timer from a given duration
83
+     */
84
+    static void resume(const millis_t duration);
85
+
86
+    /**
81 87
      * @brief Reset the stopwatch
82 88
      * @details Reset all settings to their default values.
83 89
      */
@@ -88,14 +94,14 @@ class Stopwatch {
88 94
      * @details Return true if the timer is currently running, false otherwise.
89 95
      * @return true if stopwatch is running
90 96
      */
91
-    static bool isRunning();
97
+    FORCE_INLINE static bool isRunning() { return state == RUNNING; }
92 98
 
93 99
     /**
94 100
      * @brief Check if the timer is paused
95 101
      * @details Return true if the timer is currently paused, false otherwise.
96 102
      * @return true if stopwatch is paused
97 103
      */
98
-    static bool isPaused();
104
+    FORCE_INLINE static bool isPaused() { return state == PAUSED; }
99 105
 
100 106
     /**
101 107
      * @brief Get the running time

Loading…
취소
저장