vex_rt/macros/
entry.rs

1#[macro_export]
2/// Specifies the entrypoint for the robot.
3///
4/// # Examples
5///
6/// ```
7/// #![no_std]
8/// #![no_main]
9///
10/// use vex_rt::prelude::*;
11///
12/// struct FooBot;
13///
14/// impl Robot for FooBot {
15///     fn new(_p: Peripherals) -> Self {
16///         FooBot
17///     }
18/// }
19///
20/// entry!(FooBot);
21/// ```
22macro_rules! entry {
23    ($robot_type:ty) => {
24        static ROBOT: $crate::once::Once<$crate::robot::Competition<$robot_type>> =
25            $crate::once::Once::new();
26
27        #[no_mangle]
28        unsafe extern "C" fn initialize() {
29            ROBOT.call_once(|| {
30                Competition::new($crate::robot::Robot::new(unsafe {
31                    $crate::peripherals::Peripherals::new()
32                }))
33            });
34        }
35
36        #[no_mangle]
37        extern "C" fn opcontrol() {
38            ROBOT.wait().opcontrol();
39        }
40
41        #[no_mangle]
42        extern "C" fn autonomous() {
43            ROBOT.wait().autonomous();
44        }
45
46        #[no_mangle]
47        extern "C" fn disabled() {
48            ROBOT.wait().disabled();
49        }
50    };
51}