Kenji Arai / SoftSerial_IR

Dependents:   TestVirtualisation Bf_SoftSerial_IR

Revision:
12:79d63607bbb1
Parent:
6:517082212c00
Child:
13:2b5649a1278a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoftSerial_Ticker_IR.h	Mon Dec 17 03:38:12 2018 +0000
@@ -0,0 +1,38 @@
+//A modified version of the regular ticker/timeout libraries to allow us to do timeout without losing accuracy
+
+#ifndef FLEXTICKERIR_H
+#define FLEXTICKERIR_H
+
+#include "mbed.h"
+
+class FlexTicker_IR: public TimerEvent {
+    public:
+    template<typename T>
+    void attach(T* tptr, void (T::*mptr)(void)) {
+        _function.attach(tptr, mptr);
+    }
+ 
+    /** Detach the function
+     */
+    void detach() {
+        remove();
+    }
+    
+    void setNext(int delay) {
+        insert(event.timestamp + delay);
+    }
+    
+    void prime(void) {
+        event.timestamp = us_ticker_read();
+    }
+ 
+protected:
+    virtual void handler() {
+        _function.call();
+    }
+ 
+    unsigned int _delay;
+    FunctionPointer _function;
+};
+
+#endif
\ No newline at end of file