1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
use core::ffi::*;

pub const NUM_V5_PORTS: usize = 21;
// v5 comp
pub const COMPETITION_DISABLED: i32 = 0b001;
pub const COMPETITION_AUTONOMOUS: i32 = 0b010;
pub const COMPETITION_CONNECTED: i32 = 0b100;
extern "C" {
    pub fn competition_get_status() -> u8;
}
// controller
pub const E_CONTROLLER_MASTER: c_uint = 0;
pub const E_CONTROLLER_PARTNER: c_uint = 1;
pub type controller_id_e_t = c_uint;
pub const E_CONTROLLER_ANALOG_LEFT_X: c_uint = 0;
pub const E_CONTROLLER_ANALOG_LEFT_Y: c_uint = 1;
pub const E_CONTROLLER_ANALOG_RIGHT_X: c_uint = 2;
pub const E_CONTROLLER_ANALOG_RIGHT_Y: c_uint = 3;
pub type controller_analog_e_t = c_uint;
pub const E_CONTROLLER_DIGITAL_L1: c_uint = 6;
pub const E_CONTROLLER_DIGITAL_L2: c_uint = 7;
pub const E_CONTROLLER_DIGITAL_R1: c_uint = 8;
pub const E_CONTROLLER_DIGITAL_R2: c_uint = 9;
pub const E_CONTROLLER_DIGITAL_UP: c_uint = 10;
pub const E_CONTROLLER_DIGITAL_DOWN: c_uint = 11;
pub const E_CONTROLLER_DIGITAL_LEFT: c_uint = 12;
pub const E_CONTROLLER_DIGITAL_RIGHT: c_uint = 13;
pub const E_CONTROLLER_DIGITAL_X: c_uint = 14;
pub const E_CONTROLLER_DIGITAL_B: c_uint = 15;
pub const E_CONTROLLER_DIGITAL_Y: c_uint = 16;
pub const E_CONTROLLER_DIGITAL_A: c_uint = 17;
pub type controller_digital_e_t = c_uint;

extern "C" {
    /**
    Checks if the controller is connected.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER

    \return 1 if the controller is connected, 0 otherwise
    */
    pub fn controller_is_connected(id: controller_id_e_t) -> i32;
    /**
    Gets the value of an analog channel (joystick) on a controller.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
    \param channel
           The analog channel to get.
           Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X,
           ANALOG_RIGHT_Y

    \return The current reading of the analog channel: [-127, 127].
    If the controller was not connected, then 0 is returned
    */
    pub fn controller_get_analog(id: controller_id_e_t, channel: controller_analog_e_t) -> i32;
    /**
    Gets the battery capacity of the given controller.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER

    \return The controller's battery capacity
    */
    pub fn controller_get_battery_capacity(id: controller_id_e_t) -> i32;
    /**
    Gets the battery level of the given controller.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER

    \return The controller's battery level
    */
    pub fn controller_get_battery_level(id: controller_id_e_t) -> i32;
    /**
    Checks if a digital channel (button) on the controller is currently pressed.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
    \param button
           The button to read.
           Must be one of DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}

    \return 1 if the button on the controller is pressed.
    If the controller was not connected, then 0 is returned
    */
    pub fn controller_get_digital(id: controller_id_e_t, button: controller_digital_e_t) -> i32;
    /**
    Returns a rising-edge case for a controller button press.

    This function is not thread-safe.
    Multiple tasks polling a single button may return different results under the
    same circumstances, so only one task should call this function for any given
    button. E.g., Task A calls this function for buttons 1 and 2. Task B may call
    this function for button 3, but should not for buttons 1 or 2. A typical
    use-case for this function is to call inside opcontrol to detect new button
    presses, and not in any other tasks.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
    \param button
                  The button to read. Must be one of
           DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}

    \return 1 if the button on the controller is pressed and had not been pressed
    the last time this function was called, 0 otherwise.
    */
    pub fn controller_get_digital_new_press(
        id: controller_id_e_t,
        button: controller_digital_e_t,
    ) -> i32;
    /**
    Sets text to the controller LCD screen.

    \note Controller text setting is currently in beta, so continuous, fast
    updates will not work well.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
    \param line
           The line number at which the text will be displayed [0-2]
    \param col
           The column number at which the text will be displayed [0-14]
    \param fmt
           The format string to print to the controller
    \param ...
           The argument list for the format string

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn controller_print(
        id: controller_id_e_t,
        line: u8,
        col: u8,
        fmt: *const c_char,
        ...
    ) -> i32;
    /**
    Sets text to the controller LCD screen.

    \note Controller text setting is currently in beta, so continuous, fast
    updates will not work well.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
    \param line
           The line number at which the text will be displayed [0-2]
    \param col
           The column number at which the text will be displayed [0-14]
    \param str
           The pre-formatted string to print to the controller

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn controller_set_text(
        id: controller_id_e_t,
        line: u8,
        col: u8,
        string: *const c_char,
    ) -> i32;
    /**
    Clears an individual line of the controller screen.

    \note Controller text setting is currently in beta, so continuous, fast
    updates will not work well.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
    \param line
           The line number to clear [0-2]

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn controller_clear_line(id: controller_id_e_t, line: u8) -> i32;
    /**
    Clears all of the lines on the controller screen.

    \note Controller text setting is currently in beta, so continuous, fast
    updates will not work well. On vexOS version 1.0.0 this function will block
    for 110ms.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
           The ID of the controller (e.g. the master or partner controller).
           Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn controller_clear(id: controller_id_e_t) -> i32;
    /**
    Rumble the controller.

    \note Controller rumble activation is currently in beta, so continuous, fast
    updates will not work well.

    This function uses the following values of errno when an error state is
    reached:
    EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
    given.
    EACCES - Another resource is currently trying to access the controller port.

    \param id
                   The ID of the controller (e.g. the master or partner controller).
                   Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
    \param rumble_pattern
                   A string consisting of the characters '.', '-', and ' ', where dots
                   are short rumbles, dashes are long rumbles, and spaces are pauses.
                   Maximum supported length is 8 characters.

    \return 1 if the operation was successful or PROS_ERR if the operation
    failed, setting errno.
    */
    pub fn controller_rumble(id: controller_id_e_t, rumble: *const c_char) -> i32;
}

// date and time
extern "C" {
    pub static mut baked_date: *const c_char;
    pub static mut baked_time: *const c_char;
}
#[repr(C)]
pub struct date_s_t {
    /// Year - 1980
    pub year: u16,
    pub day: u8,
    /// 1 = January
    pub month: u8,
}
#[repr(C)]
pub struct time_s_t {
    pub hour: u8,
    pub minute: u8,
    pub sec: u8,
    /// hundredths of a second
    pub sec_hund: u8,
}

// robot

extern "C" {
    /**
    Gets the current voltage of the battery, as reported by VEXos.

    This function uses the following values of errno when an error state is
    reached:
    EACCES - Another resource is currently trying to access the battery port.

    \return The current voltage of the battery
    */
    pub fn battery_get_voltage() -> i32;
    /**
    Gets the current current of the battery, as reported by VEXos.

    This function uses the following values of errno when an error state is
    reached:
    EACCES - Another resource is currently trying to access the battery port.

    \return The current current of the battery
    */
    pub fn battery_get_current() -> i32;
    /**
    Gets the current temperature of the battery, as reported by VEXos.

    This function uses the following values of errno when an error state is
    reached:
    EACCES - Another resource is currently trying to access the battery port.

    \return The current temperature of the battery
    */
    pub fn battery_get_temperature() -> f64;
    /**
    Gets the current capacity of the battery, as reported by VEXos.

    This function uses the following values of errno when an error state is
    reached:
    EACCES - Another resource is currently trying to access the battery port.

    \return The current capacity of the battery
    */
    pub fn battery_get_capacity() -> f64;
    /**
    Checks if the SD card is installed.

    \return 1 if the SD card is installed, 0 otherwise
    */
    pub fn usd_is_installed() -> i32;
}