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 <wpi/deprecated.h>
13 
14 #include "GenericHID.h"
15 
16 namespace frc {
17 
26 class Joystick : public GenericHID {
27  public:
28  static constexpr int kDefaultXChannel = 0;
29  static constexpr int kDefaultYChannel = 1;
30  static constexpr int kDefaultZChannel = 2;
31  static constexpr int kDefaultTwistChannel = 2;
32  static constexpr int kDefaultThrottleChannel = 3;
33 
34  WPI_DEPRECATED("Use kDefaultXChannel instead.")
35  static constexpr int kDefaultXAxis = 0;
36  WPI_DEPRECATED("Use kDefaultYChannel instead.")
37  static constexpr int kDefaultYAxis = 1;
38  WPI_DEPRECATED("Use kDefaultZChannel instead.")
39  static constexpr int kDefaultZAxis = 2;
40  WPI_DEPRECATED("Use kDefaultTwistChannel instead.")
41  static constexpr int kDefaultTwistAxis = 2;
42  WPI_DEPRECATED("Use kDefaultThrottleChannel instead.")
43  static constexpr int kDefaultThrottleAxis = 3;
44 
45  enum AxisType { kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis };
46  enum ButtonType { kTriggerButton, kTopButton };
47 
56  explicit Joystick(int port);
57 
58  virtual ~Joystick() = default;
59 
60  Joystick(const Joystick&) = delete;
61  Joystick& operator=(const Joystick&) = delete;
62 
68  void SetXChannel(int channel);
69 
76  void SetYChannel(int channel);
77 
84  void SetZChannel(int channel);
85 
92  void SetTwistChannel(int channel);
93 
100  void SetThrottleChannel(int channel);
101 
108  WPI_DEPRECATED("Use the more specific axis channel setter functions.")
109  void SetAxisChannel(AxisType axis, int channel);
110 
116  int GetXChannel() const;
117 
123  int GetYChannel() const;
124 
130  int GetZChannel() const;
131 
137  int GetTwistChannel() const;
138 
144  int GetThrottleChannel() const;
145 
154  double GetX(JoystickHand hand = kRightHand) const override;
155 
164  double GetY(JoystickHand hand = kRightHand) const override;
165 
171  double GetZ() const;
172 
178  double GetTwist() const;
179 
185  double GetThrottle() const;
186 
197  WPI_DEPRECATED("Use the more specific axis channel getter functions.")
198  double GetAxis(AxisType axis) const;
199 
207  bool GetTrigger() const;
208 
214  bool GetTriggerPressed();
215 
221  bool GetTriggerReleased();
222 
230  bool GetTop() const;
231 
237  bool GetTopPressed();
238 
244  bool GetTopReleased();
245 
246  WPI_DEPRECATED("Use Joystick instances instead.")
247  static Joystick* GetStickForPort(int port);
248 
257  WPI_DEPRECATED("Use the more specific button getter functions.")
258  bool GetButton(ButtonType button) const;
259 
266  double GetMagnitude() const;
267 
274  double GetDirectionRadians() const;
275 
282  double GetDirectionDegrees() const;
283 
284  private:
285  enum Axis { kX, kY, kZ, kTwist, kThrottle, kNumAxes };
286  enum Button { kTrigger = 1, kTop = 2 };
287 
288  std::array<int, Axis::kNumAxes> m_axes;
289 };
290 
291 } // namespace frc
Definition: Utility.cpp:119
double GetAxis(AxisType axis) const
For the current joystick, return the axis determined by the argument.
Definition: Joystick.cpp:73
double GetDirectionRadians() const
Get the direction of the vector formed by the joystick and its origin in radians. ...
Definition: Joystick.cpp:127
double GetX(JoystickHand hand=kRightHand) const override
Get the X value of the joystick.
Definition: Joystick.cpp:57
int GetTwistChannel() const
Get the channel currently associated with the twist axis.
Definition: Joystick.cpp:53
void SetTwistChannel(int channel)
Set the channel associated with the twist axis.
Definition: Joystick.cpp:37
int GetZChannel() const
Get the channel currently associated with the Z axis.
Definition: Joystick.cpp:51
int GetXChannel() const
Get the channel currently associated with the X axis.
Definition: Joystick.cpp:47
Joystick(int port)
Construct an instance of a joystick.
Definition: Joystick.cpp:21
bool GetTopReleased()
Whether the top button was released since the last check.
Definition: Joystick.cpp:105
void SetAxisChannel(AxisType axis, int channel)
Set the channel associated with a specified axis.
Definition: Joystick.cpp:43
int GetYChannel() const
Get the channel currently associated with the Y axis.
Definition: Joystick.cpp:49
void SetYChannel(int channel)
Set the channel associated with the Y axis.
Definition: Joystick.cpp:33
double GetTwist() const
Get the twist value of the current joystick.
Definition: Joystick.cpp:67
void SetXChannel(int channel)
Set the channel associated with the X axis.
Definition: Joystick.cpp:31
bool GetTopPressed()
Whether the top button was pressed since the last check.
Definition: Joystick.cpp:103
double GetThrottle() const
Get the throttle value of the current joystick.
Definition: Joystick.cpp:69
double GetDirectionDegrees() const
Get the direction of the vector formed by the joystick and its origin in degrees. ...
Definition: Joystick.cpp:131
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:123
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:55
void SetThrottleChannel(int channel)
Set the channel associated with the throttle axis.
Definition: Joystick.cpp:39
double GetY(JoystickHand hand=kRightHand) const override
Get the Y value of the joystick.
Definition: Joystick.cpp:61
bool GetTriggerReleased()
Whether the trigger was released since the last check.
Definition: Joystick.cpp:97
GenericHID Interface.
Definition: GenericHID.h:23
bool GetTop() const
Read the state of the top button on the joystick.
Definition: Joystick.cpp:101
bool GetTrigger() const
Read the state of the trigger on the joystick.
Definition: Joystick.cpp:91
bool GetButton(ButtonType button) const
Get buttons based on an enumerated type.
Definition: Joystick.cpp:118
bool GetTriggerPressed()
Whether the trigger was pressed since the last check.
Definition: Joystick.cpp:93
void SetZChannel(int channel)
Set the channel associated with the Z axis.
Definition: Joystick.cpp:35
double GetZ() const
Get the Z value of the current joystick.
Definition: Joystick.cpp:65