Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 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 Schuh | 9950f68 | 2021-11-06 15:27:58 -0700 | [diff] [blame^] | 13 | #include <functional> |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 14 | #include <string> |
Austin Schuh | 9950f68 | 2021-11-06 15:27:58 -0700 | [diff] [blame^] | 15 | #include <string_view> |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 16 | #include <thread> |
| 17 | |
Austin Schuh | f6b9463 | 2019-02-02 22:11:27 -0800 | [diff] [blame] | 18 | #include "hal/DriverStation.h" |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 19 | #include "frc971/wpilib/ahal/SensorBase.h" |
Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 20 | |
| 21 | namespace frc { |
| 22 | |
| 23 | /** |
| 24 | * Provide access to the network communication data to / from the Driver |
| 25 | * Station. |
| 26 | */ |
| 27 | class DriverStation { |
| 28 | public: |
| 29 | enum Alliance { kRed, kBlue, kInvalid }; |
| 30 | |
| 31 | virtual ~DriverStation(); |
| 32 | static DriverStation &GetInstance(); |
Austin Schuh | 9950f68 | 2021-11-06 15:27:58 -0700 | [diff] [blame^] | 33 | 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 Schuh | d3b7a887 | 2018-02-19 16:42:27 -0800 | [diff] [blame] | 37 | |
| 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 |