Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | #pragma once |
| 6 | |
| 7 | #include <stdint.h> |
| 8 | |
| 9 | #include "hal/Encoder.h" |
| 10 | |
| 11 | namespace hal { |
| 12 | |
| 13 | bool GetEncoderBaseHandle(HAL_EncoderHandle handle, |
| 14 | HAL_FPGAEncoderHandle* fpgaEncoderHandle, |
| 15 | HAL_CounterHandle* counterHandle); |
| 16 | |
| 17 | class Encoder { |
| 18 | public: |
| 19 | friend bool GetEncoderBaseHandle(HAL_EncoderHandle handle, |
| 20 | HAL_FPGAEncoderHandle* fpgaEncoderHandle, |
| 21 | HAL_CounterHandle* counterHandle); |
| 22 | |
| 23 | Encoder(HAL_Handle digitalSourceHandleA, |
| 24 | HAL_AnalogTriggerType analogTriggerTypeA, |
| 25 | HAL_Handle digitalSourceHandleB, |
| 26 | HAL_AnalogTriggerType analogTriggerTypeB, bool reverseDirection, |
| 27 | HAL_EncoderEncodingType encodingType, int32_t* status); |
| 28 | ~Encoder(); |
| 29 | |
| 30 | // CounterBase interface |
| 31 | int32_t Get(int32_t* status) const; |
| 32 | int32_t GetRaw(int32_t* status) const; |
| 33 | int32_t GetEncodingScale(int32_t* status) const; |
| 34 | void Reset(int32_t* status); |
| 35 | double GetPeriod(int32_t* status) const; |
| 36 | void SetMaxPeriod(double maxPeriod, int32_t* status); |
| 37 | bool GetStopped(int32_t* status) const; |
| 38 | bool GetDirection(int32_t* status) const; |
| 39 | |
| 40 | double GetDistance(int32_t* status) const; |
| 41 | double GetRate(int32_t* status) const; |
| 42 | void SetMinRate(double minRate, int32_t* status); |
| 43 | void SetDistancePerPulse(double distancePerPulse, int32_t* status); |
| 44 | void SetReverseDirection(bool reverseDirection, int32_t* status); |
| 45 | void SetSamplesToAverage(int32_t samplesToAverage, int32_t* status); |
| 46 | int32_t GetSamplesToAverage(int32_t* status) const; |
| 47 | |
| 48 | void SetIndexSource(HAL_Handle digitalSourceHandle, |
| 49 | HAL_AnalogTriggerType analogTriggerType, |
| 50 | HAL_EncoderIndexingType type, int32_t* status); |
| 51 | |
| 52 | int32_t GetFPGAIndex() const { return m_index; } |
| 53 | |
| 54 | int32_t GetEncodingScale() const { return m_encodingScale; } |
| 55 | |
| 56 | double DecodingScaleFactor() const; |
| 57 | |
| 58 | double GetDistancePerPulse() const { return m_distancePerPulse; } |
| 59 | |
| 60 | HAL_EncoderEncodingType GetEncodingType() const { return m_encodingType; } |
| 61 | |
| 62 | private: |
| 63 | void SetupCounter(HAL_Handle digitalSourceHandleA, |
| 64 | HAL_AnalogTriggerType analogTriggerTypeA, |
| 65 | HAL_Handle digitalSourceHandleB, |
| 66 | HAL_AnalogTriggerType analogTriggerTypeB, |
| 67 | bool reverseDirection, HAL_EncoderEncodingType encodingType, |
| 68 | int32_t* status); |
| 69 | |
| 70 | HAL_FPGAEncoderHandle m_encoder = HAL_kInvalidHandle; |
| 71 | |
| 72 | HAL_CounterHandle m_counter = HAL_kInvalidHandle; |
| 73 | |
| 74 | int32_t m_index = 0; |
| 75 | |
| 76 | double m_distancePerPulse = 1.0; |
| 77 | |
| 78 | HAL_EncoderEncodingType m_encodingType; |
| 79 | |
| 80 | int32_t m_encodingScale; |
| 81 | }; |
| 82 | |
| 83 | } // namespace hal |