blob: f1d08046e5b3cd62765777dc8b96be91573a3db4 [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>
13#include <string>
14#include <thread>
15
16#include "HAL/DriverStation.h"
17#include "frc971/wpilib/ahal/SensorBase.h"
18#include "llvm/StringRef.h"
19
20namespace frc {
21
22/**
23 * Provide access to the network communication data to / from the Driver
24 * Station.
25 */
26class DriverStation {
27 public:
28 enum Alliance { kRed, kBlue, kInvalid };
29
30 virtual ~DriverStation();
31 static DriverStation &GetInstance();
32 static void ReportError(llvm::StringRef error);
33 static void ReportWarning(llvm::StringRef error);
34 static void ReportError(bool is_error, int code, llvm::StringRef error,
35 llvm::StringRef location, llvm::StringRef stack);
36
37 static const int kJoystickPorts = 6;
38
39 double GetStickAxis(int stick, int axis);
40 int GetStickPOV(int stick, int pov);
41 int GetStickButtons(int stick) const;
42 bool GetStickButton(int stick, int button);
43
44 int GetStickAxisCount(int stick) const;
45 int GetStickPOVCount(int stick) const;
46 int GetStickButtonCount(int stick) const;
47
48 bool GetJoystickIsXbox(int stick) const;
49 int GetJoystickType(int stick) const;
50 std::string GetJoystickName(int stick) const;
51 int GetJoystickAxisType(int stick, int axis) const;
52
53 bool IsEnabled() const { return is_enabled_; }
54 bool IsTestMode() const { return is_test_mode_; }
55 bool IsFmsAttached() const { return is_fms_attached_; }
56 bool IsAutonomous() const { return is_autonomous_; }
57
58 bool IsSysActive() const;
59 bool IsBrownedOut() const;
60
61 Alliance GetAlliance() const;
62 int GetLocation() const;
63 double GetMatchTime() const;
64 double GetBatteryVoltage() const;
65
66 void RunIteration(std::function<void()> on_data);
67
68 protected:
69 void GetData();
70
71 private:
72 DriverStation();
73
74 // Joystick User Data
75 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
76 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
77 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtons;
78 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptor;
79
80 // Joystick Cached Data
81 std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxesCache;
82 std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVsCache;
83 std::unique_ptr<HAL_JoystickButtons[]> m_joystickButtonsCache;
84 std::unique_ptr<HAL_JoystickDescriptor[]> m_joystickDescriptorCache;
85
86 bool is_enabled_ = false;
87 bool is_test_mode_ = false;
88 bool is_autonomous_ = false;
89 bool is_fms_attached_ = false;
90};
91
92} // namespace frc