brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame^] | 1 | #ifndef AOS_CRIO_SHARED_LIBS_INTERRUPT_NOTIFIER_H_ |
| 2 | #define AOS_CRIO_SHARED_LIBS_INTERRUPT_NOTIFIER_H_ |
| 3 | |
| 4 | #include "WPILib/InterruptableSensorBase.h" |
| 5 | |
| 6 | #include "aos/crio/shared_libs/interrupt_bridge.h" |
| 7 | |
| 8 | namespace aos { |
| 9 | namespace crio { |
| 10 | |
| 11 | // An InterruptBridge that notifies based on interrupts from a WPILib |
| 12 | // InterruptableSensorBase object (which DigitalInput is an example of). |
| 13 | template<typename T> |
| 14 | class InterruptNotifier : public InterruptBridge<T> { |
| 15 | public: |
| 16 | // This object will hold a reference to sensor, but will not free it. This |
| 17 | // object will take ownership of everything related to interrupts for sensor |
| 18 | // (ie this constructor will call sensor->RequestInterrupts). |
| 19 | // Interrupts should be cancelled (the state InterruptableSensorBases are |
| 20 | // constructed in) when this constructor is called. |
| 21 | // Any setup of sensor that is required should happen before Start() is |
| 22 | // called, but after this constructor (ie SetUpSourceEdge). |
| 23 | InterruptNotifier(typename InterruptBridge<T>::Handler handler, |
| 24 | InterruptableSensorBase *sensor, |
| 25 | T *param = NULL, |
| 26 | int priority = InterruptBridge<T>::kDefaultPriority); |
| 27 | virtual ~InterruptNotifier(); |
| 28 | |
| 29 | // Starts calling the handler whenever the interrupt triggers. |
| 30 | void Start(); |
| 31 | |
| 32 | private: |
| 33 | // The only docs that seem to exist on the first arg is that it's named |
| 34 | // interruptAssertedMask in WPILib/ChipObject/tInterruptManager.h |
| 35 | // The second arg is the general callback parameter which will be a pointer to |
| 36 | // an instance. This function calls Notify() on that instance. |
| 37 | static void StaticNotify(uint32_t, void *self_in); |
| 38 | virtual void StopNotifications(); |
| 39 | |
| 40 | InterruptableSensorBase *const sensor_; |
| 41 | DISALLOW_COPY_AND_ASSIGN(InterruptNotifier<T>); |
| 42 | }; |
| 43 | |
| 44 | } // namespace crio |
| 45 | } // namespace aos |
| 46 | |
| 47 | #include "aos/crio/shared_libs/interrupt_notifier-tmpl.h" |
| 48 | |
| 49 | #endif // AOS_CRIO_SHARED_LIBS_INTERRUPT_NOTIFIER_H_ |