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
#[macro_export]
/// Specifies the entrypoint for the robot.
///
/// # Examples
///
/// ```
/// #![no_std]
/// #![no_main]
///
/// use vex_rt::prelude::*;
///
/// struct FooBot;
///
/// impl Robot for FooBot {
///     fn new(_p: Peripherals) -> Self {
///         FooBot
///     }
/// }
///
/// entry!(FooBot);
/// ```
macro_rules! entry {
    ($robot_type:ty) => {
        static ROBOT: $crate::once::Once<($robot_type, Competition)> = $crate::once::Once::new();

        #[no_mangle]
        unsafe extern "C" fn initialize() {
            $crate::rtos::Task::spawn(|| {
                ROBOT.call_once(|| {
                    (
                        $crate::robot::Robot::new(unsafe {
                            $crate::peripherals::Peripherals::new()
                        }),
                        Competition::new(),
                    )
                });
            })
            .expect("failed to launch task for initialize()");
        }

        #[no_mangle]
        extern "C" fn opcontrol() {
            ROBOT.wait().1.opcontrol();
        }

        #[no_mangle]
        extern "C" fn autonomous() {
            ROBOT.wait().1.autonomous();
        }

        #[no_mangle]
        extern "C" fn disabled() {
            ROBOT.wait().1.disabled();
        }

        $crate::state_machine! {
            /// State machine for the competition modes.
            pub Competition = initialize();

            #[inline]
            /// Initialization stage of the robot.
            initialize(ctx) {
                $crate::robot::Robot::initialize(&ROBOT.wait().0, ctx);
            }

            #[inline]
            /// Driver control period.
            opcontrol(ctx) {
                $crate::robot::Robot::opcontrol(&ROBOT.wait().0, ctx);
            }

            #[inline]
            /// Autonomous period.
            autonomous(ctx) {
                $crate::robot::Robot::autonomous(&ROBOT.wait().0, ctx);
            }

            #[inline]
            /// Disabled period.
            disabled(ctx) {
                $crate::robot::Robot::disabled(&ROBOT.wait().0, ctx);
            }
        }
    };
}