blob: 8bcdcf1d6172766f02969fc76890ca0070c994a9 [file] [log] [blame]
Parker Schuhd3b7a8872018-02-19 16:42:27 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#pragma once
9
10#include <atomic>
11// #include <condition_variable>
12#include <memory>
Austin Schuh9950f682021-11-06 15:27:58 -070013#include <functional>
Parker Schuhd3b7a8872018-02-19 16:42:27 -080014#include <string>
Austin Schuh9950f682021-11-06 15:27:58 -070015#include <string_view>
Parker Schuhd3b7a8872018-02-19 16:42:27 -080016#include <thread>
17
Austin Schuhf6b94632019-02-02 22:11:27 -080018#include "hal/DriverStation.h"
Parker Schuhd3b7a8872018-02-19 16:42:27 -080019#include "frc971/wpilib/ahal/SensorBase.h"
Parker Schuhd3b7a8872018-02-19 16:42:27 -080020
21namespace frc {
22
23/**
24 * Provide access to the network communication data to / from the Driver
25 * Station.
26 */
27class DriverStation {
28 public:
29 enum Alliance { kRed, kBlue, kInvalid };
Lee Mracekdb8bde02022-01-08 02:54:21 -050030 enum MatchType { kNone, kPractice, kQualification, kElimination };
Parker Schuhd3b7a8872018-02-19 16:42:27 -080031
32 virtual ~DriverStation();
33 static DriverStation &GetInstance();
Austin Schuh9950f682021-11-06 15:27:58 -070034 static void ReportError(const std::string_view &error);
35 static void ReportWarning(const std::string_view &error);
36 static void ReportError(bool is_error, int code, const std::string_view &error,
37 const std::string_view &location, const std::string_view &stack);
Parker Schuhd3b7a8872018-02-19 16:42:27 -080038
39 static const int kJoystickPorts = 6;
40
41 double GetStickAxis(int stick, int axis);
42 int GetStickPOV(int stick, int pov);
43 int GetStickButtons(int stick) const;
44 bool GetStickButton(int stick, int button);
45
46 int GetStickAxisCount(int stick) const;
47 int GetStickPOVCount(int stick) const;
48 int GetStickButtonCount(int stick) const;
49
50 bool GetJoystickIsXbox(int stick) const;
51 int GetJoystickType(int stick) const;
52 std::string GetJoystickName(int stick) const;
53 int GetJoystickAxisType(int stick, int axis) const;
54
55 bool IsEnabled() const { return is_enabled_; }
56 bool IsTestMode() const { return is_test_mode_; }
57 bool IsFmsAttached() const { return is_fms_attached_; }
58 bool IsAutonomous() const { return is_autonomous_; }
Lee Mracekdb8bde02022-01-08 02:54:21 -050059 bool IsTeleop() const { return is_teleop_; }
60 bool IsDSAttached() const { return is_ds_attached_; }
Parker Schuhd3b7a8872018-02-19 16:42:27 -080061
62 bool IsSysActive() const;
63 bool IsBrownedOut() const;
64
Lee Mracekdb8bde02022-01-08 02:54:21 -050065 std::string_view GetGameSpecificMessage() const;
66
67 std::string_view GetEventName() const;
68 MatchType GetMatchType() const;
69 int GetMatchNumber() const;
70 int GetReplayNumber() const;
Parker Schuhd3b7a8872018-02-19 16:42:27 -080071 Alliance GetAlliance() const;
72 int GetLocation() const;
73 double GetMatchTime() const;
74 double GetBatteryVoltage() const;
75
76 void RunIteration(std::function<void()> on_data);
77
78 protected:
79 void GetData();
80
81 private:
82 DriverStation();
83
84 // Joystick User Data
85 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
86 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
87 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
88 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
89
90 // Joystick Cached Data
91 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxesCache;
92 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVsCache;
93 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtonsCache;
94 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptorCache;
95
96 bool is_enabled_ = false;
97 bool is_test_mode_ = false;
98 bool is_autonomous_ = false;
99 bool is_fms_attached_ = false;
Lee Mracekdb8bde02022-01-08 02:54:21 -0500100 bool is_teleop_ = false;
101 bool is_ds_attached_ = false;
102
103 // statically allocated match info so we can return string_views into it.
104 HAL_MatchInfo info_;
Parker Schuhd3b7a8872018-02-19 16:42:27 -0800105};
106
107} // namespace frc