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