Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */ |
| 5 | /*----------------------------------------------------------------------------*/ |
| 6 | #pragma once |
| 7 | |
| 8 | #include "HAL/HAL.hpp" |
| 9 | #include "CounterBase.h" |
| 10 | #include "SensorBase.h" |
| 11 | #include "LiveWindow/LiveWindowSendable.h" |
| 12 | |
| 13 | #include <memory> |
| 14 | |
| 15 | /** |
| 16 | * Class for counting the number of ticks on a digital input channel. |
| 17 | * This is a general purpose class for counting repetitive events. It can return the number |
| 18 | * of counts, the period of the most recent cycle, and detect when the signal being counted |
| 19 | * has stopped by supplying a maximum cycle time. |
| 20 | * |
| 21 | * All counters will immediately start counting - Reset() them if you need them |
| 22 | * to be zeroed before use. |
| 23 | */ |
| 24 | class Counter : public SensorBase, public CounterBase, public LiveWindowSendable |
| 25 | { |
| 26 | public: |
| 27 | |
| 28 | explicit Counter(Mode mode = kTwoPulse); |
| 29 | explicit Counter(uint32_t channel); |
| 30 | // TODO: [Not Supported] explicit Counter(DigitalSource *source); |
| 31 | // TODO: [Not Supported] explicit Counter(DigitalSource &source); |
| 32 | // TODO: [Not Supported] explicit Counter(AnalogTrigger *source); |
| 33 | // TODO: [Not Supported] explicit Counter(AnalogTrigger &source); |
| 34 | // TODO: [Not Supported] Counter(EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted); |
| 35 | virtual ~Counter(); |
| 36 | |
| 37 | void SetUpSource(uint32_t channel); |
| 38 | // TODO: [Not Supported] void SetUpSource(AnalogTrigger *analogTrigger, AnalogTriggerType triggerType); |
| 39 | // TODO: [Not Supported] void SetUpSource(AnalogTrigger &analogTrigger, AnalogTriggerType triggerType); |
| 40 | // TODO: [Not Supported] void SetUpSource(DigitalSource *source); |
| 41 | // TODO: [Not Supported] void SetUpSource(DigitalSource &source); |
| 42 | void SetUpSourceEdge(bool risingEdge, bool fallingEdge); |
| 43 | void ClearUpSource(); |
| 44 | |
| 45 | void SetDownSource(uint32_t channel); |
| 46 | // TODO: [Not Supported] void SetDownSource(AnalogTrigger *analogTrigger, AnalogTriggerType triggerType); |
| 47 | // TODO: [Not Supported] void SetDownSource(AnalogTrigger &analogTrigger, AnalogTriggerType triggerType); |
| 48 | // TODO: [Not Supported] void SetDownSource(DigitalSource *source); |
| 49 | // TODO: [Not Supported] void SetDownSource(DigitalSource &source); |
| 50 | void SetDownSourceEdge(bool risingEdge, bool fallingEdge); |
| 51 | void ClearDownSource(); |
| 52 | |
| 53 | void SetUpDownCounterMode(); |
| 54 | void SetExternalDirectionMode(); |
| 55 | void SetSemiPeriodMode(bool highSemiPeriod); |
| 56 | void SetPulseLengthMode(float threshold); |
| 57 | |
| 58 | void SetReverseDirection(bool reverseDirection); |
| 59 | |
| 60 | // CounterBase interface |
| 61 | int32_t Get() const override; |
| 62 | void Reset() override; |
| 63 | double GetPeriod() const override; |
| 64 | void SetMaxPeriod(double maxPeriod) override; |
| 65 | void SetUpdateWhenEmpty(bool enabled); |
| 66 | bool GetStopped() const override; |
| 67 | bool GetDirection() const override; |
| 68 | |
| 69 | void SetSamplesToAverage(int samplesToAverage); |
| 70 | int GetSamplesToAverage() const; |
| 71 | uint32_t GetFPGAIndex() const |
| 72 | { |
| 73 | return m_index; |
| 74 | } |
| 75 | |
| 76 | void UpdateTable() override; |
| 77 | void StartLiveWindowMode() override; |
| 78 | void StopLiveWindowMode() override; |
| 79 | virtual std::string GetSmartDashboardType() const override; |
| 80 | void InitTable(std::shared_ptr<ITable> subTable) override; |
| 81 | std::shared_ptr<ITable> GetTable() const override; |
| 82 | protected: |
| 83 | // TODO: [Not Supported] DigitalSource *m_upSource; ///< What makes the counter count up. |
| 84 | // TODO: [Not Supported] DigitalSource *m_downSource; ///< What makes the counter count down. |
| 85 | void* m_counter; ///< The FPGA counter object. |
| 86 | private: |
| 87 | |
| 88 | bool m_allocatedUpSource; ///< Was the upSource allocated locally? |
| 89 | bool m_allocatedDownSource; ///< Was the downSource allocated locally? |
| 90 | uint32_t m_index; ///< The index of this counter. |
| 91 | |
| 92 | std::shared_ptr<ITable> m_table; |
| 93 | }; |