blob: 04b98ef68fbf764ef20aaa6f43458333d333263a [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
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
13class DriverStation;
14
15/**
16 * Handle input from standard Joysticks connected to the Driver Station.
17 * This class handles standard input that comes from the Driver Station. Each time a value is requested
18 * the most recent value is returned. There is a single class instance for each joystick and the mapping
19 * of ports to hardware buttons depends on the code in the driver station.
20 */
21class Joystick : public GenericHID, public ErrorBase
22{
23public:
24 static const UINT32 kDefaultXAxis = 1;
25 static const UINT32 kDefaultYAxis = 2;
26 static const UINT32 kDefaultZAxis = 3;
27 static const UINT32 kDefaultTwistAxis = 4;
28 static const UINT32 kDefaultThrottleAxis = 3;
29 typedef enum
30 {
31 kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis, kNumAxisTypes
32 } AxisType;
33 static const UINT32 kDefaultTriggerButton = 1;
34 static const UINT32 kDefaultTopButton = 2;
35 typedef enum
36 {
37 kTriggerButton, kTopButton, kNumButtonTypes
38 } ButtonType;
39
40 explicit Joystick(UINT32 port);
41 Joystick(UINT32 port, UINT32 numAxisTypes, UINT32 numButtonTypes);
42 virtual ~Joystick();
43
44 UINT32 GetAxisChannel(AxisType axis);
45 void SetAxisChannel(AxisType axis, UINT32 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 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 button);
60 static Joystick* GetStickForPort(UINT32 port);
61
62 virtual float GetMagnitude();
63 virtual float GetDirectionRadians();
64 virtual float GetDirectionDegrees();
65
66private:
67 DISALLOW_COPY_AND_ASSIGN(Joystick);
68 void InitJoystick(UINT32 numAxisTypes, UINT32 numButtonTypes);
69
70 DriverStation *m_ds;
71 UINT32 m_port;
72 UINT32 *m_axes;
73 UINT32 *m_buttons;
74};
75
76#endif
77