Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Field Control State Getter #608

Merged
merged 7 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions include/pros/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@
/// \name V5 Competition
//@{

#define COMPETITION_DISABLED (1 << 0)
/*#define COMPETITION_DISABLED (1 << 0)
#define COMPETITION_AUTONOMOUS (1 << 1)
#define COMPETITION_CONNECTED (1 << 2)
#define COMPETITION_SYSTEM (1 << 3)*/
typedef enum {
COMPETITION_DISABLED = 1 << 0,
COMPETITION_CONNECTED = 1 << 2,
COMPETITION_AUTONOMOUS = 1 << 1,
COMPETITION_SYSTEM = 1 << 3,
} competition_status;

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -91,7 +98,7 @@ uint8_t competition_get_status(void);
* }
* \endcode
*/
#define competition_is_disabled() ((competition_get_status() & COMPETITION_DISABLED) != 0)
uint8_t competition_is_disabled();

/**
* \return True if the V5 Brain is connected to competition control, false otherwise.
Expand All @@ -106,7 +113,7 @@ uint8_t competition_get_status(void);
* }
* \endcode
*/
#define competition_is_connected() ((competition_get_status() & COMPETITION_CONNECTED) != 0)
uint8_t competition_is_connected();

/**
* \return True if the V5 Brain is in autonomous mode, false otherwise.
Expand All @@ -128,7 +135,34 @@ uint8_t competition_get_status(void);
* }
* \endcode
*/
#define competition_is_autonomous() ((competition_get_status() & COMPETITION_AUTONOMOUS) != 0)
uint8_t competition_is_autonomous();

/**
* \return True if the V5 Brain is connected to VEXnet Field Controller, false otherwise.
*
* \b Example
* \code
* void initialize() {
* if (competition_is_field()) {
* // connected to VEXnet Field Controller
* }
* }
* \endcode
*/
uint8_t competition_is_field();

/**
* \return True if the V5 Brain is connected to VEXnet Competition Switch, false otherwise.
*
* \b Example
* \code
* void initialize() {
* if (competition_is_switch()) {
* // connected to VEXnet Competition Switch
* }
* }
*/
uint8_t competition_is_switch();

///@}

Expand Down
2 changes: 2 additions & 0 deletions include/pros/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ std::uint8_t get_status(void);
std::uint8_t is_autonomous(void);
std::uint8_t is_connected(void);
std::uint8_t is_disabled(void);
std::uint8_t is_field_control(void);
std::uint8_t is_competition_switch(void);
} // namespace competition

namespace usd {
Expand Down
20 changes: 20 additions & 0 deletions src/devices/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,23 @@ int32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern) {
uint8_t competition_get_status(void) {
return vexCompetitionStatus();
}

uint8_t competition_is_disabled() {
return (competition_get_status() & COMPETITION_DISABLED) != 0;
}

uint8_t competition_is_connected() {
return (competition_get_status() & COMPETITION_CONNECTED) != 0;
}

uint8_t competition_is_autonomous() {
return (competition_get_status() & COMPETITION_AUTONOMOUS) != 0;
}

uint8_t competition_is_field() {
return (competition_get_status() & COMPETITION_SYSTEM) != 0;
}

uint8_t competition_is_switch() {
return (competition_get_status() & COMPETITION_SYSTEM) == 0;
}
9 changes: 9 additions & 0 deletions src/devices/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,14 @@ std::uint8_t is_connected(void) {
std::uint8_t is_disabled(void) {
return competition_is_disabled();
}

std::uint8_t is_field_control(void) {
return competition_is_field();
}

std::uint8_t is_competition_switch(void) {
return competition_is_switch();
}

} // namespace competition
} // namespace pros
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void competition_initialize() {}
* will be stopped. Re-enabling the robot will restart the task, not re-start it
* from where it left off.
*/
void autonomous() {}
void autonomous() {
}

/**
* Runs the operator control code. This function will be started in its own task
Expand All @@ -79,8 +80,10 @@ void opcontrol() {
pros::MotorGroup right_mg({-4,5,-6}); // Creates a motor group with forwards port 4 and reversed ports 4 & 6

while (true) {

pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,
(pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1,

(pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0); // Prints status of the emulated screen LCDs

// Arcade control scheme
Expand Down