Skip to content

Commit

Permalink
Add ==, != operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ecdr committed Sep 6, 2014
1 parent 6d3c2c3 commit e826474
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion DueTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class DueTimer

double getFrequency();
long getPeriod();

inline __attribute__((always_inline)) bool operator== (const DueTimer& rhs) const
{return timer == rhs.timer; };
inline __attribute__((always_inline)) bool operator!= (const DueTimer& rhs) const
{return timer != rhs.timer; };
};

// Just to call Timer.getAvailable instead of Timer::getAvailable() :
Expand All @@ -93,4 +98,4 @@ extern DueTimer Timer8;

#else
#error Oops! Trying to include DueTimer on another device?
#endif
#endif
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ Timer.getAvailable().attachInterrupt(callback1).start(10);
DueTimer::getAvailable().attachInterrupt(callback2).start(10);
// Start timer on second available timer
// And so on...

DueTimer myTimer = Timer.getAvailable();
if (myTimer != DueTimer(0))
// Now we know that the timer returned is actually available
// Can compare timers using == or !=

```
### Compatibility with Servo.h
Expand Down Expand Up @@ -104,7 +110,7 @@ You will need uncommend the line in `DueTimer.h` in `DueTimer` folder inside the
### You don't need to know:
- `int timer` - Stores the object timer id (to acces Timers struct array).
- `int timer` - Stores the object timer id (to access Timers struct array).
- `DueTimer(int _timer)` - Instantiate a new DueTimer object for Timer _timer (NOTE: All objects are already instantiated!).
Expand Down

0 comments on commit e826474

Please sign in to comment.