Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
bhepp
Date:
Tue Nov 24 16:41:23 2015 +0000
Revision:
48:5999e510f154
Child:
50:50b8aea54a51
Multiple Receivers implemented

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhepp 48:5999e510f154 1 #pragma once
bhepp 48:5999e510f154 2
bhepp 48:5999e510f154 3 #include "mbed.h"
bhepp 48:5999e510f154 4 #include <vector>
bhepp 48:5999e510f154 5 #include <utility>
bhepp 48:5999e510f154 6
bhepp 48:5999e510f154 7 //#include "PC.h"
bhepp 48:5999e510f154 8 //static PC _pc(USBTX, USBRX, 115200); // USB UART Terminal
bhepp 48:5999e510f154 9
bhepp 48:5999e510f154 10 class InterruptMultiplexer {
bhepp 48:5999e510f154 11 public:
bhepp 48:5999e510f154 12 void enable(int index) {
bhepp 48:5999e510f154 13 // _pc.printf("Enabled %d\r\n", index);
bhepp 48:5999e510f154 14 isr_array[index].second = true;
bhepp 48:5999e510f154 15 }
bhepp 48:5999e510f154 16
bhepp 48:5999e510f154 17 void disable(int index) {
bhepp 48:5999e510f154 18 // _pc.printf("Disabled %d\r\n", index);
bhepp 48:5999e510f154 19 isr_array[index].second = false;
bhepp 48:5999e510f154 20 }
bhepp 48:5999e510f154 21
bhepp 48:5999e510f154 22 void trigger() {
bhepp 48:5999e510f154 23 // _pc.printf("Trigger\r\n");
bhepp 48:5999e510f154 24 for (int i = 0; i < isr_array.size(); ++i) {
bhepp 48:5999e510f154 25 bool enable = isr_array[i].second;
bhepp 48:5999e510f154 26 if (enable) {
bhepp 48:5999e510f154 27 FunctionPointer& fptr = isr_array[i].first;
bhepp 48:5999e510f154 28 fptr.call();
bhepp 48:5999e510f154 29 }
bhepp 48:5999e510f154 30 }
bhepp 48:5999e510f154 31 // _pc.printf("Trigger stop\r\n");
bhepp 48:5999e510f154 32 }
bhepp 48:5999e510f154 33
bhepp 48:5999e510f154 34 int addISR(void (*isr)(void), bool enable = true) {
bhepp 48:5999e510f154 35 FunctionPointer fptr;
bhepp 48:5999e510f154 36 fptr.attach(isr);
bhepp 48:5999e510f154 37 isr_array.push_back(std::make_pair(fptr, enable));
bhepp 48:5999e510f154 38 return isr_array.size() - 1;
bhepp 48:5999e510f154 39 }
bhepp 48:5999e510f154 40
bhepp 48:5999e510f154 41 template <typename T>
bhepp 48:5999e510f154 42 int addISR(T* tptr, void (T::*isr)(void), bool enable = true) {
bhepp 48:5999e510f154 43 FunctionPointer fptr;
bhepp 48:5999e510f154 44 fptr.attach(tptr, isr);
bhepp 48:5999e510f154 45 isr_array.push_back(std::make_pair(fptr, enable));
bhepp 48:5999e510f154 46 return isr_array.size() - 1;
bhepp 48:5999e510f154 47 }
bhepp 48:5999e510f154 48
bhepp 48:5999e510f154 49 private:
bhepp 48:5999e510f154 50 std::vector<std::pair<FunctionPointer, bool> > isr_array;
bhepp 48:5999e510f154 51 };