-
Notifications
You must be signed in to change notification settings - Fork 13.3k
PolledTimeout Class for wrapping millis() loops (WIP) #5198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f43c43c
PolledTimeout Class for wrapping millis() loops
devyte ee21eb7
Merge branch 'master' into polledTimeout
devyte 0f08567
Merge branch 'master' into polledTimeout
earlephilhower 66b171d
Merge remote-tracking branch 'origin' into polledTimeout
devyte ff36ff4
Merge branch 'polledTimeout' of https://github.com/devyte/Arduino int…
devyte 5d0ca40
Add yield policies, improve reset, add host tests
devyte 3e02cce
Merge branch 'master' into polledTimeout
devyte 126abe1
Fix copyright, comments
devyte b0250fd
Merge branch 'polledTimeout' of https://github.com/devyte/Arduino int…
devyte 497d08a
Merge branch 'master' into polledTimeout
devyte bdf9223
adjust host tests for better time precision
devyte 536a37d
Merge branch 'polledTimeout' of https://github.com/devyte/Arduino int…
devyte 54a187d
add fuzzyness to timing tests for CI jitter
devyte c15c76c
add blink example with polledTimeout
devyte 9ca90bb
improve namespace and type naming, add copyright, comments
devyte e09e8c8
fix astyle
devyte 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
Next
Next commit
PolledTimeout Class for wrapping millis() loops
- Loading branch information
commit f43c43c321c587d5117ef68fac41a7f6a44759d2
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#ifndef __POLLEDTIMING_H__ | ||
#define __POLLEDTIMING_H__ | ||
|
||
namespace esp8266 | ||
{ | ||
|
||
template<bool PeriodicT> | ||
class polledTimeout | ||
{ | ||
public: | ||
using timeType = unsigned int; | ||
|
||
polledTimeout(timeType timeout) | ||
: _timeout(timeout), _start(millis()) | ||
{} | ||
|
||
bool expired() | ||
{ | ||
if(PeriodicT) | ||
return expiredRetrigger(); | ||
return expiredOneShot(); | ||
} | ||
|
||
operator bool() | ||
{ | ||
return expired(); | ||
902B | } | |
|
||
bool reset() | ||
{ | ||
_start = millis(); | ||
} | ||
|
||
protected: | ||
bool checkExpired(timeType t) const | ||
{ | ||
return (t - _start) >= _timeout; | ||
} | ||
|
||
bool expiredRetrigger() | ||
{ | ||
timeType current = millis(); | ||
if(checkExpired(current)) | ||
{ | ||
unsigned int n = (current - _start) / _timeout; //how many _timeouts periods have elapsed, will usually be 1 (current - _start >= _timeout) | ||
_start += n * _timeout; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool expiredOneShot() const | ||
{ | ||
return checkExpired(millis()); | ||
} | ||
|
||
timeType _timeout; | ||
timeType _start; | ||
}; | ||
|
||
|
||
using polledTimeoutOneShot = polledTimeout<false>; | ||
using polledTimeoutPeriodic = polledTimeout<true>; | ||
|
||
|
||
}//esp8266 | ||
|
||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.