Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
bhepp
Date:
Fri Nov 27 16:17:53 2015 +0000
Revision:
52:94688f414dcd
Parent:
50:50b8aea54a51
Child:
54:a59803fcce58
Fixed bug in loop of anchor nodes and addressing of anchor nodes

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