Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame] | 2 | /* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 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 <stdint.h> |
| 11 | |
| 12 | #include "hal/Encoder.h" |
| 13 | |
| 14 | namespace hal { |
| 15 | |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame] | 16 | bool GetEncoderBaseHandle(HAL_EncoderHandle handle, |
| 17 | HAL_FPGAEncoderHandle* fpgaEncoderHandle, |
| 18 | HAL_CounterHandle* counterHandle); |
| 19 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 20 | class Encoder { |
| 21 | public: |
James Kuszmaul | 4b81d30 | 2019-12-14 20:53:14 -0800 | [diff] [blame] | 22 | friend bool GetEncoderBaseHandle(HAL_EncoderHandle handle, |
| 23 | HAL_FPGAEncoderHandle* fpgaEncoderHandle, |
| 24 | HAL_CounterHandle* counterHandle); |
| 25 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 26 | Encoder(HAL_Handle digitalSourceHandleA, |
| 27 | HAL_AnalogTriggerType analogTriggerTypeA, |
| 28 | HAL_Handle digitalSourceHandleB, |
| 29 | HAL_AnalogTriggerType analogTriggerTypeB, bool reverseDirection, |
| 30 | HAL_EncoderEncodingType encodingType, int32_t* status); |
| 31 | ~Encoder(); |
| 32 | |
| 33 | // CounterBase interface |
| 34 | int32_t Get(int32_t* status) const; |
| 35 | int32_t GetRaw(int32_t* status) const; |
| 36 | int32_t GetEncodingScale(int32_t* status) const; |
| 37 | void Reset(int32_t* status); |
| 38 | double GetPeriod(int32_t* status) const; |
| 39 | void SetMaxPeriod(double maxPeriod, int32_t* status); |
| 40 | bool GetStopped(int32_t* status) const; |
| 41 | bool GetDirection(int32_t* status) const; |
| 42 | |
| 43 | double GetDistance(int32_t* status) const; |
| 44 | double GetRate(int32_t* status) const; |
| 45 | void SetMinRate(double minRate, int32_t* status); |
| 46 | void SetDistancePerPulse(double distancePerPulse, int32_t* status); |
| 47 | void SetReverseDirection(bool reverseDirection, int32_t* status); |
| 48 | void SetSamplesToAverage(int32_t samplesToAverage, int32_t* status); |
| 49 | int32_t GetSamplesToAverage(int32_t* status) const; |
| 50 | |
| 51 | void SetIndexSource(HAL_Handle digitalSourceHandle, |
| 52 | HAL_AnalogTriggerType analogTriggerType, |
| 53 | HAL_EncoderIndexingType type, int32_t* status); |
| 54 | |
| 55 | int32_t GetFPGAIndex() const { return m_index; } |
| 56 | |
| 57 | int32_t GetEncodingScale() const { return m_encodingScale; } |
| 58 | |
| 59 | double DecodingScaleFactor() const; |
| 60 | |
| 61 | double GetDistancePerPulse() const { return m_distancePerPulse; } |
| 62 | |
| 63 | HAL_EncoderEncodingType GetEncodingType() const { return m_encodingType; } |
| 64 | |
| 65 | private: |
| 66 | void SetupCounter(HAL_Handle digitalSourceHandleA, |
| 67 | HAL_AnalogTriggerType analogTriggerTypeA, |
| 68 | HAL_Handle digitalSourceHandleB, |
| 69 | HAL_AnalogTriggerType analogTriggerTypeB, |
| 70 | bool reverseDirection, HAL_EncoderEncodingType encodingType, |
| 71 | int32_t* status); |
| 72 | |
| 73 | HAL_FPGAEncoderHandle m_encoder = HAL_kInvalidHandle; |
| 74 | |
| 75 | HAL_CounterHandle m_counter = HAL_kInvalidHandle; |
| 76 | |
| 77 | int32_t m_index = 0; |
| 78 | |
| 79 | double m_distancePerPulse = 1.0; |
| 80 | |
| 81 | HAL_EncoderEncodingType m_encodingType; |
| 82 | |
| 83 | int32_t m_encodingScale; |
| 84 | }; |
| 85 | |
| 86 | } // namespace hal |