[wpilib] Add methods to check game and enabled state together (#2661)

This avoids users having to call both IsOperatorControl() and IsEnabled() to figure out if their robot is
enabled and in the teleop state. The expression above involves calling two methods that each have their
own lock.

These new methods should only involve locking one mutex, since only one call is made to HAL_GetControlWord().
This commit is contained in:
Prateek Machiraju
2020-08-29 16:32:19 -04:00
committed by GitHub
parent 5d1220e629
commit 526f26685d
8 changed files with 106 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -55,7 +55,7 @@ public class Robot extends RobotBase {
m_ds.InAutonomous(true);
autonomous();
m_ds.InAutonomous(false);
while (isAutonomous() && !isDisabled()) {
while (isAutonomousEnabled()) {
m_ds.waitForData();
}
} else if (isTest()) {
@@ -73,7 +73,7 @@ public class Robot extends RobotBase {
m_ds.InOperatorControl(true);
teleop();
m_ds.InOperatorControl(false);
while (isOperatorControl() && !isDisabled()) {
while (isOperatorControlEnabled()) {
m_ds.waitForData();
}
}