Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <memory> |
| 11 | |
| 12 | #include "HAL/Interrupts.h" |
| 13 | #include "frc971/wpilib/ahal/AnalogTriggerType.h" |
| 14 | #include "frc971/wpilib/ahal/SensorBase.h" |
| 15 | |
| 16 | namespace frc { |
| 17 | |
| 18 | class InterruptableSensorBase { |
| 19 | public: |
| 20 | enum WaitResult { |
| 21 | kTimeout = 0x0, |
| 22 | kRisingEdge = 0x1, |
| 23 | kFallingEdge = 0x100, |
| 24 | kBoth = 0x101, |
| 25 | }; |
| 26 | |
| 27 | InterruptableSensorBase(); |
| 28 | virtual ~InterruptableSensorBase() = default; |
| 29 | virtual HAL_Handle GetPortHandleForRouting() const = 0; |
| 30 | virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0; |
| 31 | virtual void RequestInterrupts( |
| 32 | HAL_InterruptHandlerFunction handler, |
| 33 | void *param); ///< Asynchronous handler version. |
| 34 | virtual void RequestInterrupts(); ///< Synchronous Wait version. |
| 35 | virtual void |
| 36 | CancelInterrupts(); ///< Free up the underlying chipobject functions. |
| 37 | virtual WaitResult WaitForInterrupt( |
| 38 | double timeout, |
| 39 | bool ignorePrevious = true); ///< Synchronous version. |
| 40 | virtual void |
| 41 | EnableInterrupts(); ///< Enable interrupts - after finishing setup. |
| 42 | virtual void DisableInterrupts(); ///< Disable, but don't deallocate. |
| 43 | virtual double ReadRisingTimestamp(); ///< Return the timestamp for the |
| 44 | /// rising interrupt that occurred. |
| 45 | virtual double ReadFallingTimestamp(); ///< Return the timestamp for the |
| 46 | /// falling interrupt that occurred. |
| 47 | virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge); |
| 48 | |
| 49 | protected: |
| 50 | HAL_InterruptHandle m_interrupt = HAL_kInvalidHandle; |
| 51 | void AllocateInterrupts(bool watcher); |
| 52 | }; |
| 53 | |
| 54 | } // namespace frc |