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