Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: InterruptMultiplexer.h
- Revision:
- 50:50b8aea54a51
- Parent:
- 48:5999e510f154
- Child:
- 52:94688f414dcd
diff -r 73cd2b37f5b3 -r 50b8aea54a51 InterruptMultiplexer.h --- a/InterruptMultiplexer.h Tue Nov 24 16:43:13 2015 +0000 +++ b/InterruptMultiplexer.h Thu Nov 26 21:42:51 2015 +0000 @@ -9,17 +9,42 @@ class InterruptMultiplexer { public: - void enable(int index) { -// _pc.printf("Enabled %d\r\n", index); - isr_array[index].second = true; + + InterruptMultiplexer(PinName irq_pin, PinName status_pin = D2) + : irq(irq_pin), status(D2) { + if (status.is_connected()) + status = 1; + } + + void clear() { + isr_array.clear(); } - void disable(int index) { -// _pc.printf("Disabled %d\r\n", index); - isr_array[index].second = false; + InterruptIn& getIRQ() { + return irq; + } + + void enableCallback(int index) { + if (index < isr_array.size()) { +// _pc.printf("Enabled %d\r\n", index); + isr_array[index].second = true; + } + } + + void disableCallback(int index) { + if (index < isr_array.size()) { +// _pc.printf("Disabled %d\r\n", index); + isr_array[index].second = false; + } } void trigger() { + if (status.is_connected()) { + if (status) + status = 0; + else + status = 1; + } // _pc.printf("Trigger\r\n"); for (int i = 0; i < isr_array.size(); ++i) { bool enable = isr_array[i].second; @@ -28,10 +53,11 @@ fptr.call(); } } + //myled1 = 0; // _pc.printf("Trigger stop\r\n"); } - int addISR(void (*isr)(void), bool enable = true) { + int addCallback(void (*isr)(void), bool enable = true) { FunctionPointer fptr; fptr.attach(isr); isr_array.push_back(std::make_pair(fptr, enable)); @@ -39,7 +65,7 @@ } template <typename T> - int addISR(T* tptr, void (T::*isr)(void), bool enable = true) { + int addCallback(T* tptr, void (T::*isr)(void), bool enable = true) { FunctionPointer fptr; fptr.attach(tptr, isr); isr_array.push_back(std::make_pair(fptr, enable)); @@ -47,5 +73,7 @@ } private: + InterruptIn irq; std::vector<std::pair<FunctionPointer, bool> > isr_array; + DigitalOut status; };