123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
-
- #ifndef MBED_TICKER_H
- #define MBED_TICKER_H
-
- #include "TimerEvent.h"
- #include "FunctionPointer.h"
-
- namespace mbed {
-
-
- class Ticker : public TimerEvent {
-
- public:
- Ticker() : TimerEvent() {
- }
-
- Ticker(const ticker_data_t *data) : TimerEvent(data) {
- }
-
-
-
- void attach(void (*fptr)(void), float t) {
- attach_us(fptr, t * 1000000.0f);
- }
-
-
-
- template<typename T>
- void attach(T* tptr, void (T::*mptr)(void), float t) {
- attach_us(tptr, mptr, t * 1000000.0f);
- }
-
-
-
- void attach_us(void (*fptr)(void), timestamp_t t) {
- _function.attach(fptr);
- setup(t);
- }
-
-
-
- template<typename T>
- void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) {
- _function.attach(tptr, mptr);
- setup(t);
- }
-
- virtual ~Ticker() {
- detach();
- }
-
-
-
- void detach();
-
- protected:
- void setup(timestamp_t t);
- virtual void handler();
-
- protected:
- timestamp_t _delay;
- FunctionPointer _function;
- };
-
- }
-
- #endif
|