blob: cd520f8946034b212f720170de01a299e07aae0d [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>
Austin Schuh9950f682021-11-06 15:27:58 -070012#include <functional>
Philipp Schrader790cb542023-07-05 21:06:52 -070013#include <memory>
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
Parker Schuhd3b7a8872018-02-19 16:42:27 -080018#include "frc971/wpilib/ahal/SensorBase.h"
Philipp Schrader790cb542023-07-05 21:06:52 -070019#include "hal/DriverStation.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);
Philipp Schrader790cb542023-07-05 21:06:52 -070036 static void ReportError(bool is_error, int code,
37 const std::string_view &error,
38 const std::string_view &location,
39 const std::string_view &stack);
Parker Schuhd3b7a8872018-02-19 16:42:27 -080040
41 static const int kJoystickPorts = 6;
42
43 double GetStickAxis(int stick, int axis);
44 int GetStickPOV(int stick, int pov);
45 int GetStickButtons(int stick) const;
46 bool GetStickButton(int stick, int button);
47
48 int GetStickAxisCount(int stick) const;
49 int GetStickPOVCount(int stick) const;
50 int GetStickButtonCount(int stick) const;
51
52 bool GetJoystickIsXbox(int stick) const;
53 int GetJoystickType(int stick) const;
54 std::string GetJoystickName(int stick) const;
55 int GetJoystickAxisType(int stick, int axis) const;
56
57 bool IsEnabled() const { return is_enabled_; }
58 bool IsTestMode() const { return is_test_mode_; }
59 bool IsFmsAttached() const { return is_fms_attached_; }
60 bool IsAutonomous() const { return is_autonomous_; }
Lee Mracekdb8bde02022-01-08 02:54:21 -050061 bool IsTeleop() const { return is_teleop_; }
62 bool IsDSAttached() const { return is_ds_attached_; }
Parker Schuhd3b7a8872018-02-19 16:42:27 -080063
64 bool IsSysActive() const;
65 bool IsBrownedOut() const;
66
Lee Mracekdb8bde02022-01-08 02:54:21 -050067 std::string_view GetGameSpecificMessage() const;
68
69 std::string_view GetEventName() const;
70 MatchType GetMatchType() const;
71 int GetMatchNumber() const;
72 int GetReplayNumber() const;
Parker Schuhd3b7a8872018-02-19 16:42:27 -080073 Alliance GetAlliance() const;
74 int GetLocation() const;
75 double GetMatchTime() const;
76 double GetBatteryVoltage() const;
77
78 void RunIteration(std::function<void()> on_data);
79
80 protected:
81 void GetData();
82
83 private:
84 DriverStation();
85
86 // Joystick User Data
87 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
88 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
89 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
90 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
91
92 // Joystick Cached Data
93 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxesCache;
94 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVsCache;
95 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtonsCache;
96 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptorCache;
97
98 bool is_enabled_ = false;
99 bool is_test_mode_ = false;
100 bool is_autonomous_ = false;
101 bool is_fms_attached_ = false;
Lee Mracekdb8bde02022-01-08 02:54:21 -0500102 bool is_teleop_ = false;
103 bool is_ds_attached_ = false;
104
105 // statically allocated match info so we can return string_views into it.
106 HAL_MatchInfo info_;
Parker Schuhd3b7a8872018-02-19 16:42:27 -0800107};
108
109} // namespace frc