pros_sys/
misc.rs

1use core::ffi::*;
2
3pub const NUM_V5_PORTS: usize = 21;
4// v5 comp
5pub const COMPETITION_AUTONOMOUS: u8 = 1 << 0;
6pub const COMPETITION_DISABLED: u8 = 1 << 1;
7pub const COMPETITION_CONNECTED: u8 = 1 << 2;
8extern "C" {
9    /// Get the current status of the competition control.
10    /// Returns The competition control status as a mask of bits with COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}.
11    pub fn competition_get_status() -> u8;
12}
13// controller
14pub const E_CONTROLLER_MASTER: c_uint = 0;
15pub const E_CONTROLLER_PARTNER: c_uint = 1;
16pub type controller_id_e_t = c_uint;
17pub const E_CONTROLLER_ANALOG_LEFT_X: c_uint = 0;
18pub const E_CONTROLLER_ANALOG_LEFT_Y: c_uint = 1;
19pub const E_CONTROLLER_ANALOG_RIGHT_X: c_uint = 2;
20pub const E_CONTROLLER_ANALOG_RIGHT_Y: c_uint = 3;
21pub type controller_analog_e_t = c_uint;
22pub const E_CONTROLLER_DIGITAL_L1: c_uint = 6;
23pub const E_CONTROLLER_DIGITAL_L2: c_uint = 7;
24pub const E_CONTROLLER_DIGITAL_R1: c_uint = 8;
25pub const E_CONTROLLER_DIGITAL_R2: c_uint = 9;
26pub const E_CONTROLLER_DIGITAL_UP: c_uint = 10;
27pub const E_CONTROLLER_DIGITAL_DOWN: c_uint = 11;
28pub const E_CONTROLLER_DIGITAL_LEFT: c_uint = 12;
29pub const E_CONTROLLER_DIGITAL_RIGHT: c_uint = 13;
30pub const E_CONTROLLER_DIGITAL_X: c_uint = 14;
31pub const E_CONTROLLER_DIGITAL_B: c_uint = 15;
32pub const E_CONTROLLER_DIGITAL_Y: c_uint = 16;
33pub const E_CONTROLLER_DIGITAL_A: c_uint = 17;
34pub type controller_digital_e_t = c_uint;
35
36extern "C" {
37    /**
38    Checks if the controller is connected.
39
40    This function uses the following values of errno when an error state is
41    reached:
42    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
43    given.
44    EACCES - Another resource is currently trying to access the controller port.
45
46    \param id
47           The ID of the controller (e.g. the master or partner controller).
48           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
49
50    \return 1 if the controller is connected, 0 otherwise
51    */
52    pub fn controller_is_connected(id: controller_id_e_t) -> i32;
53    /**
54    Gets the value of an analog channel (joystick) on a controller.
55
56    This function uses the following values of errno when an error state is
57    reached:
58    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
59    given.
60    EACCES - Another resource is currently trying to access the controller port.
61
62    \param id
63           The ID of the controller (e.g. the master or partner controller).
64           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
65    \param channel
66           The analog channel to get.
67           Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X,
68           ANALOG_RIGHT_Y
69
70    \return The current reading of the analog channel: [-127, 127].
71    If the controller was not connected, then 0 is returned
72    */
73    pub fn controller_get_analog(id: controller_id_e_t, channel: controller_analog_e_t) -> i32;
74    /**
75    Gets the battery capacity of the given controller.
76
77    This function uses the following values of errno when an error state is
78    reached:
79    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
80    given.
81    EACCES - Another resource is currently trying to access the controller port.
82
83    \param id
84           The ID of the controller (e.g. the master or partner controller).
85           Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER
86
87    \return The controller's battery capacity
88    */
89    pub fn controller_get_battery_capacity(id: controller_id_e_t) -> i32;
90    /**
91    Gets the battery level of the given controller.
92
93    This function uses the following values of errno when an error state is
94    reached:
95    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
96    given.
97    EACCES - Another resource is currently trying to access the controller port.
98
99    \param id
100           The ID of the controller (e.g. the master or partner controller).
101           Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER
102
103    \return The controller's battery level
104    */
105    pub fn controller_get_battery_level(id: controller_id_e_t) -> i32;
106    /**
107    Checks if a digital channel (button) on the controller is currently pressed.
108
109    This function uses the following values of errno when an error state is
110    reached:
111    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
112    given.
113    EACCES - Another resource is currently trying to access the controller port.
114
115    \param id
116           The ID of the controller (e.g. the master or partner controller).
117           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
118    \param button
119           The button to read.
120           Must be one of DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
121
122    \return 1 if the button on the controller is pressed.
123    If the controller was not connected, then 0 is returned
124    */
125    pub fn controller_get_digital(id: controller_id_e_t, button: controller_digital_e_t) -> i32;
126    /**
127    Returns a rising-edge case for a controller button press.
128
129    This function is not thread-safe.
130    Multiple tasks polling a single button may return different results under the
131    same circumstances, so only one task should call this function for any given
132    button. E.g., Task A calls this function for buttons 1 and 2. Task B may call
133    this function for button 3, but should not for buttons 1 or 2. A typical
134    use-case for this function is to call inside opcontrol to detect new button
135    presses, and not in any other tasks.
136
137    This function uses the following values of errno when an error state is
138    reached:
139    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
140    given.
141    EACCES - Another resource is currently trying to access the controller port.
142
143    \param id
144           The ID of the controller (e.g. the master or partner controller).
145           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
146    \param button
147                  The button to read. Must be one of
148           DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
149
150    \return 1 if the button on the controller is pressed and had not been pressed
151    the last time this function was called, 0 otherwise.
152    */
153    pub fn controller_get_digital_new_press(
154        id: controller_id_e_t,
155        button: controller_digital_e_t,
156    ) -> i32;
157    /**
158    Sets text to the controller LCD screen.
159
160    \note Controller text setting is currently in beta, so continuous, fast
161    updates will not work well.
162
163    This function uses the following values of errno when an error state is
164    reached:
165    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
166    given.
167    EACCES - Another resource is currently trying to access the controller port.
168
169    \param id
170           The ID of the controller (e.g. the master or partner controller).
171           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
172    \param line
173           The line number at which the text will be displayed [0-2]
174    \param col
175           The column number at which the text will be displayed [0-14]
176    \param fmt
177           The format string to print to the controller
178    \param ...
179           The argument list for the format string
180
181    \return 1 if the operation was successful or PROS_ERR if the operation
182    failed, setting errno.
183    */
184    pub fn controller_print(
185        id: controller_id_e_t,
186        line: u8,
187        col: u8,
188        fmt: *const c_char,
189        ...
190    ) -> i32;
191    /**
192    Sets text to the controller LCD screen.
193
194    \note Controller text setting is currently in beta, so continuous, fast
195    updates will not work well.
196
197    This function uses the following values of errno when an error state is
198    reached:
199    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
200    given.
201    EACCES - Another resource is currently trying to access the controller port.
202
203    \param id
204           The ID of the controller (e.g. the master or partner controller).
205           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
206    \param line
207           The line number at which the text will be displayed [0-2]
208    \param col
209           The column number at which the text will be displayed [0-14]
210    \param str
211           The pre-formatted string to print to the controller
212
213    \return 1 if the operation was successful or PROS_ERR if the operation
214    failed, setting errno.
215    */
216    pub fn controller_set_text(
217        id: controller_id_e_t,
218        line: u8,
219        col: u8,
220        string: *const c_char,
221    ) -> i32;
222    /**
223    Clears an individual line of the controller screen.
224
225    \note Controller text setting is currently in beta, so continuous, fast
226    updates will not work well.
227
228    This function uses the following values of errno when an error state is
229    reached:
230    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
231    given.
232    EACCES - Another resource is currently trying to access the controller port.
233
234    \param id
235           The ID of the controller (e.g. the master or partner controller).
236           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
237    \param line
238           The line number to clear [0-2]
239
240    \return 1 if the operation was successful or PROS_ERR if the operation
241    failed, setting errno.
242    */
243    pub fn controller_clear_line(id: controller_id_e_t, line: u8) -> i32;
244    /**
245    Clears all of the lines on the controller screen.
246
247    \note Controller text setting is currently in beta, so continuous, fast
248    updates will not work well. On vexOS version 1.0.0 this function will block
249    for 110ms.
250
251    This function uses the following values of errno when an error state is
252    reached:
253    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
254    given.
255    EACCES - Another resource is currently trying to access the controller port.
256
257    \param id
258           The ID of the controller (e.g. the master or partner controller).
259           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
260
261    \return 1 if the operation was successful or PROS_ERR if the operation
262    failed, setting errno.
263    */
264    pub fn controller_clear(id: controller_id_e_t) -> i32;
265    /**
266    Rumble the controller.
267
268    \note Controller rumble activation is currently in beta, so continuous, fast
269    updates will not work well.
270
271    This function uses the following values of errno when an error state is
272    reached:
273    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
274    given.
275    EACCES - Another resource is currently trying to access the controller port.
276
277    \param id
278                   The ID of the controller (e.g. the master or partner controller).
279                   Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
280    \param rumble_pattern
281                   A string consisting of the characters '.', '-', and ' ', where dots
282                   are short rumbles, dashes are long rumbles, and spaces are pauses.
283                   Maximum supported length is 8 characters.
284
285    \return 1 if the operation was successful or PROS_ERR if the operation
286    failed, setting errno.
287    */
288    pub fn controller_rumble(id: controller_id_e_t, rumble: *const c_char) -> i32;
289}
290
291// date and time
292extern "C" {
293    pub static mut baked_date: *const c_char;
294    pub static mut baked_time: *const c_char;
295}
296#[repr(C)]
297pub struct date_s_t {
298    /// Year - 1980
299    pub year: u16,
300    pub day: u8,
301    /// 1 = January
302    pub month: u8,
303}
304#[repr(C)]
305pub struct time_s_t {
306    pub hour: u8,
307    pub minute: u8,
308    pub sec: u8,
309    /// hundredths of a second
310    pub sec_hund: u8,
311}
312
313// robot
314
315extern "C" {
316    /**
317    Gets the current voltage of the battery, as reported by VEXos.
318
319    This function uses the following values of errno when an error state is
320    reached:
321    EACCES - Another resource is currently trying to access the battery port.
322
323    \return The current voltage of the battery
324    */
325    pub fn battery_get_voltage() -> i32;
326    /**
327    Gets the current current of the battery, as reported by VEXos.
328
329    This function uses the following values of errno when an error state is
330    reached:
331    EACCES - Another resource is currently trying to access the battery port.
332
333    \return The current current of the battery
334    */
335    pub fn battery_get_current() -> i32;
336    /**
337    Gets the current temperature of the battery, as reported by VEXos.
338
339    This function uses the following values of errno when an error state is
340    reached:
341    EACCES - Another resource is currently trying to access the battery port.
342
343    \return The current temperature of the battery
344    */
345    pub fn battery_get_temperature() -> f64;
346    /**
347    Gets the current capacity of the battery, as reported by VEXos.
348
349    This function uses the following values of errno when an error state is
350    reached:
351    EACCES - Another resource is currently trying to access the battery port.
352
353    \return The current capacity of the battery
354    */
355    pub fn battery_get_capacity() -> f64;
356    /**
357    Checks if the SD card is installed.
358
359    \return 1 if the SD card is installed, 0 otherwise
360    */
361    pub fn usd_is_installed() -> i32;
362}