WPILibC++  2020.3.2-60-g3011ebe
GenericHID.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2020 FIRST. 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 <stdint.h>
11 
12 #include <string>
13 
14 #include "frc/ErrorBase.h"
15 
16 namespace frc {
17 
18 class DriverStation;
19 
23 class GenericHID : public ErrorBase {
24  public:
25  enum RumbleType { kLeftRumble, kRightRumble };
26 
27  enum HIDType {
28  kUnknown = -1,
29  kXInputUnknown = 0,
30  kXInputGamepad = 1,
31  kXInputWheel = 2,
32  kXInputArcadeStick = 3,
33  kXInputFlightStick = 4,
34  kXInputDancePad = 5,
35  kXInputGuitar = 6,
36  kXInputGuitar2 = 7,
37  kXInputDrumKit = 8,
38  kXInputGuitar3 = 11,
39  kXInputArcadePad = 19,
40  kHIDJoystick = 20,
41  kHIDGamepad = 21,
42  kHIDDriving = 22,
43  kHIDFlight = 23,
44  kHID1stPerson = 24
45  };
46 
47  enum JoystickHand { kLeftHand = 0, kRightHand = 1 };
48 
49  explicit GenericHID(int port);
50  virtual ~GenericHID() = default;
51 
52  GenericHID(GenericHID&&) = default;
53  GenericHID& operator=(GenericHID&&) = default;
54 
55  virtual double GetX(JoystickHand hand = kRightHand) const = 0;
56  virtual double GetY(JoystickHand hand = kRightHand) const = 0;
57 
71  bool GetRawButton(int button) const;
72 
84  bool GetRawButtonPressed(int button);
85 
97  bool GetRawButtonReleased(int button);
98 
105  double GetRawAxis(int axis) const;
106 
116  int GetPOV(int pov = 0) const;
117 
123  int GetAxisCount() const;
124 
130  int GetPOVCount() const;
131 
137  int GetButtonCount() const;
138 
144  GenericHID::HIDType GetType() const;
145 
151  std::string GetName() const;
152 
158  int GetAxisType(int axis) const;
159 
165  int GetPort() const;
166 
173  void SetOutput(int outputNumber, bool value);
174 
180  void SetOutputs(int value);
181 
190  void SetRumble(RumbleType type, double value);
191 
192  private:
193  DriverStation* m_ds;
194  int m_port;
195  int m_outputs = 0;
196  uint16_t m_leftRumble = 0;
197  uint16_t m_rightRumble = 0;
198 };
199 
200 } // namespace frc
frc::GenericHID::GetRawButton
bool GetRawButton(int button) const
Get the button value (starting at button 1).
frc::GenericHID::GetType
GenericHID::HIDType GetType() const
Get the type of the HID.
frc::GenericHID::GetAxisType
int GetAxisType(int axis) const
Get the axis type of a joystick axis.
frc::GenericHID::GetRawButtonPressed
bool GetRawButtonPressed(int button)
Whether the button was pressed since the last check.
frc::GenericHID::GetButtonCount
int GetButtonCount() const
Get the number of buttons for the HID.
frc::GenericHID::GetPort
int GetPort() const
Get the port number of the HID.
frc::GenericHID::SetOutput
void SetOutput(int outputNumber, bool value)
Set a single HID output value for the HID.
frc::GenericHID::GetName
std::string GetName() const
Get the name of the HID.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::GenericHID::SetRumble
void SetRumble(RumbleType type, double value)
Set the rumble output for the HID.
frc::GenericHID::GetAxisCount
int GetAxisCount() const
Get the number of axes for the HID.
frc::GenericHID::GetRawAxis
double GetRawAxis(int axis) const
Get the value of the axis.
frc::GenericHID::GetPOV
int GetPOV(int pov=0) const
Get the angle in degrees of a POV on the HID.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::GenericHID::GetPOVCount
int GetPOVCount() const
Get the number of POVs for the HID.
frc::DriverStation
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:33
frc::GenericHID::SetOutputs
void SetOutputs(int value)
Set all output values for the HID.
frc::GenericHID
GenericHID Interface.
Definition: GenericHID.h:23
frc::GenericHID::GetRawButtonReleased
bool GetRawButtonReleased(int button)
Whether the button was released since the last check.