001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package org.wpilib.driverstation;
006
007import java.util.Optional;
008import java.util.OptionalInt;
009import org.wpilib.driverstation.internal.DriverStationBackend;
010
011/** Provides access to match state information from the Driver Station. */
012public final class MatchState {
013  private MatchState() {}
014
015  /**
016   * Return the approximate match time. The FMS does not send an official match time to the robots,
017   * but does send an approximate match time. The value will count down the time remaining in the
018   * current period (auto or teleop). Warning: This is not an official time (so it cannot be used to
019   * dispute ref calls or guarantee that a function will trigger before the match ends).
020   *
021   * <p>When connected to the real field, this number only changes in full integer increments, and
022   * always counts down.
023   *
024   * <p>When the DS is in practice mode, this number is a floating point number, and counts down.
025   *
026   * <p>When the DS is in teleop or autonomous mode, this number returns -1.0.
027   *
028   * <p>Simulation matches DS behavior without an FMS connected.
029   *
030   * @return Time remaining in current match period (auto or teleop) in seconds
031   */
032  public static double getMatchTime() {
033    return DriverStationBackend.getMatchTime();
034  }
035
036  /**
037   * Get the current alliance from the FMS.
038   *
039   * <p>If the FMS is not connected, it is set from the team alliance setting on the driver station.
040   *
041   * @return The alliance (red or blue) or an empty optional if the alliance is invalid
042   */
043  public static Optional<Alliance> getAlliance() {
044    return DriverStationBackend.getAlliance();
045  }
046
047  /**
048   * Gets the location of the team's driver station controls from the FMS.
049   *
050   * <p>If the FMS is not connected, it is set from the team alliance setting on the driver station.
051   *
052   * @return the location of the team's driver station controls: 1, 2, or 3
053   */
054  public static OptionalInt getLocation() {
055    return DriverStationBackend.getLocation();
056  }
057
058  /**
059   * Get the replay number from the FMS.
060   *
061   * @return the replay number
062   */
063  public static int getReplayNumber() {
064    return DriverStationBackend.getReplayNumber();
065  }
066
067  /**
068   * Get the match number from the FMS.
069   *
070   * @return the match number
071   */
072  public static int getMatchNumber() {
073    return DriverStationBackend.getMatchNumber();
074  }
075
076  /**
077   * Get the match type from the FMS.
078   *
079   * @return the match type
080   */
081  public static MatchType getMatchType() {
082    return DriverStationBackend.getMatchType();
083  }
084
085  /**
086   * Get the event name from the FMS.
087   *
088   * @return the event name
089   */
090  public static String getEventName() {
091    return DriverStationBackend.getEventName();
092  }
093
094  /**
095   * Get the game specific message from the FMS.
096   *
097   * <p>If the FMS is not connected, it is set from the game data setting on the driver station.
098   *
099   * @return the game specific message
100   */
101  public static Optional<String> getGameData() {
102    return DriverStationBackend.getGameData();
103  }
104}