pros_sys/
optical.rs

1use core::ffi::*;
2
3use crate::PROS_ERR;
4
5pub const OPT_GESTURE_ERR: i8 = i8::MAX;
6pub const OPT_COUNT_ERR: i16 = i16::MAX;
7pub const OPT_TIME_ERR: i32 = PROS_ERR;
8
9#[repr(C)]
10pub struct optical_rgb_s_t {
11    pub red: f64,
12    pub green: f64,
13    pub blue: f64,
14    pub brightness: f64,
15}
16
17#[repr(C)]
18pub struct optical_raw_s_t {
19    pub clear: u32,
20    pub red: u32,
21    pub green: u32,
22    pub blue: u32,
23}
24
25#[repr(C)]
26pub struct optical_gesture_s_t {
27    pub udata: u8,
28    pub ddata: u8,
29    pub ldata: u8,
30    pub rdata: u8,
31    pub r#type: u8,
32    pub pad: u8,
33    pub count: u16,
34    pub time: u32,
35}
36
37pub const E_OPTICAL_DIRECTION_NO_GESTURE: c_int = 0;
38pub const E_OPTICAL_DIRECTION_UP: c_int = 1;
39pub const E_OPTICAL_DIRECTION_DOWN: c_int = 2;
40pub const E_OPTICAL_DIRECTION_RIGHT: c_int = 3;
41pub const E_OPTICAL_DIRECTION_LEFT: c_int = 4;
42pub const E_OPTICAL_DIRECTION_ERROR: c_int = PROS_ERR;
43pub type optical_direction_e_t = c_int;
44
45extern "C" {
46
47    /// Get the detected color hue
48    ///
49    /// This is not available if gestures are being detected. Hue has a
50    /// range of 0 to 359.999
51    ///
52    /// This function uses the following values of errno when an error state is
53    /// reached:
54    /// ENXIO - The given value is not within the range of V5 ports (1-21).
55    /// ENODEV - The port cannot be configured as an Optical Sensor
56    ///
57    /// \param port
58    ///        The V5 Optical Sensor port number from 1-21
59    /// \return hue value if the operation was successful or PROS_ERR_F if the operation
60    /// failed, setting errno.
61    pub fn optical_get_hue(port: u8) -> f64;
62
63    /// Get the detected color saturation
64    ///
65    /// This is not available if gestures are being detected. Saturation has a
66    /// range of 0 to 1.0
67    ///
68    /// This function uses the following values of errno when an error state is
69    /// reached:
70    /// ENXIO - The given value is not within the range of V5 ports (1-21).
71    /// ENODEV - The port cannot be configured as an Optical Sensor
72    ///
73    /// \param port
74    ///        The V5 Optical Sensor port number from 1-21
75    /// \return saturation value if the operation was successful or PROS_ERR_F if
76    /// the operation failed, setting errno.
77    pub fn optical_get_saturation(port: u8) -> f64;
78
79    /// Get the detected color brightness
80    ///
81    /// This is not available if gestures are being detected. Brightness has a
82    /// range of 0 to 1.0
83    ///
84    /// This function uses the following values of errno when an error state is
85    /// reached:
86    /// ENXIO - The given value is not within the range of V5 ports (1-21).
87    /// ENODEV - The port cannot be configured as an Optical Sensor
88    ///
89    /// \param port
90    ///        The V5 Optical Sensor port number from 1-21
91    /// \return brightness value if the operation was successful or PROS_ERR_F if
92    /// the operation failed, setting errno.
93    pub fn optical_get_brightness(port: u8) -> f64;
94
95    /// Get the detected proximity value
96    ///
97    /// This is not available if gestures are being detected. proximity has
98    /// a range of 0 to 255.
99    ///
100    /// This function uses the following values of errno when an error state is
101    /// reached:
102    /// ENXIO - The given value is not within the range of V5 ports (1-21).
103    /// ENODEV - The port cannot be configured as an Optical Sensor
104    ///
105    /// \param port
106    ///        The V5 Optical Sensor port number from 1-21
107    /// \return poximity value if the operation was successful or PROS_ERR if
108    /// the operation failed, setting errno.
109    pub fn optical_get_proximity(port: u8) -> i32;
110
111    /// Set the pwm value of the White LED
112    ///
113    /// value that ranges from 0 to 100
114    ///
115    /// This function uses the following values of errno when an error state is
116    /// reached:
117    /// ENXIO - The given value is not within the range of V5 ports (1-21).
118    /// ENODEV - The port cannot be configured as an Optical Sensor
119    ///
120    /// \param port
121    ///        The V5 Optical Sensor port number from 1-21
122    /// \return 1 if the operation is successful or PROS_ERR if the operation failed,
123    /// setting errno.
124    pub fn optical_set_led_pwm(port: u8, value: u8) -> i32;
125
126    /// Get the pwm value of the White LED
127    ///
128    ///
129    /// This function uses the following values of errno when an error state is
130    /// reached:
131    /// ENXIO - The given value is not within the range of V5 ports (1-21).
132    /// ENODEV - The port cannot be configured as an Optical Sensor
133    ///
134    /// \param port
135    ///        The V5 Optical Sensor port number from 1-21
136    /// \return LED pwm value that ranges from 0 to 100 if the operation was
137    /// successful or PROS_ERR if the operation failed, setting errno.
138    pub fn optical_get_led_pwm(port: u8) -> i32;
139
140    /// Get the processed RGBC data from the sensor
141    ///
142    /// This function uses the following values of errno when an error state is
143    /// reached:
144    /// ENXIO - The given value is not within the range of V5 ports (1-21).
145    /// ENODEV - The port cannot be configured as an Optical Sensor
146    ///
147    /// \param port
148    ///        The V5 Optical Sensor port number from 1-21
149    /// \return rgb value if the operation was successful or an optical_rgb_s_t with
150    /// all fields set to PROS_ERR if the operation failed, setting errno.
151    pub fn optical_get_rgb(port: u8) -> optical_rgb_s_t;
152
153    /// Get the raw, unprocessed RGBC data from the sensor
154    ///
155    /// This function uses the following values of errno when an error state is
156    /// reached:
157    /// ENXIO - The given value is not within the range of V5 ports (1-21).
158    /// ENODEV - The port cannot be configured as an Optical Sensor
159    ///
160    /// \param port
161    ///        The V5 Optical Sensor port number from 1-21
162    /// \return raw rgb value if the operation was successful or an optical_raw_s_t
163    /// with all fields set to PROS_ERR if the operation failed, setting errno.
164    pub fn optical_get_raw(port: u8) -> optical_raw_s_t;
165
166    /// Get the most recent gesture data from the sensor
167    ///
168    /// Gestures will be cleared after 500mS
169    ///
170    /// This function uses the following values of errno when an error state is
171    /// reached:
172    /// ENXIO - The given value is not within the range of V5 ports (1-21).
173    /// ENODEV - The port cannot be configured as an Optical Sensor
174    ///
175    /// \param port
176    ///        The V5 Optical Sensor port number from 1-21
177    /// \return gesture value if the operation was successful or PROS_ERR if
178    /// the operation failed, setting errno.
179    pub fn optical_get_gesture(port: u8) -> optical_direction_e_t;
180
181    /// Get the most recent raw gesture data from the sensor
182    ///
183    /// This function uses the following values of errno when an error state is
184    /// reached:
185    /// ENXIO - The given value is not within the range of V5 ports (1-21).
186    /// ENODEV - The port cannot be configured as an Optical Sensor
187    ///
188    /// \param port
189    ///        The V5 Optical Sensor port number from 1-21
190    /// \return gesture value if the operation was successful or an optical_gesture_s_t
191    /// with all fields set to PROS_ERR if the operation failed, setting errno.
192    pub fn optical_get_gesture_raw(port: u8) -> optical_gesture_s_t;
193
194    /// Enable gesture detection on the sensor
195    ///
196    /// This function uses the following values of errno when an error state is
197    /// reached:
198    /// ENXIO - The given value is not within the range of V5 ports (1-21).
199    /// ENODEV - The port cannot be configured as an Optical Sensor
200    ///
201    /// \param port
202    ///        The V5 Optical Sensor port number from 1-21
203    /// \return 1 if the operation is successful or PROS_ERR if the operation failed,
204    /// setting errno.
205    pub fn optical_enable_gesture(port: u8) -> i32;
206
207    /// Disable gesture detection on the sensor
208    ///
209    /// This function uses the following values of errno when an error state is
210    /// reached:
211    /// ENXIO - The given value is not within the range of V5 ports (1-21).
212    /// ENODEV - The port cannot be configured as an Optical Sensor
213    ///
214    /// \param port
215    ///        The V5 Optical Sensor port number from 1-21
216    /// \return 1 if the operation is successful or PROS_ERR if the operation failed,
217    /// setting errno.
218    pub fn optical_disable_gesture(port: u8) -> i32;
219
220    /// Get integration time (update rate) of the optical sensor in milliseconds, with
221    /// minimum time being
222    ///
223    /// This function uses the following values of errno when an error state is
224    /// reached:
225    /// ENXIO - The given value is not within the range of V5 ports (1-21).
226    /// ENODEV - The port cannot be configured as an Optical Sensor
227    ///
228    /// \param port
229    ///        The V5 Optical Sensor port number from 1-21
230    /// \return Integration time in milliseconds if the operation is successful
231    /// or PROS_ERR if the operation failed, setting errno.
232    pub fn optical_get_integration_time(port: u8) -> f64;
233
234    /// Set integration time (update rate) of the optical sensor in milliseconds.
235    ///
236    /// This function uses the following values of errno when an error state is
237    /// reached:
238    /// ENXIO - The given value is not within the range of V5 ports (1-21).
239    /// ENODEV - The port cannot be configured as an Optical Sensor
240    ///
241    /// \param port
242    ///        The V5 Optical Sensor port number from 1-21
243    /// \param time
244    ///        The desired integration time in milliseconds
245    /// \return 1 if the operation is successful or PROS_ERR if the operation failed,
246    /// setting errno.
247    pub fn optical_set_integration_time(port: u8, time: f64) -> i32;
248}