Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Revision:
48:5999e510f154
Child:
50:50b8aea54a51
diff -r b6120c152ad1 -r 5999e510f154 InterruptMultiplexer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/InterruptMultiplexer.h	Tue Nov 24 16:41:23 2015 +0000
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "mbed.h"
+#include <vector>
+#include <utility>
+
+//#include "PC.h"
+//static PC _pc(USBTX, USBRX, 115200);           // USB UART Terminal
+
+class InterruptMultiplexer {
+public:
+    void enable(int index) {
+//        _pc.printf("Enabled %d\r\n", index);
+        isr_array[index].second = true;
+    }
+
+    void disable(int index) {
+//        _pc.printf("Disabled %d\r\n", index);
+        isr_array[index].second = false;
+    }
+
+    void trigger() {
+//        _pc.printf("Trigger\r\n");
+        for (int i = 0; i < isr_array.size(); ++i) {
+            bool enable = isr_array[i].second;
+            if (enable) {
+                FunctionPointer& fptr = isr_array[i].first;
+                fptr.call();
+            }
+        }
+//        _pc.printf("Trigger stop\r\n");
+    }
+
+    int addISR(void (*isr)(void), bool enable = true) {
+        FunctionPointer fptr;
+        fptr.attach(isr);
+        isr_array.push_back(std::make_pair(fptr, enable));
+        return isr_array.size() - 1;
+    }
+
+    template <typename T>
+    int addISR(T* tptr, void (T::*isr)(void), bool enable = true) {
+        FunctionPointer fptr;
+        fptr.attach(tptr, isr);
+        isr_array.push_back(std::make_pair(fptr, enable));
+        return isr_array.size() - 1;
+    }
+
+private:
+    std::vector<std::pair<FunctionPointer, bool> > isr_array;
+};