brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #ifndef AOS_INPUT_JOYSTICK_INPUT_H_ |
| 2 | #define AOS_INPUT_JOYSTICK_INPUT_H_ |
| 3 | |
| 4 | #include "FRCComm.h" |
| 5 | |
| 6 | namespace aos { |
| 7 | |
| 8 | // Class for implementing atom code that reads the joystick values from the |
| 9 | // cRIO. |
| 10 | // Designed for a subclass that implements RunIteration to be instantiated and |
| 11 | // Runed. |
| 12 | class JoystickInput { |
| 13 | private: |
| 14 | uint16_t buttons[4], old_buttons[4]; |
| 15 | inline uint16_t MASK(int button) { |
| 16 | return 1 << ((button > 8) ? (button - 9) : (button + 7)); |
| 17 | } |
| 18 | void SetupButtons(); |
| 19 | protected: |
| 20 | FRCCommonControlData control_data_; |
| 21 | |
| 22 | // Constants that retrieve data when used with joystick 0. |
| 23 | static const int ENABLED = 13; |
| 24 | static const int AUTONOMOUS = 14; |
| 25 | static const int FMS_ATTACHED = 15; |
brians | 6591d58 | 2013-03-03 05:31:53 +0000 | [diff] [blame^] | 26 | static const int TEST_MODE = 16; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 27 | bool Pressed(int stick, int button) { |
| 28 | return buttons[stick] & MASK(button); |
| 29 | } |
| 30 | bool PosEdge(int stick, int button) { |
| 31 | return !(old_buttons[stick] & MASK(button)) && (buttons[stick] & MASK(button)); |
| 32 | } |
| 33 | bool NegEdge(int stick, int button) { |
| 34 | return (old_buttons[stick] & MASK(button)) && !(buttons[stick] & MASK(button)); |
| 35 | } |
| 36 | |
| 37 | virtual void RunIteration() = 0; |
| 38 | public: |
| 39 | // Enters an infinite loop that reads values and calls RunIteration. |
| 40 | void Run(); |
| 41 | }; |
| 42 | |
| 43 | } // namespace aos |
| 44 | |
| 45 | #endif |
| 46 | |