WPILibC++  2019.1.1-beta-1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
GenericHID.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 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 
68  bool GetRawButton(int button) const;
69 
77  bool GetRawButtonPressed(int button);
78 
86  bool GetRawButtonReleased(int button);
87 
94  double GetRawAxis(int axis) const;
95 
105  int GetPOV(int pov = 0) const;
106 
112  int GetAxisCount() const;
113 
119  int GetPOVCount() const;
120 
126  int GetButtonCount() const;
127 
133  GenericHID::HIDType GetType() const;
134 
140  std::string GetName() const;
141 
147  int GetAxisType(int axis) const;
148 
154  int GetPort() const;
155 
162  void SetOutput(int outputNumber, bool value);
163 
169  void SetOutputs(int value);
170 
179  void SetRumble(RumbleType type, double value);
180 
181  private:
182  DriverStation& m_ds;
183  int m_port;
184  int m_outputs = 0;
185  uint16_t m_leftRumble = 0;
186  uint16_t m_rightRumble = 0;
187 };
188 
189 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
bool GetRawButtonReleased(int button)
Whether the button was released since the last check.
bool GetRawButton(int button) const
Get the button value (starting at button 1).
int GetAxisCount() const
Get the number of axes for the HID.
int GetAxisType(int axis) const
Get the axis type of a joystick axis.
bool GetRawButtonPressed(int button)
Whether the button was pressed since the last check.
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:33
int GetButtonCount() const
Get the number of buttons for the HID.
void SetRumble(RumbleType type, double value)
Set the rumble output for the HID.
GenericHID::HIDType GetType() const
Get the type of the HID.
void SetOutput(int outputNumber, bool value)
Set a single HID output value for the HID.
int GetPOVCount() const
Get the number of POVs for the HID.
double GetRawAxis(int axis) const
Get the value of the axis.
Base class for most objects.
Definition: ErrorBase.h:74
std::string GetName() const
Get the name of the HID.
GenericHID Interface.
Definition: GenericHID.h:23
int GetPort() const
Get the port number of the HID.
void SetOutputs(int value)
Set all output values for the HID.
int GetPOV(int pov=0) const
Get the angle in degrees of a POV on the HID.