WPILib 2012
WPILibRoboticsLibraryforFRC
|
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #ifndef JOYSTICK_H_ 00008 #define JOYSTICK_H_ 00009 00010 #include "GenericHID.h" 00011 #include "ErrorBase.h" 00012 00013 class DriverStation; 00014 00021 class Joystick : public GenericHID, public ErrorBase 00022 { 00023 public: 00024 static const UINT32 kDefaultXAxis = 1; 00025 static const UINT32 kDefaultYAxis = 2; 00026 static const UINT32 kDefaultZAxis = 3; 00027 static const UINT32 kDefaultTwistAxis = 4; 00028 static const UINT32 kDefaultThrottleAxis = 3; 00029 typedef enum 00030 { 00031 kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis, kNumAxisTypes 00032 } AxisType; 00033 static const UINT32 kDefaultTriggerButton = 1; 00034 static const UINT32 kDefaultTopButton = 2; 00035 typedef enum 00036 { 00037 kTriggerButton, kTopButton, kNumButtonTypes 00038 } ButtonType; 00039 00040 explicit Joystick(UINT32 port); 00041 Joystick(UINT32 port, UINT32 numAxisTypes, UINT32 numButtonTypes); 00042 virtual ~Joystick(); 00043 00044 UINT32 GetAxisChannel(AxisType axis); 00045 void SetAxisChannel(AxisType axis, UINT32 channel); 00046 00047 virtual float GetX(JoystickHand hand = kRightHand); 00048 virtual float GetY(JoystickHand hand = kRightHand); 00049 virtual float GetZ(); 00050 virtual float GetTwist(); 00051 virtual float GetThrottle(); 00052 virtual float GetAxis(AxisType axis); 00053 float GetRawAxis(UINT32 axis); 00054 00055 virtual bool GetTrigger(JoystickHand hand = kRightHand); 00056 virtual bool GetTop(JoystickHand hand = kRightHand); 00057 virtual bool GetBumper(JoystickHand hand = kRightHand); 00058 virtual bool GetButton(ButtonType button); 00059 bool GetRawButton(UINT32 button); 00060 static Joystick* GetStickForPort(UINT32 port); 00061 00062 virtual float GetMagnitude(); 00063 virtual float GetDirectionRadians(); 00064 virtual float GetDirectionDegrees(); 00065 00066 private: 00067 DISALLOW_COPY_AND_ASSIGN(Joystick); 00068 void InitJoystick(UINT32 numAxisTypes, UINT32 numButtonTypes); 00069 00070 DriverStation *m_ds; 00071 UINT32 m_port; 00072 UINT32 *m_axes; 00073 UINT32 *m_buttons; 00074 }; 00075 00076 #endif 00077