Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2017. 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 <stdint.h> |
| 11 | |
| 12 | #include <memory> |
| 13 | #include <vector> |
| 14 | |
| 15 | #include "ErrorBase.h" |
| 16 | #include "JoystickBase.h" |
| 17 | |
| 18 | namespace frc { |
| 19 | |
| 20 | class DriverStation; |
| 21 | |
| 22 | /** |
| 23 | * Handle input from standard Joysticks connected to the Driver Station. |
| 24 | * This class handles standard input that comes from the Driver Station. Each |
| 25 | * time a value is requested the most recent value is returned. There is a |
| 26 | * single class instance for each joystick and the mapping of ports to hardware |
| 27 | * buttons depends on the code in the Driver Station. |
| 28 | */ |
| 29 | class Joystick : public JoystickBase, public ErrorBase { |
| 30 | public: |
| 31 | static const int kDefaultXAxis = 0; |
| 32 | static const int kDefaultYAxis = 1; |
| 33 | static const int kDefaultZAxis = 2; |
| 34 | static const int kDefaultTwistAxis = 2; |
| 35 | static const int kDefaultThrottleAxis = 3; |
| 36 | |
| 37 | typedef enum { |
| 38 | kXAxis, |
| 39 | kYAxis, |
| 40 | kZAxis, |
| 41 | kTwistAxis, |
| 42 | kThrottleAxis, |
| 43 | kNumAxisTypes |
| 44 | } AxisType; |
| 45 | |
| 46 | static const int kDefaultTriggerButton = 1; |
| 47 | static const int kDefaultTopButton = 2; |
| 48 | |
| 49 | typedef enum { kTriggerButton, kTopButton, kNumButtonTypes } ButtonType; |
| 50 | |
| 51 | explicit Joystick(int port); |
| 52 | Joystick(int port, int numAxisTypes, int numButtonTypes); |
| 53 | virtual ~Joystick() = default; |
| 54 | |
| 55 | Joystick(const Joystick&) = delete; |
| 56 | Joystick& operator=(const Joystick&) = delete; |
| 57 | |
| 58 | int GetAxisChannel(AxisType axis) const; |
| 59 | void SetAxisChannel(AxisType axis, int channel); |
| 60 | |
| 61 | double GetX(JoystickHand hand = kRightHand) const override; |
| 62 | double GetY(JoystickHand hand = kRightHand) const override; |
| 63 | double GetZ(JoystickHand hand = kRightHand) const override; |
| 64 | double GetTwist() const override; |
| 65 | double GetThrottle() const override; |
| 66 | virtual double GetAxis(AxisType axis) const; |
| 67 | |
| 68 | bool GetTrigger(JoystickHand hand = kRightHand) const override; |
| 69 | bool GetTop(JoystickHand hand = kRightHand) const override; |
| 70 | bool GetButton(ButtonType button) const; |
| 71 | static Joystick* GetStickForPort(int port); |
| 72 | |
| 73 | virtual double GetMagnitude() const; |
| 74 | virtual double GetDirectionRadians() const; |
| 75 | virtual double GetDirectionDegrees() const; |
| 76 | |
| 77 | int GetAxisType(int axis) const; |
| 78 | |
| 79 | int GetAxisCount() const; |
| 80 | int GetButtonCount() const; |
| 81 | |
| 82 | private: |
| 83 | DriverStation& m_ds; |
| 84 | std::vector<int> m_axes; |
| 85 | std::vector<int> m_buttons; |
| 86 | }; |
| 87 | |
| 88 | } // namespace frc |