brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2011. 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 __KINECT_STICK_H__ |
| 8 | #define __KINECT_STICK_H__ |
| 9 | |
| 10 | #include "ErrorBase.h" |
| 11 | #include "GenericHID.h" |
| 12 | |
| 13 | /** |
| 14 | * Handles input from the Joystick data sent by the FRC Kinect Server |
| 15 | * when used with a Kinect device connected to the Driver Station. |
| 16 | * Each time a value is requested the most recent value is returned. |
| 17 | * Default gestures embedded in the FRC Kinect Server are described |
| 18 | * in the document Getting Started with Microsoft Kinect for FRC. |
| 19 | */ |
| 20 | class KinectStick : public GenericHID, public ErrorBase |
| 21 | { |
| 22 | public: |
| 23 | explicit KinectStick(int id); |
| 24 | virtual float GetX(JoystickHand hand = kRightHand); |
| 25 | virtual float GetY(JoystickHand hand = kRightHand); |
| 26 | virtual float GetZ(); |
| 27 | virtual float GetTwist(); |
| 28 | virtual float GetThrottle(); |
Brian Silverman | 6874947 | 2014-01-05 14:50:00 -0800 | [diff] [blame] | 29 | virtual float GetRawAxis(uint32_t axis); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 30 | |
| 31 | virtual bool GetTrigger(JoystickHand hand = kRightHand); |
| 32 | virtual bool GetTop(JoystickHand hand = kRightHand); |
| 33 | virtual bool GetBumper(JoystickHand hand = kRightHand); |
Brian Silverman | 6874947 | 2014-01-05 14:50:00 -0800 | [diff] [blame] | 34 | virtual bool GetRawButton(uint32_t button); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 35 | |
| 36 | private: |
| 37 | void GetData(); |
Brian Silverman | 6874947 | 2014-01-05 14:50:00 -0800 | [diff] [blame] | 38 | float ConvertRawToFloat(int8_t charValue); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 39 | |
| 40 | typedef union |
| 41 | { |
| 42 | struct |
| 43 | { |
Brian Silverman | 6874947 | 2014-01-05 14:50:00 -0800 | [diff] [blame] | 44 | uint8_t size; |
| 45 | uint8_t id; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 46 | struct |
| 47 | { |
| 48 | unsigned char axis[6]; |
| 49 | unsigned short buttons; |
| 50 | } rawSticks[2]; |
| 51 | } formatted; |
| 52 | char data[18]; |
| 53 | } KinectStickData; |
| 54 | |
| 55 | int m_id; |
Brian Silverman | 6874947 | 2014-01-05 14:50:00 -0800 | [diff] [blame] | 56 | static uint32_t _recentPacketNumber; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 57 | static KinectStickData _sticks; |
| 58 | }; |
| 59 | |
| 60 | #endif |
| 61 | |