WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
AnalogInput.h
Go to the documentation of this file.
1// 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.
4
5#pragma once
6
7#include <stdint.h>
8
9#include "wpi/hal/Types.h"
10
11/**
12 * @defgroup hal_analoginput Analog Input Functions
13 * @ingroup hal_capi
14 * @{
15 */
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/**
22 * Initializes the analog input port using the given port object.
23 *
24 * @param[in] channel the smartio channel.
25 * @param[in] allocationLocation the location where the allocation is occurring
26 * (can be null)
27 * @param[out] status the error code, or 0 for success
28 * @return the created analog input handle
29 */
31 int32_t channel, const char* allocationLocation, int32_t* status);
32
33/**
34 * Frees an analog input port.
35 *
36 * @param analogPortHandle Handle to the analog port.
37 */
39
40/**
41 * Checks that the analog module number is valid.
42 *
43 * @param[in] module The analog module number.
44 * @return Analog module is valid and present
45 */
47
48/**
49 * Checks that the analog output channel number is valid.
50 * Verifies that the analog channel number is one of the legal channel numbers.
51 * Channel numbers are 0-based.
52 *
53 * @param[in] channel The analog output channel number.
54 * @return Analog channel is valid
55 */
57
58/**
59 * Indicates the analog input is used by a simulated device.
60 *
61 * @param handle the analog input handle
62 * @param device simulated device handle
63 */
65 HAL_SimDeviceHandle device);
66
67/**
68 * Gets a sample straight from the channel on this module.
69 *
70 * The sample is a 12-bit value representing the 0V to 3.3V range of the A/D
71 * converter in the module. The units are in A/D converter codes. Use
72 * GetVoltage() to get the analog value in calibrated units.
73 *
74 * @param[in] analogPortHandle Handle to the analog port to use.
75 * @param[out] status the error code, or 0 for success
76 * @return A sample straight from the channel on this module.
77 */
79 int32_t* status);
80
81/**
82 * Converts a voltage to a raw value for a specified channel.
83 *
84 * This process depends on the calibration of each channel, so the channel must
85 * be specified.
86 *
87 * @todo This assumes raw values. Oversampling not supported as is.
88 *
89 * @param[in] analogPortHandle Handle to the analog port to use.
90 * @param[in] voltage The voltage to convert.
91 * @param[out] status the error code, or 0 for success
92 * @return The raw value for the channel.
93 */
95 double voltage, int32_t* status);
96
97/**
98 * Gets a scaled sample straight from the channel on this module.
99 *
100 * The value is scaled to units of Volts.
101 *
102 * @param[in] analogPortHandle Handle to the analog port to use.
103 * @param[out] status the error code, or 0 for success
104 * @return A scaled sample straight from the channel on this module.
105 */
107 int32_t* status);
108
109/**
110 * Get the analog voltage from a raw value.
111 *
112 * @param[in] analogPortHandle Handle to the analog port the values were read
113 * from.
114 * @param[in] rawValue The raw analog value
115 * @param[out] status Error status variable. 0 on success.
116 * @return The voltage relating to the value
117 */
119 int32_t rawValue, int32_t* status);
120#ifdef __cplusplus
121} // extern "C"
122#endif
123/** @} */
double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle, int32_t rawValue, int32_t *status)
Get the analog voltage from a raw value.
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(int32_t channel, const char *allocationLocation, int32_t *status)
Initializes the analog input port using the given port object.
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle, int32_t *status)
Gets a scaled sample straight from the channel on this module.
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, int32_t *status)
Gets a sample straight from the channel on this module.
HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel)
Checks that the analog output channel number is valid.
HAL_Bool HAL_CheckAnalogModule(int32_t module)
Checks that the analog module number is valid.
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle, double voltage, int32_t *status)
Converts a voltage to a raw value for a specified channel.
void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle, HAL_SimDeviceHandle device)
Indicates the analog input is used by a simulated device.
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle)
Frees an analog input port.
int32_t HAL_Bool
Definition Types.h:65
HAL_Handle HAL_SimDeviceHandle
Definition Types.h:45
HAL_Handle HAL_AnalogInputHandle
Definition Types.h:21