-
Notifications
You must be signed in to change notification settings - Fork 1
/
vex_competition.h
150 lines (128 loc) · 5.95 KB
/
vex_competition.h
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
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) Innovation First 2017, All rights reserved. */
/* */
/* Module: vex_competition.h */
/* Author: James Pearman */
/* Created: 6 Nov 2017 */
/* */
/* Revisions: */
/* V1.00 TBD - Initial release */
/* */
/*----------------------------------------------------------------------------*/
#ifndef VCS_COMPETITION_CLASS_H
#define VCS_COMPETITION_CLASS_H
/*-----------------------------------------------------------------------------*/
/** @file vex_competition.h
* @brief V5 competition control class header
*//*---------------------------------------------------------------------------*/
namespace vex {
/**
* @prog_lang{block|cpp|pro}
* @brief Use this class to set up your program for competitions.
*/
class competition {
private:
int32_t _index;
static void (* _initialize_callback)(void);
static void (* _autonomous_callback)(void);
static void (* _drivercontrol_callback)(void);
static void _disable( void );
static void _autonomous( void );
static void _drivercontrol( void );
protected:
int32_t _getIndex();
public:
/**
* @prog_lang{pro}
* @drawer_cat{constructor}
* @block_sig{vex::competition Competition = vex::competition();}
* @brief Creates a competition object that has access to competition methods.
*/
competition();
~competition();
enum class tEventType {
EVENT_INITIALIZE = 8,
EVENT_AUTONOMOUS = 9,
EVENT_DRIVER_CTL = 10,
EVENT_DISABLE = 11
};
// callbacks for C++ code
// pre-auton makes no sense here
/**
* @prog_lang{cpp|pro}
* @drawer_cat{setting}
* @block_sig{Competition.autonomous(autonFunction);}
* @brief Calls back a function when the autonomous period starts.
* @param callback A reference to a function.
*/
void autonomous( void (* callback)(void) );
/**
* @prog_lang{cpp|pro}
* @drawer_cat{setting}
* @block_sig{Competition.drivercontrol(driverFunction);}
* @brief Calls back a function when the driver control period starts.
* @param callback A reference to a function.
*/
void drivercontrol( void (* callback)(void) );
// check competition states
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Competition.isEnabled()}
* @brief Gets the status of your robot when under competition control.
* @return Returns a Boolean based on if the autonomous or driver control periods is active. If either one is active, the Boolean will return true.
*/
bool isEnabled();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Competition.isDriverControl()}
* @brief Gets the status of the Driver Control period.
* @return Returns a Boolean based on if the Driver Control Period is active. If the Driver Control period is active, the Boolean will return true.
*/
bool isDriverControl();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Competition.isAutonomous()}
* @brief Gets the status of the Autonomous period.
* @return Returns a Boolean based on if the Autonomous Period is active. If the Autonomous Period is active, the Boolean will return true.
*/
bool isAutonomous();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Competition.isCompetitionSwitch()}
* @brief Gets the status of the Competition Control Switch being plugged into the robot.
* @return Returns a Boolean based on if the V5 is connected to the Competition Control Switch. If the Brain is connected, the Boolean will return true.
*/
bool isCompetitionSwitch();
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{sensing}
* @block_sig{Competition.isFieldControl()}
* @brief Gets the status of the Field Control System being plugged into the robot.
* @return Returns a Boolean based on if the V5 is connected to the Field Control System. If the Brain is connected, the Boolean will return true.
*/
bool isFieldControl();
// may be useful for testing without controller
void test_auton(void);
void test_driver(void);
void test_disable(void);
// competition is part of brain device
// simple events for everything
mevent PRE_AUTONOMOUS = {(uint32_t)brain::_getIndex(), (int32_t)tEventType::EVENT_INITIALIZE };
mevent AUTONOMOUS = {(uint32_t)brain::_getIndex(), (int32_t)tEventType::EVENT_AUTONOMOUS };
mevent DRIVER_CONTROL = {(uint32_t)brain::_getIndex(), (int32_t)tEventType::EVENT_DRIVER_CTL };
mevent DISABLED = {(uint32_t)brain::_getIndex(), (int32_t)tEventType::EVENT_DISABLE };
/**
* @prog_lang{block|cpp|pro}
* @drawer_cat{none}
* @brief Sets whether or not your program will stop tasks between modes.
* @return Gets whether or not your program will stop tasks between modes.
*/
static bool bStopTasksBetweenModes;
};
};
#endif // VCS_COMPETITION_CLASS_H