From e8264746791c57a088f84c28f55d1df42d710b45 Mon Sep 17 00:00:00 2001 From: ecdr Date: Sat, 6 Sep 2014 15:01:44 -0700 Subject: [PATCH] Add ==, != operators --- DueTimer.h | 7 ++++++- README.md | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/DueTimer.h b/DueTimer.h index dbbf11a..bb95444 100644 --- a/DueTimer.h +++ b/DueTimer.h @@ -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() : @@ -93,4 +98,4 @@ extern DueTimer Timer8; #else #error Oops! Trying to include DueTimer on another device? -#endif \ No newline at end of file +#endif diff --git a/README.md b/README.md index c08de82..43ffcf6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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!).