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