Brian Silverman | c206573 | 2015-11-28 22:55:30 +0000 | [diff] [blame] | 1 | #ifndef AOS_INPUT_JOYSTICK_INPUT_H_ |
| 2 | #define AOS_INPUT_JOYSTICK_INPUT_H_ |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 3 | |
Austin Schuh | b58ceb6 | 2017-02-05 14:21:57 -0800 | [diff] [blame] | 4 | #include <atomic> |
| 5 | |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 6 | #include "aos/events/event-loop.h" |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 7 | #include "aos/input/driver_station_data.h" |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 8 | |
| 9 | namespace aos { |
| 10 | namespace input { |
| 11 | |
Brian Silverman | c25bc89 | 2013-05-09 19:09:34 -0700 | [diff] [blame] | 12 | // A class for handling joystick packet values. |
| 13 | // It will call RunIteration each time a new packet is received. |
| 14 | // |
Brian Silverman | 699f0cb | 2015-02-05 19:45:01 -0500 | [diff] [blame] | 15 | // This class automatically handles updating ::aos::joystick_state and logging |
| 16 | // (at INFO) button edges. |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 17 | class JoystickInput { |
| 18 | public: |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 19 | explicit JoystickInput(::aos::EventLoop *event_loop) |
| 20 | : event_loop_(event_loop) { |
| 21 | event_loop_->MakeWatcher( |
| 22 | ".aos.joystick_state", |
| 23 | [this](const ::aos::JoystickState &joystick_state) { |
| 24 | this->HandleData(joystick_state); |
| 25 | }); |
Austin Schuh | 9fe68f7 | 2019-08-10 19:32:03 -0700 | [diff] [blame^] | 26 | event_loop->SetRuntimeRealtimePriority(29); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 27 | } |
| 28 | |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 29 | protected: |
| 30 | int mode() const { return mode_; } |
| 31 | |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 32 | private: |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 33 | void HandleData(const ::aos::JoystickState &joystick_state); |
| 34 | |
Brian Silverman | c25bc89 | 2013-05-09 19:09:34 -0700 | [diff] [blame] | 35 | // Subclasses should do whatever they want with data here. |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 36 | virtual void RunIteration(const driver_station::Data &data) = 0; |
Austin Schuh | b58ceb6 | 2017-02-05 14:21:57 -0800 | [diff] [blame] | 37 | |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 38 | EventLoop *event_loop_; |
| 39 | driver_station::Data data_; |
| 40 | |
| 41 | int mode_; |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Austin Schuh | 374fd17 | 2014-10-25 17:57:54 -0700 | [diff] [blame] | 44 | // Class which will proxy joystick information from UDP packets to the queues. |
| 45 | class JoystickProxy { |
| 46 | public: |
| 47 | void Run(); |
| 48 | }; |
| 49 | |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 50 | } // namespace input |
| 51 | } // namespace aos |
| 52 | |
Brian Silverman | c206573 | 2015-11-28 22:55:30 +0000 | [diff] [blame] | 53 | #endif // AOS_INPUT_JOYSTICK_INPUT_H_ |