WPILibC++  2019.1.1-beta-2-39-gff58c51
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Counter.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. 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/AnalogTrigger.h"
13 #include "hal/Types.h"
14 
21 // clang-format off
25 HAL_ENUM(HAL_Counter_Mode) {
26  HAL_Counter_kTwoPulse = 0,
27  HAL_Counter_kSemiperiod = 1,
28  HAL_Counter_kPulseLength = 2,
29  HAL_Counter_kExternalDirection = 3
30 };
31 // clang-format on
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
44 HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
45  int32_t* status);
46 
52 void HAL_FreeCounter(HAL_CounterHandle counterHandle, int32_t* status);
53 
60 void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size,
61  int32_t* status);
62 
72 void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,
73  HAL_Handle digitalSourceHandle,
74  HAL_AnalogTriggerType analogTriggerType,
75  int32_t* status);
76 
86 void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle,
87  HAL_Bool risingEdge, HAL_Bool fallingEdge,
88  int32_t* status);
89 
95 void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle, int32_t* status);
96 
106 void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
107  HAL_Handle digitalSourceHandle,
108  HAL_AnalogTriggerType analogTriggerType,
109  int32_t* status);
110 
119 void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle,
120  HAL_Bool risingEdge, HAL_Bool fallingEdge,
121  int32_t* status);
122 
128 void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle,
129  int32_t* status);
130 
138 void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle, int32_t* status);
139 
148 void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle,
149  int32_t* status);
150 
160 void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle,
161  HAL_Bool highSemiPeriod, int32_t* status);
162 
173 void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle,
174  double threshold, int32_t* status);
175 
184 int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
185  int32_t* status);
186 
195 void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
196  int32_t samplesToAverage, int32_t* status);
197 
206 void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status);
207 
217 int32_t HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status);
218 
219 /*
220  * Gets the Period of the most recent count.
221  *
222  * Returns the time interval of the most recent count. This can be used for
223  * velocity calculations to determine shaft speed.
224  *
225  * @param counterHandle the counter handle
226  * @returns the period of the last two pulses in units of seconds
227  */
228 double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status);
229 
241 void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
242  int32_t* status);
243 
267 void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle,
268  HAL_Bool enabled, int32_t* status);
269 
281 HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle,
282  int32_t* status);
283 
290 HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle,
291  int32_t* status);
292 
302 void HAL_SetCounterReverseDirection(HAL_CounterHandle counterHandle,
303  HAL_Bool reverseDirection, int32_t* status);
304 #ifdef __cplusplus
305 } // extern "C"
306 #endif
307 
int32_t HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t *status)
Reads the current counter value.
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle, int32_t *status)
Sets directional counting mode on this counter.
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle, int32_t *status)
Gets the last direction the counter value changed.
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle, int32_t *status)
Determines if the clock is stopped.
void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle, HAL_Handle digitalSourceHandle, HAL_AnalogTriggerType analogTriggerType, int32_t *status)
Sets the source object that causes the counter to count down.
void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle, int32_t *status)
Disables the down counting source to the counter.
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle, int32_t *status)
Gets the Samples to Average which specifies the number of samples of the timer to average when calcul...
void HAL_SetCounterReverseDirection(HAL_CounterHandle counterHandle, HAL_Bool reverseDirection, int32_t *status)
Sets the Counter to return reversed sensing on the direction.
void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle, int32_t *status)
Disables the up counting source to the counter.
HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t *index, int32_t *status)
Initializes a counter.
void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size, int32_t *status)
Sets the average sample size of a counter.
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod, int32_t *status)
Sets the maximum period where the device is still considered "moving".
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle, HAL_Bool risingEdge, HAL_Bool fallingEdge, int32_t *status)
Sets the down source to either detect rising edges or falling edges.
HAL_ENUM(HAL_Counter_Mode)
The counter mode.
Definition: Counter.h:25
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle, int32_t samplesToAverage, int32_t *status)
Sets the Samples to Average which specifies the number of samples of the timer to average when calcul...
void HAL_FreeCounter(HAL_CounterHandle counterHandle, int32_t *status)
Frees a counter.
void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle, int32_t *status)
Sets standard up / down counting mode on this counter.
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle, double threshold, int32_t *status)
Configures the counter to count in up or down based on the length of the input pulse.
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle, HAL_Bool enabled, int32_t *status)
Selects whether you want to continue updating the event timer output when there are no samples captur...
void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t *status)
Resets the Counter to zero.
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle, HAL_Bool highSemiPeriod, int32_t *status)
Sets Semi-period mode on this counter.
void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle, HAL_Handle digitalSourceHandle, HAL_AnalogTriggerType analogTriggerType, int32_t *status)
Sets the source object that causes the counter to count up.
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle, HAL_Bool risingEdge, HAL_Bool fallingEdge, int32_t *status)
Sets the up source to either detect rising edges or falling edges.