blob: b401ccdca58cfe87aa56c6cd30cdfd2b8a47ca71 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
Brian Silverman8fce7482020-01-05 13:18:21 -08004
5#pragma once
6
7#include <stdint.h>
8
9#include "hal/AnalogTrigger.h"
10#include "hal/Types.h"
11
12extern "C" {
13
14HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
15 HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
16 HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
17 HAL_Bool reverseDirection, int32_t* index, int32_t* status);
18void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
19 int32_t* status);
20
21/**
22 * Reset the Encoder distance to zero.
23 * Resets the current count to zero on the encoder.
24 */
25void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
26 int32_t* status);
27
28/**
29 * Gets the fpga value from the encoder.
30 * The fpga value is the actual count unscaled by the 1x, 2x, or 4x scale
31 * factor.
32 * @return Current fpga count from the encoder
33 */
34int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
35 int32_t* status); // Raw value
36
37/**
38 * Returns the period of the most recent pulse.
39 * Returns the period of the most recent Encoder pulse in seconds.
40 * This method compenstates for the decoding type.
41 *
42 * @deprecated Use GetRate() in favor of this method. This returns unscaled
43 * periods and GetRate() scales using value from SetDistancePerPulse().
44 *
45 * @return Period in seconds of the most recent pulse.
46 */
47double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
48 int32_t* status);
49
50/**
51 * Sets the maximum period for stopped detection.
52 * Sets the value that represents the maximum period of the Encoder before it
53 * will assume that the attached device is stopped. This timeout allows users
54 * to determine if the wheels or other shaft has stopped rotating.
55 * This method compensates for the decoding type.
56 *
57 * @deprecated Use SetMinRate() in favor of this method. This takes unscaled
58 * periods and SetMinRate() scales using value from SetDistancePerPulse().
59 *
60 * @param maxPeriod The maximum time between rising and falling edges before the
61 * FPGA will
62 * report the device stopped. This is expressed in seconds.
63 */
64void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
65 double maxPeriod, int32_t* status);
66
67/**
68 * Determine if the encoder is stopped.
69 * Using the MaxPeriod value, a boolean is returned that is true if the encoder
70 * is considered stopped and false if it is still moving. A stopped encoder is
71 * one where the most recent pulse width exceeds the MaxPeriod.
72 * @return True if the encoder is considered stopped.
73 */
74HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpgaEncoderHandle,
75 int32_t* status);
76
77/**
78 * The last direction the encoder value changed.
79 * @return The last direction the encoder value changed.
80 */
81HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
82 int32_t* status);
83
84/**
85 * Set the direction sensing for this encoder.
86 * This sets the direction sensing on the encoder so that it could count in the
87 * correct software direction regardless of the mounting.
88 * @param reverseDirection true if the encoder direction should be reversed
89 */
90void HAL_SetFPGAEncoderReverseDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
91 HAL_Bool reverseDirection,
92 int32_t* status);
93
94/**
95 * Set the Samples to Average which specifies the number of samples of the timer
96 * to average when calculating the period. Perform averaging to account for
97 * mechanical imperfections or as oversampling to increase resolution.
98 * @param samplesToAverage The number of samples to average from 1 to 127.
99 */
100void HAL_SetFPGAEncoderSamplesToAverage(HAL_FPGAEncoderHandle fpgaEncoderHandle,
101 int32_t samplesToAverage,
102 int32_t* status);
103
104/**
105 * Get the Samples to Average which specifies the number of samples of the timer
106 * to average when calculating the period. Perform averaging to account for
107 * mechanical imperfections or as oversampling to increase resolution.
108 * @return SamplesToAverage The number of samples being averaged (from 1 to 127)
109 */
110int32_t HAL_GetFPGAEncoderSamplesToAverage(
111 HAL_FPGAEncoderHandle fpgaEncoderHandle, int32_t* status);
112
113/**
114 * Set an index source for an encoder, which is an input that resets the
115 * encoder's count.
116 */
117void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpgaEncoderHandle,
118 HAL_Handle digitalSourceHandle,
119 HAL_AnalogTriggerType analogTriggerType,
120 HAL_Bool activeHigh, HAL_Bool edgeSensitive,
121 int32_t* status);
122
123} // extern "C"