WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
Joystick.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef JOYSTICK_H_
8 #define JOYSTICK_H_
9 
10 #include "GenericHID.h"
11 #include "ErrorBase.h"
12 
13 class DriverStation;
14 
21 class Joystick : public GenericHID, public ErrorBase
22 {
23 public:
24  static const uint32_t kDefaultXAxis = 1;
25  static const uint32_t kDefaultYAxis = 2;
26  static const uint32_t kDefaultZAxis = 3;
27  static const uint32_t kDefaultTwistAxis = 4;
28  static const uint32_t kDefaultThrottleAxis = 3;
29  typedef enum
30  {
31  kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis, kNumAxisTypes
32  } AxisType;
33  static const uint32_t kDefaultTriggerButton = 1;
34  static const uint32_t kDefaultTopButton = 2;
35  typedef enum
36  {
37  kTriggerButton, kTopButton, kNumButtonTypes
38  } ButtonType;
39 
40  explicit Joystick(uint32_t port);
41  Joystick(uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes);
42  virtual ~Joystick();
43 
44  uint32_t GetAxisChannel(AxisType axis);
45  void SetAxisChannel(AxisType axis, uint32_t channel);
46 
47  virtual float GetX(JoystickHand hand = kRightHand);
48  virtual float GetY(JoystickHand hand = kRightHand);
49  virtual float GetZ();
50  virtual float GetTwist();
51  virtual float GetThrottle();
52  virtual float GetAxis(AxisType axis);
53  float GetRawAxis(uint32_t axis);
54 
55  virtual bool GetTrigger(JoystickHand hand = kRightHand);
56  virtual bool GetTop(JoystickHand hand = kRightHand);
57  virtual bool GetBumper(JoystickHand hand = kRightHand);
58  virtual bool GetButton(ButtonType button);
59  bool GetRawButton(uint32_t button);
60  static Joystick* GetStickForPort(uint32_t port);
61 
62  virtual float GetMagnitude();
63  virtual float GetDirectionRadians();
64  virtual float GetDirectionDegrees();
65 
66 private:
67  DISALLOW_COPY_AND_ASSIGN(Joystick);
68  void InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes);
69 
70  DriverStation *m_ds;
71  uint32_t m_port;
72  uint32_t *m_axes;
73  uint32_t *m_buttons;
74 };
75 
76 #endif
77 
float GetRawAxis(uint32_t axis)
Definition: Joystick.cpp:151
virtual bool GetButton(ButtonType button)
Definition: Joystick.cpp:238
virtual float GetX(JoystickHand hand=kRightHand)
Definition: Joystick.cpp:104
virtual float GetMagnitude()
Definition: Joystick.cpp:277
virtual bool GetTrigger(JoystickHand hand=kRightHand)
Definition: Joystick.cpp:188
virtual float GetTwist()
Definition: Joystick.cpp:131
virtual float GetThrottle()
Definition: Joystick.cpp:140
Definition: ErrorBase.h:37
virtual float GetDirectionRadians()
Definition: Joystick.cpp:287
Joystick(uint32_t port)
Definition: Joystick.cpp:29
Definition: Joystick.h:21
virtual float GetY(JoystickHand hand=kRightHand)
Definition: Joystick.cpp:113
bool GetRawButton(uint32_t button)
Definition: Joystick.cpp:225
virtual bool GetBumper(JoystickHand hand=kRightHand)
Definition: Joystick.cpp:210
virtual bool GetTop(JoystickHand hand=kRightHand)
Definition: Joystick.cpp:201
uint32_t GetAxisChannel(AxisType axis)
Definition: Joystick.cpp:255
virtual float GetDirectionDegrees()
Definition: Joystick.cpp:300
Definition: GenericHID.h:14
void SetAxisChannel(AxisType axis, uint32_t channel)
Definition: Joystick.cpp:266
virtual float GetAxis(AxisType axis)
Definition: Joystick.cpp:165
virtual float GetZ()
Definition: Joystick.cpp:122
Definition: DriverStation.h:21