-
Notifications
You must be signed in to change notification settings - Fork 54
/
Counter.h
96 lines (82 loc) · 3.56 KB
/
Counter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef CPPCOUNTER_H_
#define CPPCOUNTER_H_
#include "AnalogTriggerOutput.h"
#include "CounterBase.h"
#include "SensorBase.h"
#include "LiveWindow/LiveWindowSendable.h"
/**
* Class for counting the number of ticks on a digital input channel.
* This is a general purpose class for counting repetitive events. It can return the number
* of counts, the period of the most recent cycle, and detect when the signal being counted
* has stopped by supplying a maximum cycle time.
*/
class Counter : public SensorBase, public CounterBase, public LiveWindowSendable
{
public:
typedef enum {kTwoPulse=0, kSemiperiod=1, kPulseLength=2, kExternalDirection=3} Mode;
Counter();
explicit Counter(uint32_t channel);
Counter(uint8_t moduleNumber, uint32_t channel);
explicit Counter(DigitalSource *source);
explicit Counter(DigitalSource &source);
explicit Counter(AnalogTrigger *trigger);
explicit Counter(AnalogTrigger &trigger);
Counter(EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted);
virtual ~Counter();
void SetUpSource(uint32_t channel);
void SetUpSource(uint8_t moduleNumber, uint32_t channel);
void SetUpSource(AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType);
void SetUpSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType);
void SetUpSource(DigitalSource *source);
void SetUpSource(DigitalSource &source);
void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
void ClearUpSource();
void SetDownSource(uint32_t channel);
void SetDownSource(uint8_t moduleNumber, uint32_t channel);
void SetDownSource(AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType);
void SetDownSource(AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType);
void SetDownSource(DigitalSource *source);
void SetDownSource(DigitalSource &source);
void SetDownSourceEdge(bool risingEdge, bool fallingEdge);
void ClearDownSource();
void SetUpDownCounterMode();
void SetExternalDirectionMode();
void SetSemiPeriodMode(bool highSemiPeriod);
void SetPulseLengthMode(float threshold);
void SetReverseDirection(bool reverseDirection);
// CounterBase interface
void Start();
int32_t Get();
void Reset();
void Stop();
double GetPeriod();
void SetMaxPeriod(double maxPeriod);
void SetUpdateWhenEmpty(bool enabled);
bool GetStopped();
bool GetDirection();
void SetSamplesToAverage(int samplesToAverage);
int GetSamplesToAverage();
uint32_t GetIndex() {return m_index;}
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
virtual std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
protected:
DigitalSource *m_upSource; ///< What makes the counter count up.
DigitalSource *m_downSource; ///< What makes the counter count down.
tCounter *m_counter; ///< The FPGA counter object.
private:
void InitCounter(Mode mode = kTwoPulse);
bool m_allocatedUpSource; ///< Was the upSource allocated locally?
bool m_allocatedDownSource; ///< Was the downSource allocated locally?
uint32_t m_index; ///< The index of this counter.
ITable *m_table;
};
#endif