WPILibC++  2018.4.1-20180730003225-1150-g0a0d924
 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  virtual double GetX(JoystickHand hand = kRightHand) const = 0;
53  virtual double GetY(JoystickHand hand = kRightHand) const = 0;
54 
65  bool GetRawButton(int button) const;
66 
74  bool GetRawButtonPressed(int button);
75 
83  bool GetRawButtonReleased(int button);
84 
91  double GetRawAxis(int axis) const;
92 
102  int GetPOV(int pov = 0) const;
103 
109  int GetAxisCount() const;
110 
116  int GetPOVCount() const;
117 
123  int GetButtonCount() const;
124 
130  GenericHID::HIDType GetType() const;
131 
137  std::string GetName() const;
138 
144  int GetAxisType(int axis) const;
145 
151  int GetPort() const;
152 
159  void SetOutput(int outputNumber, bool value);
160 
166  void SetOutputs(int value);
167 
176  void SetRumble(RumbleType type, double value);
177 
178  private:
179  DriverStation& m_ds;
180  int m_port;
181  int m_outputs = 0;
182  uint16_t m_leftRumble = 0;
183  uint16_t m_rightRumble = 0;
184 };
185 
186 } // 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.