blob: ed72e78df7238cfbffa6b217bb31e5e3c92e74a1 [file] [log] [blame]
Brian Silvermanc2065732015-11-28 22:55:30 +00001#ifndef AOS_INPUT_JOYSTICK_INPUT_H_
2#define AOS_INPUT_JOYSTICK_INPUT_H_
Brian Silvermanba3de7e2013-05-08 16:18:15 -07003
Austin Schuhb58ceb62017-02-05 14:21:57 -08004#include <atomic>
5
Austin Schuh3e45c752019-02-02 12:19:11 -08006#include "aos/events/event-loop.h"
John Park33858a32018-09-28 23:05:48 -07007#include "aos/input/driver_station_data.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07008
9namespace aos {
10namespace input {
11
Brian Silvermanc25bc892013-05-09 19:09:34 -070012// A class for handling joystick packet values.
13// It will call RunIteration each time a new packet is received.
14//
Brian Silverman699f0cb2015-02-05 19:45:01 -050015// This class automatically handles updating ::aos::joystick_state and logging
16// (at INFO) button edges.
Brian Silvermanba3de7e2013-05-08 16:18:15 -070017class JoystickInput {
18 public:
Austin Schuh3e45c752019-02-02 12:19:11 -080019 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 Schuh9fe68f72019-08-10 19:32:03 -070026 event_loop->SetRuntimeRealtimePriority(29);
Austin Schuh3e45c752019-02-02 12:19:11 -080027 }
28
Austin Schuh3e45c752019-02-02 12:19:11 -080029 protected:
30 int mode() const { return mode_; }
31
Brian Silvermanba3de7e2013-05-08 16:18:15 -070032 private:
Austin Schuh3e45c752019-02-02 12:19:11 -080033 void HandleData(const ::aos::JoystickState &joystick_state);
34
Brian Silvermanc25bc892013-05-09 19:09:34 -070035 // Subclasses should do whatever they want with data here.
Brian Silvermanba3de7e2013-05-08 16:18:15 -070036 virtual void RunIteration(const driver_station::Data &data) = 0;
Austin Schuhb58ceb62017-02-05 14:21:57 -080037
Austin Schuh3e45c752019-02-02 12:19:11 -080038 EventLoop *event_loop_;
39 driver_station::Data data_;
40
41 int mode_;
Brian Silvermanba3de7e2013-05-08 16:18:15 -070042};
43
Austin Schuh374fd172014-10-25 17:57:54 -070044// Class which will proxy joystick information from UDP packets to the queues.
45class JoystickProxy {
46 public:
47 void Run();
48};
49
Brian Silvermanba3de7e2013-05-08 16:18:15 -070050} // namespace input
51} // namespace aos
52
Brian Silvermanc2065732015-11-28 22:55:30 +000053#endif // AOS_INPUT_JOYSTICK_INPUT_H_