Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2016-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 | #include "GenericHID.h" |
| 9 | |
| 10 | #include "DriverStation.h" |
| 11 | |
| 12 | using namespace frc; |
| 13 | |
| 14 | GenericHID::GenericHID(int port) : m_ds(DriverStation::GetInstance()) { |
| 15 | m_port = port; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Get the value of the axis. |
| 20 | * |
| 21 | * @param axis The axis to read, starting at 0. |
| 22 | * @return The value of the axis. |
| 23 | */ |
| 24 | double GenericHID::GetRawAxis(int axis) const { |
| 25 | return m_ds.GetStickAxis(m_port, axis); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Get the button value (starting at button 1) |
| 30 | * |
| 31 | * The buttons are returned in a single 16 bit value with one bit representing |
| 32 | * the state of each button. The appropriate button is returned as a boolean |
| 33 | * value. |
| 34 | * |
| 35 | * @param button The button number to be read (starting at 1) |
| 36 | * @return The state of the button. |
| 37 | **/ |
| 38 | bool GenericHID::GetRawButton(int button) const { |
| 39 | return m_ds.GetStickButton(m_port, button); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the angle in degrees of a POV on the HID. |
| 44 | * |
| 45 | * The POV angles start at 0 in the up direction, and increase clockwise |
| 46 | * (e.g. right is 90, upper-left is 315). |
| 47 | * |
| 48 | * @param pov The index of the POV to read (starting at 0) |
| 49 | * @return the angle of the POV in degrees, or -1 if the POV is not pressed. |
| 50 | */ |
| 51 | int GenericHID::GetPOV(int pov) const { return 0; } |
| 52 | |
| 53 | /** |
| 54 | * Get the number of POVs for the HID. |
| 55 | * |
| 56 | * @return the number of POVs for the current HID |
| 57 | */ |
| 58 | int GenericHID::GetPOVCount() const { return 0; } |
| 59 | |
| 60 | /** |
| 61 | * Get the port number of the HID. |
| 62 | * |
| 63 | * @return The port number of the HID. |
| 64 | */ |
| 65 | int GenericHID::GetPort() const { return m_port; } |
| 66 | |
| 67 | /** |
| 68 | * Get the type of the HID. |
| 69 | * |
| 70 | * @return the type of the HID. |
| 71 | */ |
| 72 | GenericHID::HIDType GenericHID::GetType() const { return HIDType::kUnknown; } |
| 73 | |
| 74 | /** |
| 75 | * Get the name of the HID. |
| 76 | * |
| 77 | * @return the name of the HID. |
| 78 | */ |
| 79 | std::string GenericHID::GetName() const { return ""; } |
| 80 | |
| 81 | /** |
| 82 | * Set a single HID output value for the HID. |
| 83 | * |
| 84 | * @param outputNumber The index of the output to set (1-32) |
| 85 | * @param value The value to set the output to |
| 86 | */ |
| 87 | |
| 88 | void GenericHID::SetOutput(int outputNumber, bool value) { |
| 89 | m_outputs = |
| 90 | (m_outputs & ~(1 << (outputNumber - 1))) | (value << (outputNumber - 1)); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Set all output values for the HID. |
| 95 | * |
| 96 | * @param value The 32 bit output value (1 bit for each output) |
| 97 | */ |
| 98 | void GenericHID::SetOutputs(int value) { m_outputs = value; } |
| 99 | |
| 100 | /** |
| 101 | * Set the rumble output for the HID. |
| 102 | * |
| 103 | * The DS currently supports 2 rumble values, left rumble and right rumble. |
| 104 | * |
| 105 | * @param type Which rumble value to set |
| 106 | * @param value The normalized value (0 to 1) to set the rumble to |
| 107 | */ |
| 108 | void GenericHID::SetRumble(RumbleType type, double value) { |
| 109 | if (value < 0) |
| 110 | value = 0; |
| 111 | else if (value > 1) |
| 112 | value = 1; |
| 113 | if (type == kLeftRumble) { |
| 114 | m_leftRumble = value * 65535; |
| 115 | } else { |
| 116 | m_rightRumble = value * 65535; |
| 117 | } |
| 118 | } |