WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
Counter.h
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 
7 #ifndef CPPCOUNTER_H_
8 #define CPPCOUNTER_H_
9 
10 #include "AnalogTriggerOutput.h"
11 #include "CounterBase.h"
12 #include "SensorBase.h"
13 #include "LiveWindow/LiveWindowSendable.h"
14 
21 class Counter : public SensorBase, public CounterBase, public LiveWindowSendable
22 {
23 public:
24  typedef enum {kTwoPulse=0, kSemiperiod=1, kPulseLength=2, kExternalDirection=3} Mode;
25 
26  Counter();
27  explicit Counter(uint32_t channel);
28  Counter(uint8_t moduleNumber, uint32_t channel);
29  explicit Counter(DigitalSource *source);
30  explicit Counter(DigitalSource &source);
31  explicit Counter(AnalogTrigger *trigger);
32  explicit Counter(AnalogTrigger &trigger);
33  Counter(EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted);
34  virtual ~Counter();
35 
36  void SetUpSource(uint32_t channel);
37  void SetUpSource(uint8_t moduleNumber, uint32_t channel);
38  void SetUpSource(AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType);
39  void SetUpSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType);
40  void SetUpSource(DigitalSource *source);
41  void SetUpSource(DigitalSource &source);
42  void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
43  void ClearUpSource();
44 
45  void SetDownSource(uint32_t channel);
46  void SetDownSource(uint8_t moduleNumber, uint32_t channel);
47  void SetDownSource(AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType);
48  void SetDownSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType);
49  void SetDownSource(DigitalSource *source);
50  void SetDownSource(DigitalSource &source);
51  void SetDownSourceEdge(bool risingEdge, bool fallingEdge);
52  void ClearDownSource();
53 
54  void SetUpDownCounterMode();
56  void SetSemiPeriodMode(bool highSemiPeriod);
57  void SetPulseLengthMode(float threshold);
58 
59  void SetReverseDirection(bool reverseDirection);
60 
61  // CounterBase interface
62  void Start();
63  int32_t Get();
64  void Reset();
65  void Stop();
66  double GetPeriod();
67  void SetMaxPeriod(double maxPeriod);
68  void SetUpdateWhenEmpty(bool enabled);
69  bool GetStopped();
70  bool GetDirection();
71  void SetSamplesToAverage(int samplesToAverage);
72  int GetSamplesToAverage();
73  uint32_t GetIndex() {return m_index;}
74 
75 
76  void UpdateTable();
77  void StartLiveWindowMode();
78  void StopLiveWindowMode();
79  virtual std::string GetSmartDashboardType();
80  void InitTable(ITable *subTable);
81  ITable * GetTable();
82 protected:
85  tCounter *m_counter;
86 private:
87  void InitCounter(Mode mode = kTwoPulse);
88 
89  bool m_allocatedUpSource;
90  bool m_allocatedDownSource;
91  uint32_t m_index;
92 
93  ITable *m_table;
94 };
95 
96 #endif
DigitalSource * m_downSource
What makes the counter count down.
Definition: Counter.h:84
Definition: AnalogTrigger.h:16
void SetPulseLengthMode(float threshold)
Definition: Counter.cpp:498
Counter()
Definition: Counter.cpp:49
void SetSemiPeriodMode(bool highSemiPeriod)
Definition: Counter.cpp:483
Definition: DigitalSource.h:19
void ClearUpSource()
Definition: Counter.cpp:300
void Stop()
Definition: Counter.cpp:581
int32_t Get()
Definition: Counter.cpp:555
DigitalSource * m_upSource
What makes the counter count up.
Definition: Counter.h:83
void SetDownSourceEdge(bool risingEdge, bool fallingEdge)
Definition: Counter.cpp:417
void Reset()
Definition: Counter.cpp:569
void SetDownSource(uint32_t channel)
Definition: Counter.cpp:325
bool GetDirection()
Definition: Counter.cpp:671
virtual ~Counter()
Definition: Counter.cpp:172
void SetUpSource(uint32_t channel)
Definition: Counter.cpp:207
void Start()
Definition: Counter.cpp:542
void ClearDownSource()
Definition: Counter.cpp:433
Definition: CounterBase.h:15
Definition: SensorBase.h:20
void SetUpdateWhenEmpty(bool enabled)
Definition: Counter.cpp:643
void SetUpSourceEdge(bool risingEdge, bool fallingEdge)
Definition: Counter.cpp:284
void SetSamplesToAverage(int samplesToAverage)
Definition: Counter.cpp:527
void SetReverseDirection(bool reverseDirection)
Definition: Counter.cpp:686
Definition: Counter.h:21
int GetSamplesToAverage()
Definition: Counter.cpp:514
void SetMaxPeriod(double maxPeriod)
Definition: Counter.cpp:623
bool GetStopped()
Definition: Counter.cpp:659
tCounter * m_counter
The FPGA counter object.
Definition: Counter.h:85
void SetUpDownCounterMode()
Definition: Counter.cpp:458
void SetExternalDirectionMode()
Definition: Counter.cpp:471