Skip to content

Commit 9430a39

Browse files
committed
Fix one-shot mode in resetToNeverExpires(). Add convenient stop() synonym for same function.
1 parent 1d68d42 commit 9430a39

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cores/esp8266/PolledTimeout.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class timeoutTemplate
175175

176176
bool canWait () const
177177
{
178-
return !(_timeout == 0 || _oneShotExpired);
178+
return _timeout != 0 && (PeriodicT || !_oneShotExpired);
179179
}
180180

181181
// Resets, will trigger after this new timeout.
@@ -192,7 +192,7 @@ class timeoutTemplate
192192
void reset()
193193
{
194194
_start = TimePolicyT::time();
195-
_oneShotExpired = false;
195+
if (!PeriodicT) _oneShotExpired = false;
196196
}
197197

198198
// Resets to just expired so that on next poll the check will immediately trigger for the user,
@@ -216,6 +216,12 @@ class timeoutTemplate
216216
{
217217
_timeout = 1; // because canWait() has precedence
218218
_neverExpires = true;
219+
if (!PeriodicT) _oneShotExpired = false;
220+
}
221+
222+
void stop()
223+
{
224+
resetToNeverExpires();
219225
}
220226

221227
timeType getTimeout() const
@@ -246,7 +252,7 @@ class timeoutTemplate
246252
{
247253
// canWait() is not checked here
248254
// returns "oneshot has expired", otherwise returns "can expire" and "time has expired"
249-
return _oneShotExpired || (!_neverExpires && ((internalUnit - _start) >= _timeout));
255+
return !_neverExpires && ((!PeriodicT && _oneShotExpired) || ((internalUnit - _start) >= _timeout));
250256
}
251257

252258
protected:
@@ -274,7 +280,7 @@ class timeoutTemplate
274280
if (!canWait()) return true;
275281
if (checkExpired(TimePolicyT::time()))
276282
{
277-
_oneShotExpired = true;
283+
if (!PeriodicT) _oneShotExpired = true;
278284
return true;
279285
}
280286
return false;

0 commit comments

Comments
 (0)