Sfoglia il codice sorgente

Add Stopwatch::resume method

Scott Lahteine 7 anni fa
parent
commit
2f4b4d6076
2 ha cambiato i file con 26 aggiunte e 19 eliminazioni
  1. 10
    9
      Marlin/src/libs/stopwatch.cpp
  2. 16
    10
      Marlin/src/libs/stopwatch.h

+ 10
- 9
Marlin/src/libs/stopwatch.cpp Vedi File

71
   else return false;
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
 void Stopwatch::reset() {
83
 void Stopwatch::reset() {
75
   #if ENABLED(DEBUG_STOPWATCH)
84
   #if ENABLED(DEBUG_STOPWATCH)
76
     Stopwatch::debug(PSTR("reset"));
85
     Stopwatch::debug(PSTR("reset"));
82
   accumulator = 0;
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
 millis_t Stopwatch::duration() {
94
 millis_t Stopwatch::duration() {
94
-  return (((isRunning()) ? millis() : stopTimestamp)
95
+  return ((isRunning() ? millis() : stopTimestamp)
95
           - startTimestamp) / 1000UL + accumulator;
96
           - startTimestamp) / 1000UL + accumulator;
96
 }
97
 }
97
 
98
 

+ 16
- 10
Marlin/src/libs/stopwatch.h Vedi File

54
     FORCE_INLINE static void init() { reset(); }
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
     static bool stop();
62
     static bool stop();
63
 
63
 
64
     /**
64
     /**
65
      * @brief Pause the stopwatch
65
      * @brief Pause the stopwatch
66
      * @details Pause the running timer, it will silently ignore the request if
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
     static bool pause();
70
     static bool pause();
71
 
71
 
72
     /**
72
     /**
73
      * @brief Start the stopwatch
73
      * @brief Start the stopwatch
74
      * @details Start the timer, it will silently ignore the request if the
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
     static bool start();
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
      * @brief Reset the stopwatch
87
      * @brief Reset the stopwatch
82
      * @details Reset all settings to their default values.
88
      * @details Reset all settings to their default values.
83
      */
89
      */
88
      * @details Return true if the timer is currently running, false otherwise.
94
      * @details Return true if the timer is currently running, false otherwise.
89
      * @return true if stopwatch is running
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
      * @brief Check if the timer is paused
100
      * @brief Check if the timer is paused
95
      * @details Return true if the timer is currently paused, false otherwise.
101
      * @details Return true if the timer is currently paused, false otherwise.
96
      * @return true if stopwatch is paused
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
      * @brief Get the running time
107
      * @brief Get the running time

Loading…
Annulla
Salva