WPILibC++  unspecified
Joystick.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 <array>
11 
12 #include <support/deprecated.h>
13 
14 #include "GenericHID.h"
15 
16 namespace frc {
17 
26 class Joystick : public GenericHID {
27  public:
28  static constexpr int kDefaultXAxis = 0;
29  static constexpr int kDefaultYAxis = 1;
30  static constexpr int kDefaultZAxis = 2;
31  static constexpr int kDefaultTwistAxis = 2;
32  static constexpr int kDefaultThrottleAxis = 3;
33 
34  enum AxisType { kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis };
35  enum ButtonType { kTriggerButton, kTopButton };
36 
37  explicit Joystick(int port);
38  virtual ~Joystick() = default;
39 
40  Joystick(const Joystick&) = delete;
41  Joystick& operator=(const Joystick&) = delete;
42 
43  void SetXChannel(int channel);
44  void SetYChannel(int channel);
45  void SetZChannel(int channel);
46  void SetTwistChannel(int channel);
47  void SetThrottleChannel(int channel);
48 
49  WPI_DEPRECATED("Use the more specific axis channel setter functions.")
50  void SetAxisChannel(AxisType axis, int channel);
51 
52  int GetXChannel() const;
53  int GetYChannel() const;
54  int GetZChannel() const;
55  int GetTwistChannel() const;
56  int GetThrottleChannel() const;
57 
58  WPI_DEPRECATED("Use the more specific axis channel getter functions.")
59  int GetAxisChannel(AxisType axis) const;
60 
61  double GetX(JoystickHand hand = kRightHand) const override;
62  double GetY(JoystickHand hand = kRightHand) const override;
63  double GetZ() const;
64  double GetTwist() const;
65  double GetThrottle() const;
66 
67  WPI_DEPRECATED("Use the more specific axis channel getter functions.")
68  double GetAxis(AxisType axis) const;
69 
70  bool GetTrigger() const;
71  bool GetTriggerPressed();
72  bool GetTriggerReleased();
73 
74  bool GetTop() const;
75  bool GetTopPressed();
76  bool GetTopReleased();
77 
78  WPI_DEPRECATED("Use Joystick instances instead.")
79  static Joystick* GetStickForPort(int port);
80 
81  WPI_DEPRECATED("Use the more specific button getter functions.")
82  bool GetButton(ButtonType button) const;
83 
84  double GetMagnitude() const;
85  double GetDirectionRadians() const;
86  double GetDirectionDegrees() const;
87 
88  private:
89  enum Axis { kX, kY, kZ, kTwist, kThrottle, kNumAxes };
90  enum Button { kTrigger = 1, kTop = 2 };
91 
92  std::array<int, Axis::kNumAxes> m_axes;
93 };
94 
95 } // namespace frc
Definition: RobotController.cpp:14
double GetAxis(AxisType axis) const
For the current joystick, return the axis determined by the argument.
Definition: Joystick.cpp:182
double GetDirectionRadians() const
Get the direction of the vector formed by the joystick and its origin in radians. ...
Definition: Joystick.cpp:290
double GetX(JoystickHand hand=kRightHand) const override
Get the X value of the joystick.
Definition: Joystick.cpp:133
int GetTwistChannel() const
Get the channel currently associated with the twist axis.
Definition: Joystick.cpp:116
void SetTwistChannel(int channel)
Set the channel associated with the twist axis.
Definition: Joystick.cpp:78
int GetZChannel() const
Get the channel currently associated with the Z axis.
Definition: Joystick.cpp:109
int GetXChannel() const
Get the channel currently associated with the X axis.
Definition: Joystick.cpp:95
Joystick(int port)
Construct an instance of a joystick.
Definition: Joystick.cpp:29
bool GetTopReleased()
Whether the top button was released since the last check.
Definition: Joystick.cpp:248
void SetAxisChannel(AxisType axis, int channel)
Set the channel associated with a specified axis.
Definition: Joystick.cpp:45
int GetYChannel() const
Get the channel currently associated with the Y axis.
Definition: Joystick.cpp:102
void SetYChannel(int channel)
Set the channel associated with the Y axis.
Definition: Joystick.cpp:62
double GetTwist() const
Get the twist value of the current joystick.
Definition: Joystick.cpp:161
void SetXChannel(int channel)
Set the channel associated with the X axis.
Definition: Joystick.cpp:54
bool GetTopPressed()
Whether the top button was pressed since the last check.
Definition: Joystick.cpp:241
double GetThrottle() const
Get the throttle value of the current joystick.
Definition: Joystick.cpp:168
double GetDirectionDegrees() const
Get the direction of the vector formed by the joystick and its origin in degrees. ...
Definition: Joystick.cpp:300
double GetMagnitude() const
Get the magnitude of the direction vector formed by the joystick&#39;s current position relative to its o...
Definition: Joystick.cpp:280
Handle input from standard Joysticks connected to the Driver Station.
Definition: Joystick.h:26
int GetThrottleChannel() const
Get the channel currently associated with the throttle axis.
Definition: Joystick.cpp:123
void SetThrottleChannel(int channel)
Set the channel associated with the throttle axis.
Definition: Joystick.cpp:86
double GetY(JoystickHand hand=kRightHand) const override
Get the Y value of the joystick.
Definition: Joystick.cpp:145
bool GetTriggerReleased()
Whether the trigger was released since the last check.
Definition: Joystick.cpp:223
GenericHID Interface.
Definition: GenericHID.h:23
bool GetTop() const
Read the state of the top button on the joystick.
Definition: Joystick.cpp:234
bool GetTrigger() const
Read the state of the trigger on the joystick.
Definition: Joystick.cpp:207
bool GetButton(ButtonType button) const
Get buttons based on an enumerated type.
Definition: Joystick.cpp:269
bool GetTriggerPressed()
Whether the trigger was pressed since the last check.
Definition: Joystick.cpp:214
void SetZChannel(int channel)
Set the channel associated with the Z axis.
Definition: Joystick.cpp:70
double GetZ() const
Get the Z value of the current joystick.
Definition: Joystick.cpp:154