-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,19 @@ | ||
#ifndef __FEATHERLIB_TRIGGER_H | ||
#define __FEATHERLIB_TRIGGER_H | ||
|
||
|
||
// A Trigger returns true if enough time has passed. | ||
class Trigger { | ||
public: | ||
Trigger(unsigned long delta) : next(0), delta(delta) {} | ||
Trigger(unsigned long delta, bool skipFirst); | ||
bool ready(); | ||
bool ready(unsigned long now); | ||
|
||
private: | ||
unsigned long next; | ||
unsigned long delta; | ||
}; | ||
|
||
|
||
#endif // __FEATHERLIB_TRIGGER_H |
This file contains 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,32 @@ | ||
#include <Arduino.h> | ||
|
||
#include <feather/trigger.h> | ||
|
||
|
||
Trigger::Trigger(unsigned long delta, bool skipFirst) | ||
{ | ||
this->next = 0; | ||
this->delta = delta; | ||
if (skipFirst) { | ||
this->next = millis() + delta; | ||
} | ||
} | ||
|
||
|
||
bool | ||
Trigger::ready() | ||
{ | ||
return this->ready(millis()); | ||
} | ||
|
||
|
||
bool | ||
Trigger::ready(unsigned long now) | ||
{ | ||
if (this->next < now) { | ||
this->next = now + this->delta; | ||
return true; | ||
} | ||
|
||
return false; | ||
} |