Skip to content

Commit e826474

Browse files
committed
Add ==, != operators
1 parent 6d3c2c3 commit e826474

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

DueTimer.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class DueTimer
7171

7272
double getFrequency();
7373
long getPeriod();
74+
75+
inline __attribute__((always_inline)) bool operator== (const DueTimer& rhs) const
76+
{return timer == rhs.timer; };
77+
inline __attribute__((always_inline)) bool operator!= (const DueTimer& rhs) const
78+
{return timer != rhs.timer; };
7479
};
7580

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

9499
#else
95100
#error Oops! Trying to include DueTimer on another device?
96-
#endif
101+
#endif

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ Timer.getAvailable().attachInterrupt(callback1).start(10);
6868
DueTimer::getAvailable().attachInterrupt(callback2).start(10);
6969
// Start timer on second available timer
7070
// And so on...
71+
72+
DueTimer myTimer = Timer.getAvailable();
73+
if (myTimer != DueTimer(0))
74+
// Now we know that the timer returned is actually available
75+
// Can compare timers using == or !=
76+
7177
```
7278
7379
### Compatibility with Servo.h
@@ -104,7 +110,7 @@ You will need uncommend the line in `DueTimer.h` in `DueTimer` folder inside the
104110
105111
### You don't need to know:
106112
107-
- `int timer` - Stores the object timer id (to acces Timers struct array).
113+
- `int timer` - Stores the object timer id (to access Timers struct array).
108114
109115
- `DueTimer(int _timer)` - Instantiate a new DueTimer object for Timer _timer (NOTE: All objects are already instantiated!).
110116

0 commit comments

Comments
 (0)