![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
InterruptHandler.h@67:bd0f0580af5a, 2016-01-05 (annotated)
- Committer:
- naegelit
- Date:
- Tue Jan 05 17:06:19 2016 +0000
- Revision:
- 67:bd0f0580af5a
- Parent:
- 54:a59803fcce58
working with 4 odroids (hacky version)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bhepp | 54:a59803fcce58 | 1 | #pragma once |
bhepp | 54:a59803fcce58 | 2 | |
bhepp | 54:a59803fcce58 | 3 | #include "mbed.h" |
bhepp | 54:a59803fcce58 | 4 | #include <vector> |
bhepp | 54:a59803fcce58 | 5 | #include <utility> |
bhepp | 54:a59803fcce58 | 6 | |
bhepp | 54:a59803fcce58 | 7 | class InterruptHandler { |
bhepp | 54:a59803fcce58 | 8 | const PinName INTERRUPT_STATUS_PIN = NC; |
bhepp | 54:a59803fcce58 | 9 | |
bhepp | 54:a59803fcce58 | 10 | public: |
bhepp | 54:a59803fcce58 | 11 | |
bhepp | 54:a59803fcce58 | 12 | InterruptHandler(PinName irq_pin, PinName status_pin = D2) |
bhepp | 54:a59803fcce58 | 13 | : irq(irq_pin), status(INTERRUPT_STATUS_PIN) { |
bhepp | 54:a59803fcce58 | 14 | if (status.is_connected()) |
bhepp | 54:a59803fcce58 | 15 | status = 1; |
bhepp | 54:a59803fcce58 | 16 | } |
bhepp | 54:a59803fcce58 | 17 | |
bhepp | 54:a59803fcce58 | 18 | void clear() { |
bhepp | 54:a59803fcce58 | 19 | } |
bhepp | 54:a59803fcce58 | 20 | |
bhepp | 54:a59803fcce58 | 21 | InterruptIn& getIRQ() { |
bhepp | 54:a59803fcce58 | 22 | return irq; |
bhepp | 54:a59803fcce58 | 23 | } |
bhepp | 54:a59803fcce58 | 24 | |
bhepp | 54:a59803fcce58 | 25 | void enableCallback(int index = 0) { |
bhepp | 54:a59803fcce58 | 26 | enable = true; |
bhepp | 54:a59803fcce58 | 27 | } |
bhepp | 54:a59803fcce58 | 28 | |
bhepp | 54:a59803fcce58 | 29 | void disableCallback(int index = 0) { |
bhepp | 54:a59803fcce58 | 30 | enable = false; |
bhepp | 54:a59803fcce58 | 31 | } |
bhepp | 54:a59803fcce58 | 32 | |
bhepp | 54:a59803fcce58 | 33 | void trigger() { |
bhepp | 54:a59803fcce58 | 34 | if (status.is_connected()) { |
bhepp | 54:a59803fcce58 | 35 | if (status) |
bhepp | 54:a59803fcce58 | 36 | status = 0; |
bhepp | 54:a59803fcce58 | 37 | else |
bhepp | 54:a59803fcce58 | 38 | status = 1; |
bhepp | 54:a59803fcce58 | 39 | } |
bhepp | 54:a59803fcce58 | 40 | if (enable) { |
bhepp | 54:a59803fcce58 | 41 | fptr.call(); |
bhepp | 54:a59803fcce58 | 42 | } |
bhepp | 54:a59803fcce58 | 43 | } |
bhepp | 54:a59803fcce58 | 44 | |
bhepp | 54:a59803fcce58 | 45 | int addCallback(void (*isr)(void), bool enable = true) { |
bhepp | 54:a59803fcce58 | 46 | fptr.attach(isr); |
bhepp | 54:a59803fcce58 | 47 | this->enable = enable; |
bhepp | 54:a59803fcce58 | 48 | return 0; |
bhepp | 54:a59803fcce58 | 49 | } |
bhepp | 54:a59803fcce58 | 50 | |
bhepp | 54:a59803fcce58 | 51 | template <typename T> |
bhepp | 54:a59803fcce58 | 52 | int addCallback(T* tptr, void (T::*isr)(void), bool enable = true) { |
bhepp | 54:a59803fcce58 | 53 | fptr.attach(tptr, isr); |
bhepp | 54:a59803fcce58 | 54 | this->enable = enable; |
bhepp | 54:a59803fcce58 | 55 | return 0; |
bhepp | 54:a59803fcce58 | 56 | } |
bhepp | 54:a59803fcce58 | 57 | |
bhepp | 54:a59803fcce58 | 58 | private: |
bhepp | 54:a59803fcce58 | 59 | InterruptIn irq; |
bhepp | 54:a59803fcce58 | 60 | FunctionPointer fptr; |
bhepp | 54:a59803fcce58 | 61 | bool enable; |
bhepp | 54:a59803fcce58 | 62 | DigitalOut status; |
bhepp | 54:a59803fcce58 | 63 | }; |