Software Serial lib
Dependents: BufferedSoftSerial
Fork of SoftSerial by
SoftSerial_Ticker.h@11:2d4a883a687a, 2015-05-16 (annotated)
- Committer:
- jotaemesousa
- Date:
- Sat May 16 21:40:11 2015 +0000
- Revision:
- 11:2d4a883a687a
- Parent:
- 6:517082212c00
ENC sendong message
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 6:517082212c00 | 1 | //A modified version of the regular ticker/timeout libraries to allow us to do timeout without losing accuracy |
Sissors | 6:517082212c00 | 2 | |
Sissors | 6:517082212c00 | 3 | #ifndef FLEXTICKER_H |
Sissors | 6:517082212c00 | 4 | #define FLEXTICKER_H |
Sissors | 6:517082212c00 | 5 | |
Sissors | 6:517082212c00 | 6 | #include "mbed.h" |
Sissors | 6:517082212c00 | 7 | |
jotaemesousa | 11:2d4a883a687a | 8 | #include "us_ticker_api.h" |
jotaemesousa | 11:2d4a883a687a | 9 | |
Sissors | 6:517082212c00 | 10 | class FlexTicker: public TimerEvent { |
Sissors | 6:517082212c00 | 11 | public: |
Sissors | 6:517082212c00 | 12 | template<typename T> |
Sissors | 6:517082212c00 | 13 | void attach(T* tptr, void (T::*mptr)(void)) { |
Sissors | 6:517082212c00 | 14 | _function.attach(tptr, mptr); |
Sissors | 6:517082212c00 | 15 | } |
Sissors | 6:517082212c00 | 16 | |
Sissors | 6:517082212c00 | 17 | /** Detach the function |
Sissors | 6:517082212c00 | 18 | */ |
Sissors | 6:517082212c00 | 19 | void detach() { |
Sissors | 6:517082212c00 | 20 | remove(); |
Sissors | 6:517082212c00 | 21 | } |
Sissors | 6:517082212c00 | 22 | |
Sissors | 6:517082212c00 | 23 | void setNext(int delay) { |
Sissors | 6:517082212c00 | 24 | insert(event.timestamp + delay); |
Sissors | 6:517082212c00 | 25 | } |
Sissors | 6:517082212c00 | 26 | |
Sissors | 6:517082212c00 | 27 | void prime(void) { |
Sissors | 6:517082212c00 | 28 | event.timestamp = us_ticker_read(); |
Sissors | 6:517082212c00 | 29 | } |
Sissors | 6:517082212c00 | 30 | |
Sissors | 6:517082212c00 | 31 | protected: |
Sissors | 6:517082212c00 | 32 | virtual void handler() { |
Sissors | 6:517082212c00 | 33 | _function.call(); |
Sissors | 6:517082212c00 | 34 | } |
Sissors | 6:517082212c00 | 35 | |
Sissors | 6:517082212c00 | 36 | unsigned int _delay; |
Sissors | 6:517082212c00 | 37 | FunctionPointer _function; |
Sissors | 6:517082212c00 | 38 | }; |
Sissors | 6:517082212c00 | 39 | |
Sissors | 6:517082212c00 | 40 | #endif |