Junichi Katsu
/
MilkcocoaSampleESP8266_Temp
ワークショップ用のプログラム
SoftSerialSendOnly/SoftSerial_Ticker.h@0:d0b3a5d1ba28, 2016-09-22 (annotated)
- Committer:
- jksoft
- Date:
- Thu Sep 22 00:49:42 2016 +0000
- Revision:
- 0:d0b3a5d1ba28
????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:d0b3a5d1ba28 | 1 | //A modified version of the regular ticker/timeout libraries to allow us to do timeout without losing accuracy |
jksoft | 0:d0b3a5d1ba28 | 2 | |
jksoft | 0:d0b3a5d1ba28 | 3 | #ifndef FLEXTICKER_H |
jksoft | 0:d0b3a5d1ba28 | 4 | #define FLEXTICKER_H |
jksoft | 0:d0b3a5d1ba28 | 5 | |
jksoft | 0:d0b3a5d1ba28 | 6 | #include "mbed.h" |
jksoft | 0:d0b3a5d1ba28 | 7 | |
jksoft | 0:d0b3a5d1ba28 | 8 | class FlexTicker: public TimerEvent { |
jksoft | 0:d0b3a5d1ba28 | 9 | public: |
jksoft | 0:d0b3a5d1ba28 | 10 | template<typename T> |
jksoft | 0:d0b3a5d1ba28 | 11 | void attach(T* tptr, void (T::*mptr)(void)) { |
jksoft | 0:d0b3a5d1ba28 | 12 | _function.attach(tptr, mptr); |
jksoft | 0:d0b3a5d1ba28 | 13 | } |
jksoft | 0:d0b3a5d1ba28 | 14 | |
jksoft | 0:d0b3a5d1ba28 | 15 | /** Detach the function |
jksoft | 0:d0b3a5d1ba28 | 16 | */ |
jksoft | 0:d0b3a5d1ba28 | 17 | void detach() { |
jksoft | 0:d0b3a5d1ba28 | 18 | remove(); |
jksoft | 0:d0b3a5d1ba28 | 19 | } |
jksoft | 0:d0b3a5d1ba28 | 20 | |
jksoft | 0:d0b3a5d1ba28 | 21 | void setNext(int delay) { |
jksoft | 0:d0b3a5d1ba28 | 22 | insert(event.timestamp + delay); |
jksoft | 0:d0b3a5d1ba28 | 23 | } |
jksoft | 0:d0b3a5d1ba28 | 24 | |
jksoft | 0:d0b3a5d1ba28 | 25 | void prime(void) { |
jksoft | 0:d0b3a5d1ba28 | 26 | event.timestamp = us_ticker_read(); |
jksoft | 0:d0b3a5d1ba28 | 27 | } |
jksoft | 0:d0b3a5d1ba28 | 28 | |
jksoft | 0:d0b3a5d1ba28 | 29 | protected: |
jksoft | 0:d0b3a5d1ba28 | 30 | virtual void handler() { |
jksoft | 0:d0b3a5d1ba28 | 31 | _function.call(); |
jksoft | 0:d0b3a5d1ba28 | 32 | } |
jksoft | 0:d0b3a5d1ba28 | 33 | |
jksoft | 0:d0b3a5d1ba28 | 34 | unsigned int _delay; |
jksoft | 0:d0b3a5d1ba28 | 35 | FunctionPointer _function; |
jksoft | 0:d0b3a5d1ba28 | 36 | }; |
jksoft | 0:d0b3a5d1ba28 | 37 | |
jksoft | 0:d0b3a5d1ba28 | 38 | #endif |