@@ -44,7 +44,9 @@ class Timer {
4444 * @param on_timeout function to be executed on timeout
4545 */
4646 Timer (handler_t on_timeout)
47- : on_timeout_{on_timeout}, running_{false } {}
47+ : id_{Timers::UNUSED_ID},
48+ on_timeout_{on_timeout}
49+ {}
4850
4951 /* *
5052 * @brief Start the timer with a timeout duration
@@ -88,7 +90,7 @@ class Timer {
8890 * @return Wether the timer is running or not
8991 */
9092 bool is_running () const
91- { return running_ ; }
93+ { return id_ != Timers::UNUSED_ID ; }
9294
9395 /* *
9496 * @brief Destroys the Timer
@@ -109,8 +111,6 @@ class Timer {
109111 Timers::id_t id_;
110112 /* * Function to execute on timeout */
111113 handler_t on_timeout_;
112- /* * Wether the timer is running or not */
113- bool running_;
114114
115115 /* *
116116 * @brief Sets the timer to inactive before calling the user callback
@@ -127,16 +127,17 @@ class Timer {
127127} __attribute__((packed)); // < class Timer
128128
129129inline void Timer::start (duration_t when) {
130- if (!running_) {
130+ if (!is_running ())
131+ {
131132 id_ = Timers::oneshot (when, {this , &Timer::_internal_timeout});
132- running_ = true ;
133133 }
134134}
135135
136136inline void Timer::stop () {
137- if (running_) {
137+ if (is_running ())
138+ {
138139 Timers::stop (id_);
139- running_ = false ;
140+ id_ = Timers::UNUSED_ID ;
140141 }
141142}
142143
@@ -146,7 +147,7 @@ inline void Timer::restart(duration_t when) {
146147}
147148
148149inline void Timer::_internal_timeout (id_t id) {
149- running_ = false ;
150+ id_ = Timers::UNUSED_ID ;
150151 on_timeout_ (id);
151152}
152153
0 commit comments