WPILibC++  2018.4.1-20180729040223-1137-g011f0ff
 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 
15 // clang-format off
19 HAL_ENUM(HAL_Counter_Mode) {
20  HAL_Counter_kTwoPulse = 0,
21  HAL_Counter_kSemiperiod = 1,
22  HAL_Counter_kPulseLength = 2,
23  HAL_Counter_kExternalDirection = 3
24 };
25 // clang-format on
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
38 HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
39  int32_t* status);
40 
46 void HAL_FreeCounter(HAL_CounterHandle counterHandle, int32_t* status);
47 
54 void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size,
55  int32_t* status);
56 
66 void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,
67  HAL_Handle digitalSourceHandle,
68  HAL_AnalogTriggerType analogTriggerType,
69  int32_t* status);
70 
80 void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle,
81  HAL_Bool risingEdge, HAL_Bool fallingEdge,
82  int32_t* status);
83 
89 void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle, int32_t* status);
90 
100 void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
101  HAL_Handle digitalSourceHandle,
102  HAL_AnalogTriggerType analogTriggerType,
103  int32_t* status);
104 
113 void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle,
114  HAL_Bool risingEdge, HAL_Bool fallingEdge,
115  int32_t* status);
116 
122 void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle,
123  int32_t* status);
124 
132 void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle, int32_t* status);
133 
142 void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle,
143  int32_t* status);
144 
154 void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle,
155  HAL_Bool highSemiPeriod, int32_t* status);
156 
167 void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle,
168  double threshold, int32_t* status);
169 
178 int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
179  int32_t* status);
180 
189 void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
190  int32_t samplesToAverage, int32_t* status);
191 
200 void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status);
201 
211 int32_t HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status);
212 
213 /*
214  * Gets the Period of the most recent count.
215  *
216  * Returns the time interval of the most recent count. This can be used for
217  * velocity calculations to determine shaft speed.
218  *
219  * @param counterHandle the counter handle
220  * @returns the period of the last two pulses in units of seconds
221  */
222 double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status);
223 
235 void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
236  int32_t* status);
237 
261 void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle,
262  HAL_Bool enabled, int32_t* status);
263 
275 HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle,
276  int32_t* status);
277 
284 HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle,
285  int32_t* status);
286 
296 void HAL_SetCounterReverseDirection(HAL_CounterHandle counterHandle,
297  HAL_Bool reverseDirection, int32_t* status);
298 #ifdef __cplusplus
299 } // extern "C"
300 #endif