WPILibC++  unspecified
GenericHID.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 "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 
55  bool GetRawButton(int button) const;
56  bool GetRawButtonPressed(int button);
57  bool GetRawButtonReleased(int button);
58 
59  double GetRawAxis(int axis) const;
60  int GetPOV(int pov = 0) const;
61 
62  int GetAxisCount() const;
63  int GetPOVCount() const;
64  int GetButtonCount() const;
65 
66  GenericHID::HIDType GetType() const;
67  std::string GetName() const;
68  int GetAxisType(int axis) const;
69 
70  int GetPort() const;
71 
72  void SetOutput(int outputNumber, bool value);
73  void SetOutputs(int value);
74  void SetRumble(RumbleType type, double value);
75 
76  private:
77  DriverStation& m_ds;
78  int m_port;
79  int m_outputs = 0;
80  uint16_t m_leftRumble = 0;
81  uint16_t m_rightRumble = 0;
82 };
83 
84 } // namespace frc
Definition: Timer.cpp:18
int GetButtonCount() const
Get the number of buttons for the HID.
Definition: GenericHID.cpp:100
int GetPort() const
Get the port number of the HID.
Definition: GenericHID.cpp:134
int GetAxisType(int axis) const
Get the axis type of a joystick axis.
Definition: GenericHID.cpp:125
std::string GetName() const
Get the name of the HID.
Definition: GenericHID.cpp:118
int GetPOV(int pov=0) const
Get the angle in degrees of a POV on the HID.
Definition: GenericHID.cpp:79
bool GetRawButtonReleased(int button)
Whether the button was released since the last check.
Definition: GenericHID.cpp:56
Provide access to the network communication data to / from the Driver Station.
Definition: DriverStation.h:29
void SetOutput(int outputNumber, bool value)
Set a single HID output value for the HID.
Definition: GenericHID.cpp:143
int GetPOVCount() const
Get the number of POVs for the HID.
Definition: GenericHID.cpp:93
double GetRawAxis(int axis) const
Get the value of the axis.
Definition: GenericHID.cpp:66
bool GetRawButton(int button) const
Get the button value (starting at button 1).
Definition: GenericHID.cpp:34
Base class for most objects.
Definition: ErrorBase.h:74
bool GetRawButtonPressed(int button)
Whether the button was pressed since the last check.
Definition: GenericHID.cpp:45
void SetOutputs(int value)
Set all output values for the HID.
Definition: GenericHID.cpp:155
GenericHID Interface.
Definition: GenericHID.h:23
GenericHID::HIDType GetType() const
Get the type of the HID.
Definition: GenericHID.cpp:109
int GetAxisCount() const
Get the number of axes for the HID.
Definition: GenericHID.cpp:86
void SetRumble(RumbleType type, double value)
Set the rumble output for the HID.
Definition: GenericHID.cpp:168