Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. |
| 3 | */ |
| 4 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 5 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "HAL/HAL.hpp" |
| 10 | #include "SensorBase.h" |
| 11 | #include "Resource.h" |
| 12 | |
| 13 | #include <memory> |
| 14 | |
| 15 | class InterruptableSensorBase : public SensorBase { |
| 16 | public: |
| 17 | enum WaitResult { |
| 18 | kTimeout = 0x0, |
| 19 | kRisingEdge = 0x1, |
| 20 | kFallingEdge = 0x100, |
| 21 | kBoth = 0x101, |
| 22 | }; |
| 23 | |
| 24 | InterruptableSensorBase(); |
| 25 | virtual ~InterruptableSensorBase() = default; |
| 26 | virtual uint32_t GetChannelForRouting() const = 0; |
| 27 | virtual uint32_t GetModuleForRouting() const = 0; |
| 28 | virtual bool GetAnalogTriggerForRouting() const = 0; |
| 29 | virtual void RequestInterrupts( |
| 30 | InterruptHandlerFunction handler, |
| 31 | void *param); ///< Asynchronus handler version. |
| 32 | virtual void RequestInterrupts(); ///< Synchronus Wait version. |
| 33 | virtual void |
| 34 | CancelInterrupts(); ///< Free up the underlying chipobject functions. |
| 35 | virtual WaitResult WaitForInterrupt( |
| 36 | float timeout, bool ignorePrevious = true); ///< Synchronus version. |
| 37 | virtual void |
| 38 | EnableInterrupts(); ///< Enable interrupts - after finishing setup. |
| 39 | virtual void DisableInterrupts(); ///< Disable, but don't deallocate. |
| 40 | virtual double ReadRisingTimestamp(); ///< Return the timestamp for the |
| 41 | ///rising interrupt that occurred. |
| 42 | virtual double ReadFallingTimestamp(); ///< Return the timestamp for the |
| 43 | ///falling interrupt that occurred. |
| 44 | virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge); |
| 45 | |
| 46 | protected: |
| 47 | void *m_interrupt = nullptr; |
| 48 | uint32_t m_interruptIndex = std::numeric_limits<uint32_t>::max(); |
| 49 | void AllocateInterrupts(bool watcher); |
| 50 | |
| 51 | static std::unique_ptr<Resource> m_interrupts; |
| 52 | }; |