Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
bhepp
Date:
Thu Nov 26 21:42:51 2015 +0000
Revision:
50:50b8aea54a51
Parent:
48:5999e510f154
Child:
52:94688f414dcd
Multiple receiver basically working.; ; * Receiving from two DWM1000 modules working.; * Still issues with interrupts. Cleanup necessary.

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 50:50b8aea54a51 12
bhepp 50:50b8aea54a51 13 InterruptMultiplexer(PinName irq_pin, PinName status_pin = D2)
bhepp 50:50b8aea54a51 14 : irq(irq_pin), status(D2) {
bhepp 50:50b8aea54a51 15 if (status.is_connected())
bhepp 50:50b8aea54a51 16 status = 1;
bhepp 50:50b8aea54a51 17 }
bhepp 50:50b8aea54a51 18
bhepp 50:50b8aea54a51 19 void clear() {
bhepp 50:50b8aea54a51 20 isr_array.clear();
bhepp 48:5999e510f154 21 }
bhepp 48:5999e510f154 22
bhepp 50:50b8aea54a51 23 InterruptIn& getIRQ() {
bhepp 50:50b8aea54a51 24 return irq;
bhepp 50:50b8aea54a51 25 }
bhepp 50:50b8aea54a51 26
bhepp 50:50b8aea54a51 27 void enableCallback(int index) {
bhepp 50:50b8aea54a51 28 if (index < isr_array.size()) {
bhepp 50:50b8aea54a51 29 // _pc.printf("Enabled %d\r\n", index);
bhepp 50:50b8aea54a51 30 isr_array[index].second = true;
bhepp 50:50b8aea54a51 31 }
bhepp 50:50b8aea54a51 32 }
bhepp 50:50b8aea54a51 33
bhepp 50:50b8aea54a51 34 void disableCallback(int index) {
bhepp 50:50b8aea54a51 35 if (index < isr_array.size()) {
bhepp 50:50b8aea54a51 36 // _pc.printf("Disabled %d\r\n", index);
bhepp 50:50b8aea54a51 37 isr_array[index].second = false;
bhepp 50:50b8aea54a51 38 }
bhepp 48:5999e510f154 39 }
bhepp 48:5999e510f154 40
bhepp 48:5999e510f154 41 void trigger() {
bhepp 50:50b8aea54a51 42 if (status.is_connected()) {
bhepp 50:50b8aea54a51 43 if (status)
bhepp 50:50b8aea54a51 44 status = 0;
bhepp 50:50b8aea54a51 45 else
bhepp 50:50b8aea54a51 46 status = 1;
bhepp 50:50b8aea54a51 47 }
bhepp 48:5999e510f154 48 // _pc.printf("Trigger\r\n");
bhepp 48:5999e510f154 49 for (int i = 0; i < isr_array.size(); ++i) {
bhepp 48:5999e510f154 50 bool enable = isr_array[i].second;
bhepp 48:5999e510f154 51 if (enable) {
bhepp 48:5999e510f154 52 FunctionPointer& fptr = isr_array[i].first;
bhepp 48:5999e510f154 53 fptr.call();
bhepp 48:5999e510f154 54 }
bhepp 48:5999e510f154 55 }
bhepp 50:50b8aea54a51 56 //myled1 = 0;
bhepp 48:5999e510f154 57 // _pc.printf("Trigger stop\r\n");
bhepp 48:5999e510f154 58 }
bhepp 48:5999e510f154 59
bhepp 50:50b8aea54a51 60 int addCallback(void (*isr)(void), bool enable = true) {
bhepp 48:5999e510f154 61 FunctionPointer fptr;
bhepp 48:5999e510f154 62 fptr.attach(isr);
bhepp 48:5999e510f154 63 isr_array.push_back(std::make_pair(fptr, enable));
bhepp 48:5999e510f154 64 return isr_array.size() - 1;
bhepp 48:5999e510f154 65 }
bhepp 48:5999e510f154 66
bhepp 48:5999e510f154 67 template <typename T>
bhepp 50:50b8aea54a51 68 int addCallback(T* tptr, void (T::*isr)(void), bool enable = true) {
bhepp 48:5999e510f154 69 FunctionPointer fptr;
bhepp 48:5999e510f154 70 fptr.attach(tptr, isr);
bhepp 48:5999e510f154 71 isr_array.push_back(std::make_pair(fptr, enable));
bhepp 48:5999e510f154 72 return isr_array.size() - 1;
bhepp 48:5999e510f154 73 }
bhepp 48:5999e510f154 74
bhepp 48:5999e510f154 75 private:
bhepp 50:50b8aea54a51 76 InterruptIn irq;
bhepp 48:5999e510f154 77 std::vector<std::pair<FunctionPointer, bool> > isr_array;
bhepp 50:50b8aea54a51 78 DigitalOut status;
bhepp 48:5999e510f154 79 };