pros_sys/screen.rs
1//! Brain screen display and touch functions.
2//!
3//! Contains user calls to the v5 screen for touching and displaying graphics.
4
5use core::ffi::{c_char, c_int};
6
7/// Struct representing screen touch status, screen last x, screen last y, press count, release count.
8#[repr(C)]
9pub struct screen_touch_status_s_t {
10 /// Represents if the screen is being held, released, or pressed.
11 pub touch_status: last_touch_e_t,
12
13 /// Represents the x value of the location of the touch.
14 pub x: i16,
15
16 /// Represents the y value of the location of the touch.
17 pub y: i16,
18
19 /// Represents how many times the screen has be pressed.
20 pub press_count: i32,
21
22 /// Represents how many times the user released after a touch on the screen.
23 pub release_count: i32,
24}
25
26pub const E_TEXT_SMALL: c_int = 0;
27pub const E_TEXT_MEDIUM: c_int = 1;
28pub const E_TEXT_LARGE: c_int = 2;
29pub const E_TEXT_MEDIUM_CENTER: c_int = 3;
30pub const E_TEXT_LARGE_CENTER: c_int = 4;
31pub type text_format_e_t = c_int;
32
33pub const E_TOUCH_RELEASED: c_int = 0;
34pub const E_TOUCH_PRESSED: c_int = 1;
35pub const E_TOUCH_HELD: c_int = 2;
36pub const E_TOUCH_ERROR: c_int = 3;
37pub type last_touch_e_t = c_int;
38
39pub type touch_event_cb_fn_t = unsafe extern "C" fn();
40
41extern "C" {
42 /// Set the pen color for subsequent graphics operations
43 ///
44 /// This function uses the following values of errno when an error state is
45 /// reached:
46 /// EACCESS - Another resource is currently trying to access the screen mutex.
47 ///
48 /// \param color The pen color to set (it is recommended to use values
49 /// from the enum defined in colors.h)
50 ///
51 /// \return Returns 1 if the mutex was successfully returned, or PROS_ERR if
52 /// there was an error either taking or returning the screen mutex.
53 ///
54 /// \b Example
55 /// \code
56 /// void initialize() {
57 /// screen_set_pen(COLOR_RED);
58 /// }
59 ///
60 /// void opcontrol() {
61 /// int iter = 0;
62 /// while(1){
63 /// // This should print in red.
64 /// screen_print(TEXT_MEDIUM, 1, "%d", iter++);
65 /// }
66 /// }
67 /// \endcode
68 pub fn screen_set_pen(color: u32) -> u32;
69
70 /// Set the eraser color for erasing and the current background.
71 ///
72 /// This function uses the following values of errno when an error state is
73 /// reached:
74 /// EACCESS - Another resource is currently trying to access the screen mutex.
75 ///
76 /// \param color The background color to set (it is recommended to use values
77 /// from the enum defined in colors.h)
78 ///
79 /// \return Returns 1 if the mutex was successfully returned, or
80 /// PROS_ERR if there was an error either taking or returning the screen mutex.
81 ///
82 /// \b Example
83 /// \code
84 /// void initialize() {
85 /// screen_set_eraser(COLOR_RED);
86 /// }
87 ///
88 /// void opcontrol() {
89 /// while(1){
90 /// // This should turn the screen red.
91 /// screen_erase();
92 /// }
93 /// }
94 /// \endcode
95 pub fn screen_set_eraser(color: u32) -> u32;
96
97 /// Get the current pen color.
98 ///
99 /// This function uses the following values of errno when an error state is
100 /// reached:
101 /// EACCESS - Another resource is currently trying to access the screen mutex.
102 ///
103 /// \return The current pen color in the form of a value from the enum defined
104 /// in colors.h, or PROS_ERR if there was an error taking or returning
105 /// the screen mutex.
106 pub fn screen_get_pen() -> u32;
107
108 /// Get the current eraser color.
109 ///
110 /// This function uses the following values of errno when an error state is
111 /// reached:
112 /// EACCESS - Another resource is currently trying to access the screen mutex.
113 ///
114 /// \return The current eraser color in the form of a value from the enum
115 /// defined in colors.h, or PROS_ERR if there was an error taking or
116 /// returning the screen mutex.
117 pub fn screen_get_eraser() -> u32;
118
119 /// Clear display with eraser color
120 ///
121 /// This function uses the following values of errno when an error state is
122 /// reached:
123 /// EACCESS - Another resource is currently trying to access the screen mutex.
124 ///
125 /// \return 1 if there were no errors, or PROS_ERR if an error occured
126 /// taking or returning the screen mutex.
127 pub fn screen_erase() -> u32;
128
129 /// Scroll lines on the display upwards.
130 ///
131 /// This function uses the following values of errno when an error state is
132 /// reached:
133 /// EACCESS - Another resource is currently trying to access the screen mutex.
134 ///
135 ///
136 /// \param start_line The line from which scrolling will start
137 /// \param lines The number of lines to scroll up
138 ///
139 /// \return 1 if there were no errors, or PROS_ERR if an error occured
140 /// taking or returning the screen mutex.
141 pub fn screen_scroll(start_line: i16, lines: i16) -> u32;
142
143 /// Scroll lines within a region on the display
144 ///
145 /// This function behaves in the same way as `screen_scroll`, except that you
146 /// specify a rectangular region within which to scroll lines instead of a start
147 /// line.
148 ///
149 /// This function uses the following values of errno when an error state is
150 /// reached:
151 /// EACCESS - Another resource is currently trying to access the screen mutex.
152 ///
153 /// \param x0, y0 The (x,y) coordinates of the first corner of the
154 /// rectangular region
155 /// \param x1, y1 The (x,y) coordinates of the second corner of the
156 /// rectangular region
157 /// \param lines The number of lines to scroll upwards
158 ///
159 /// \return 1 if there were no errors, or PROS_ERR if an error occured
160 /// taking or returning the screen mutex.
161 pub fn screen_scroll_area(x0: i16, y0: i16, x1: i16, y1: i16, lines: i16) -> u32;
162
163 /// Copy a screen region (designated by a rectangle) from an off-screen buffer
164 /// to the screen
165 ///
166 /// This function uses the following values of errno when an error state is
167 /// reached:
168 /// EACCESS - Another resource is currently trying to access the screen mutex.
169 ///
170 /// \param x0, y0 The (x,y) coordinates of the first corner of the
171 /// rectangular region of the screen
172 /// \param x1, y1 The (x,y) coordinates of the second corner of the
173 /// rectangular region of the screen
174 /// \param buf Off-screen buffer containing screen data
175 /// \param stride Off-screen buffer width in pixels, such that image size
176 /// is stride-padding
177 ///
178 /// \return 1 if there were no errors, or PROS_ERR if an error occured
179 /// taking or returning the screen mutex.
180 pub fn screen_copy_area(
181 x0: i16,
182 y0: i16,
183 x1: i16,
184 y1: i16,
185 buf: *const u32,
186 stride: i32,
187 ) -> u32;
188
189 /// Draw a single pixel on the screen using the current pen color
190 ///
191 /// This function uses the following values of errno when an error state is
192 /// reached:
193 /// EACCESS - Another resource is currently trying to access the screen mutex.
194 ///
195 /// \param x, y The (x,y) coordinates of the pixel
196 ///
197 /// \return 1 if there were no errors, or PROS_ERR if an error occured
198 /// taking or returning the screen mutex.
199 pub fn screen_draw_pixel(x: i16, y: i16) -> u32;
200
201 /// Erase a pixel from the screen (Sets the location)
202 ///
203 /// This function uses the following values of errno when an error state is
204 /// reached:
205 /// EACCESS - Another resource is currently trying to access the screen mutex.
206 ///
207 /// \param x, y The (x,y) coordinates of the erased
208 ///
209 /// \return 1 if there were no errors, or PROS_ERR if an error occured
210 /// taking or returning the screen mutex.
211 pub fn screen_erase_pixel(x: i16, y: i16) -> u32;
212
213 /// Draw a line on the screen using the current pen color
214 ///
215 /// This function uses the following values of errno when an error state is
216 /// reached:
217 /// EACCESS - Another resource is currently trying to access the screen mutex.
218 ///
219 /// \param x0, y0 The (x, y) coordinates of the first point of the line
220 /// \param x1, y1 The (x, y) coordinates of the second point of the line
221 ///
222 /// \return 1 if there were no errors, or PROS_ERR if an error occured
223 /// taking or returning the screen mutex.
224 pub fn screen_draw_line(x0: i16, y0: i16, x1: i16, y1: i16) -> u32;
225
226 /// Erase a line on the screen using the current eraser color
227 ///
228 /// This function uses the following values of errno when an error state is
229 /// reached:
230 /// EACCESS - Another resource is currently trying to access the screen mutex.
231 ///
232 /// \param x0, y0 The (x, y) coordinates of the first point of the line
233 /// \param x1, y1 The (x, y) coordinates of the second point of the line
234 ///
235 /// \return 1 if there were no errors, or PROS_ERR if an error occured
236 /// taking or returning the screen mutex.
237 pub fn screen_erase_line(x0: i16, y0: i16, x1: i16, y1: i16) -> u32;
238
239 /// Draw a rectangle on the screen using the current pen color
240 ///
241 /// This function uses the following values of errno when an error state is
242 /// reached:
243 /// EACCESS - Another resource is currently trying to access the screen mutex.
244 ///
245 /// \param x0, y0 The (x,y) coordinates of the first point of the rectangle
246 /// \param x1, y1 The (x,y) coordinates of the second point of the rectangle
247 ///
248 /// \return 1 if there were no errors, or PROS_ERR if an error occured
249 /// taking or returning the screen mutex.
250 pub fn screen_draw_rect(x0: i16, y0: i16, x1: i16, y1: i16) -> u32;
251
252 /// Erase a rectangle on the screen using the current eraser color
253 ///
254 /// This function uses the following values of errno when an error state is
255 /// reached:
256 /// EACCESS - Another resource is currently trying to access the screen mutex.
257 ///
258 /// \param x0, y0 The (x,y) coordinates of the first point of the rectangle
259 /// \param x1, y1 The (x,y) coordinates of the second point of the rectangle
260 ///
261 /// \return 1 if there were no errors, or PROS_ERR if an error occured
262 /// taking or returning the screen mutex.
263 pub fn screen_erase_rect(x0: i16, y0: i16, x1: i16, y1: i16) -> u32;
264
265 /// Fill a rectangular region of the screen using the current pen
266 /// color
267 ///
268 /// This function uses the following values of errno when an error state is
269 /// reached:
270 /// EACCESS - Another resource is currently trying to access the screen mutex.
271 ///
272 /// \param x0, y0 The (x,y) coordinates of the first point of the rectangle
273 /// \param x1, y1 The (x,y) coordinates of the second point of the rectangle
274 ///
275 /// \return 1 if there were no errors, or PROS_ERR if an error occured
276 /// taking or returning the screen mutex.
277 pub fn screen_fill_rect(x0: i16, y0: i16, x1: i16, y1: i16) -> u32;
278
279 /// Draw a circle on the screen using the current pen color
280 ///
281 /// This function uses the following values of errno when an error state is
282 /// reached:
283 /// EACCESS - Another resource is currently trying to access the screen mutex.
284 ///
285 /// \param x, y The (x,y) coordinates of the center of the circle
286 /// \param r The radius of the circle
287 ///
288 /// \return 1 if there were no errors, or PROS_ERR if an error occured
289 /// taking or returning the screen mutex.
290 pub fn screen_draw_circle(x: i16, y: i16, radius: i16) -> u32;
291
292 /// Erase a circle on the screen using the current eraser color
293 ///
294 /// This function uses the following values of errno when an error state is
295 /// reached:
296 /// EACCESS - Another resource is currently trying to access the screen mutex.
297 ///
298 /// \param x, y The (x,y) coordinates of the center of the circle
299 /// \param r The radius of the circle
300 ///
301 /// \return 1 if there were no errors, or PROS_ERR if an error occured
302 /// taking or returning the screen mutex.
303 pub fn screen_erase_circle(x: i16, y: i16, radius: i16) -> u32;
304
305 /// Fill a circular region of the screen using the current pen
306 /// color
307 ///
308 /// This function uses the following values of errno when an error state is
309 /// reached:
310 /// EACCESS - Another resource is currently trying to access the screen mutex.
311 ///
312 /// \param x, y The (x,y) coordinates of the center of the circle
313 /// \param r The radius of the circle
314 ///
315 /// \return 1 if there were no errors, or PROS_ERR if an error occured
316 /// taking or returning the screen mutex.
317 pub fn screen_fill_circle(x: i16, y: i16, radius: i16) -> u32;
318
319 /// Print a formatted string to the screen on the specified line
320 ///
321 /// Will default to a medium sized font by default if invalid txt_fmt is given.
322 ///
323 /// \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES
324 /// NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param ... Optional list
325 /// of arguments for the format string
326 ///
327 /// \return 1 if there were no errors, or PROS_ERR if an error occured
328 /// taking or returning the screen mutex.
329 pub fn screen_print(
330 txt_fmt: text_format_e_t,
331 line: i16,
332 text: *const core::ffi::c_char,
333 ...
334 ) -> u32;
335
336 /// Print a formatted string to the screen at the specified point
337 ///
338 /// Will default to a medium sized font by default if invalid txt_fmt is given.
339 ///
340 /// Text formats medium_center and large_center will default to medium and large respectively.
341 ///
342 /// \param txt_fmt Text format enum that determines if the text is small, medium, or large.
343 /// \param x The y coordinate of the top left corner of the string
344 /// \param y The x coordinate of the top left corner of the string
345 /// \param text Format string
346 /// \param ... Optional list of arguments for the format string
347 ///
348 /// \return 1 if there were no errors, or PROS_ERR if an error occured
349 /// taking or returning the screen mutex.
350 pub fn screen_print_at(
351 txt_fmt: text_format_e_t,
352 x: i16,
353 y: i16,
354 text: *const core::ffi::c_char,
355 ...
356 ) -> u32;
357
358 /// Print a formatted string to the screen on the specified line
359 ///
360 /// Same as `display_printf` except that this uses a `va_list` instead of the
361 /// ellipsis operator so this can be used by other functions.
362 ///
363 /// Will default to a medium sized font by default if invalid txt_fmt is given.
364 /// Exposed mostly for writing libraries and custom functions.
365 ///
366 /// This function uses the following values of errno when an error state is
367 /// reached:
368 /// EACCESS - Another resource is currently trying to access the screen mutex.
369 ///
370 /// \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES
371 /// NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param args List of
372 /// arguments for the format string
373 ///
374 /// \return 1 if there were no errors, or PROS_ERR if an error occured
375 /// while taking or returning the screen mutex.
376 pub fn screen_vprintf(
377 txt_fmt: text_format_e_t,
378 line: i16,
379 text: *const core::ffi::c_char,
380 ...
381 ) -> u32;
382
383 /// Gets the touch status of the last touch of the screen.
384 ///
385 /// \return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE,
386 /// E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD). This will be released by default if no action was taken. If an
387 /// error occured, the screen_touch_status_s_t will have its last_touch_e_t enum specifier set to E_TOUCH_ERR, and other
388 /// values set to -1.
389 pub fn screen_touch_status() -> screen_touch_status_s_t;
390
391 /// Assigns a callback function to be called when a certain touch event happens.
392 ///
393 /// This function uses the following values of errno when an error state is
394 /// reached:
395 /// EACCESS - Another resource is currently trying to access the screen mutex.
396 ///
397 /// \param cb Function pointer to callback when event type happens
398 /// \param event_type Touch event that will trigger the callback.
399 ///
400 /// \return 1 if there were no errors, or PROS_ERR if an error occured
401 /// while taking or returning the screen mutex.
402 pub fn screen_touch_callback(cb: touch_event_cb_fn_t, event_type: last_touch_e_t) -> u32;
403
404 /// Display a fatal error to the built-in LCD/touch screen.
405 ///
406 /// This function is intended to be used when the integrity of the RTOS cannot be
407 /// trusted. No thread-safety mechanisms are used and this function only relies
408 /// on the use of the libv5rts.
409 pub fn display_fatal_error(text: *const c_char);
410}