blob: 51503607025f9ab74c0e21ae21c2f0af44c12eeb [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 };
30
31 virtual ~DriverStation();
32 static DriverStation &GetInstance();
Austin Schuh9950f682021-11-06 15:27:58 -070033 static void ReportError(const std::string_view &error);
34 static void ReportWarning(const std::string_view &error);
35 static void ReportError(bool is_error, int code, const std::string_view &error,
36 const std::string_view &location, const std::string_view &stack);
Parker Schuhd3b7a8872018-02-19 16:42:27 -080037
38 static const int kJoystickPorts = 6;
39
40 double GetStickAxis(int stick, int axis);
41 int GetStickPOV(int stick, int pov);
42 int GetStickButtons(int stick) const;
43 bool GetStickButton(int stick, int button);
44
45 int GetStickAxisCount(int stick) const;
46 int GetStickPOVCount(int stick) const;
47 int GetStickButtonCount(int stick) const;
48
49 bool GetJoystickIsXbox(int stick) const;
50 int GetJoystickType(int stick) const;
51 std::string GetJoystickName(int stick) const;
52 int GetJoystickAxisType(int stick, int axis) const;
53
54 bool IsEnabled() const { return is_enabled_; }
55 bool IsTestMode() const { return is_test_mode_; }
56 bool IsFmsAttached() const { return is_fms_attached_; }
57 bool IsAutonomous() const { return is_autonomous_; }
58
59 bool IsSysActive() const;
60 bool IsBrownedOut() const;
61
62 Alliance GetAlliance() const;
63 int GetLocation() const;
64 double GetMatchTime() const;
65 double GetBatteryVoltage() const;
66
67 void RunIteration(std::function<void()> on_data);
68
69 protected:
70 void GetData();
71
72 private:
73 DriverStation();
74
75 // Joystick User Data
76 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
77 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
78 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
79 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
80
81 // Joystick Cached Data
82 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxesCache;
83 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVsCache;
84 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtonsCache;
85 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptorCache;
86
87 bool is_enabled_ = false;
88 bool is_test_mode_ = false;
89 bool is_autonomous_ = false;
90 bool is_fms_attached_ = false;
91};
92
93} // namespace frc