Ravago Jones | 8c65c43 | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 1 | #ifndef AOS_INPUT_REDUNDANT_JOYSTICK_DATA_H_ |
| 2 | #define AOS_INPUT_REDUNDANT_JOYSTICK_DATA_H_ |
| 3 | |
| 4 | #include "frc971/input/driver_station_data.h" |
| 5 | |
| 6 | namespace frc971 { |
| 7 | namespace input { |
| 8 | namespace driver_station { |
| 9 | |
| 10 | // A class to wrap driver_station::Data and map logical joystick numbers to |
| 11 | // their actual numbers in the order they are on the driverstation. |
| 12 | // |
| 13 | // Bits 13 and 14 of the joystick bitmap are defined to be a two bit number |
| 14 | // corresponding to the joystick's logical joystick number. |
| 15 | class RedundantData : public Data { |
| 16 | public: |
| 17 | RedundantData(const Data &data); |
| 18 | |
| 19 | bool IsPressed(POVLocation location) const override; |
| 20 | bool PosEdge(POVLocation location) const override; |
| 21 | bool NegEdge(POVLocation location) const override; |
| 22 | |
| 23 | // Returns the current and previous "values" for the POV. |
| 24 | int32_t GetPOV(int joystick) const override; |
| 25 | int32_t GetOldPOV(int joystick) const override; |
| 26 | |
| 27 | bool IsPressed(ButtonLocation location) const override; |
| 28 | bool PosEdge(ButtonLocation location) const override; |
| 29 | bool NegEdge(ButtonLocation location) const override; |
| 30 | |
| 31 | bool GetControlBit(ControlBit bit) const override; |
| 32 | bool PosEdge(ControlBit bit) const override; |
| 33 | bool NegEdge(ControlBit bit) const override; |
| 34 | |
| 35 | // Returns the value in the range [-1.0, 1.0]. |
| 36 | float GetAxis(JoystickAxis axis) const override; |
| 37 | |
| 38 | private: |
| 39 | static constexpr int kIdBit0Button = 14; |
| 40 | static constexpr int kIdBit1Button = 15; |
| 41 | static constexpr int kRedundantBitButton = 16; |
| 42 | |
| 43 | int MapRedundantJoystick(int joystick) const; |
| 44 | |
| 45 | // A mapping from logical joystick numbers to their actual order on the |
| 46 | // driverstation. |
| 47 | // |
| 48 | // Index is logical joystick number, Value is mapped joystick number. |
| 49 | std::array<int, JoystickFeature::kJoysticks> joystick_map_; |
| 50 | |
| 51 | const Data &data_; |
| 52 | }; |
| 53 | |
| 54 | } // namespace driver_station |
| 55 | } // namespace input |
| 56 | } // namespace frc971 |
| 57 | |
| 58 | #endif // AOS_INPUT_REDUNDANT_JOYSTICK_DATA_H_ |