Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix one-shot mode in resetToNeverExpires(). Add convenient stop() syn…
…onym for same function.
  • Loading branch information
dok-net committed Apr 5, 2021
commit 9430a39bcd5db67c672c2a681bdb835cc178ef61
14 changes: 10 additions & 4 deletions cores/esp8266/PolledTimeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class timeoutTemplate

bool canWait () const
{
return !(_timeout == 0 || _oneShotExpired);
return _timeout != 0 && (PeriodicT || !_oneShotExpired);
}

// Resets, will trigger after this new timeout.
Expand All @@ -192,7 +192,7 @@ class timeoutTemplate
void reset()
{
_start = TimePolicyT::time();
_oneShotExpired = false;
if (!PeriodicT) _oneShotExpired = false;
}

// Resets to just expired so that on next poll the check will immediately trigger for the user,
Expand All @@ -216,6 +216,12 @@ class timeoutTemplate
{
_timeout = 1; // because canWait() has precedence
_neverExpires = true;
if (!PeriodicT) _oneShotExpired = false;
}

void stop()
{
resetToNeverExpires();
}

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

protected:
Expand Down Expand Up @@ -274,7 +280,7 @@ class timeoutTemplate
if (!canWait()) return true;
if (checkExpired(TimePolicyT::time()))
{
_oneShotExpired = true;
if (!PeriodicT) _oneShotExpired = true;
return true;
}
return false;
Expand Down