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