Skip to content

Commit 0824c66

Browse files
committed
Fix one-shot mode in resetToNeverExpires(). Add convenient stop() synonym for same function.
1 parent 66c00c1 commit 0824c66

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cores/esp8266/PolledTimeout.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class timeoutTemplate
176176

177177
bool canWait () const
178178
{
179-
return !(_timeout == 0 || _oneShotExpired);
179+
return _timeout != 0 && (PeriodicT || !_oneShotExpired);
180180
}
181181

182182
// Resets, will trigger after this new timeout.
@@ -193,7 +193,7 @@ class timeoutTemplate
193193
void reset()
194194
{
195195
_start = TimePolicyT::time();
196-
_oneShotExpired = false;
196+
if (!PeriodicT) _oneShotExpired = false;
197197
}
198198

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

222228
timeType getTimeout() const
@@ -247,7 +253,7 @@ class timeoutTemplate
247253
{
248254
// canWait() is not checked here
249255
// returns "oneshot has expired", otherwise returns "can expire" and "time has expired"
250-
return _oneShotExpired || (!_neverExpires && ((internalUnit - _start) >= _timeout));
256+
return !_neverExpires && ((!PeriodicT && _oneShotExpired) || ((internalUnit - _start) >= _timeout));
251257
}
252258

253259
protected:
@@ -275,7 +281,7 @@ class timeoutTemplate
275281
if (!canWait()) return true;
276282
if (checkExpired(TimePolicyT::time()))
277283
{
278-
_oneShotExpired = true;
284+
if (!PeriodicT) _oneShotExpired = true;
279285
return true;
280286
}
281287
return false;

0 commit comments

Comments
 (0)