mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpilib] Add function to wait for DS Connection (#5230)
This commit is contained in:
@@ -1145,6 +1145,33 @@ public final class DriverStation {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a DS connection.
|
||||
*
|
||||
* @param timeoutSeconds timeout in seconds. 0 for infinite.
|
||||
* @return true if connected, false if timeout
|
||||
*/
|
||||
public static boolean waitForDsConnection(double timeoutSeconds) {
|
||||
int event = WPIUtilJNI.createEvent(true, false);
|
||||
DriverStationJNI.provideNewDataEventHandle(event);
|
||||
boolean result;
|
||||
try {
|
||||
if (timeoutSeconds == 0) {
|
||||
WPIUtilJNI.waitForObject(event);
|
||||
result = true;
|
||||
} else {
|
||||
result = !WPIUtilJNI.waitForObjectTimeout(event, timeoutSeconds);
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
result = false;
|
||||
} finally {
|
||||
DriverStationJNI.removeNewDataEventHandle(event);
|
||||
WPIUtilJNI.destroyEvent(event);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the approximate match time. The FMS does not send an official match time to the robots,
|
||||
* but does send an approximate match time. The value will count down the time remaining in the
|
||||
|
||||
Reference in New Issue
Block a user