Convert joystick_reader over to event loops.
Change-Id: I97b78254b0fc96853f162b66ef75ec97a6c9c50b
diff --git a/aos/input/joystick_input.h b/aos/input/joystick_input.h
index 4b5c5a6..98a89b1 100644
--- a/aos/input/joystick_input.h
+++ b/aos/input/joystick_input.h
@@ -3,6 +3,7 @@
#include <atomic>
+#include "aos/events/event-loop.h"
#include "aos/input/driver_station_data.h"
namespace aos {
@@ -15,15 +16,34 @@
// (at INFO) button edges.
class JoystickInput {
public:
+ explicit JoystickInput(::aos::EventLoop *event_loop)
+ : event_loop_(event_loop) {
+ event_loop_->MakeWatcher(
+ ".aos.joystick_state",
+ [this](const ::aos::JoystickState &joystick_state) {
+ this->HandleData(joystick_state);
+ });
+ }
+
void Run();
+ protected:
+ int mode() const { return mode_; }
+
private:
+ void HandleData(const ::aos::JoystickState &joystick_state);
+
// Subclasses should do whatever they want with data here.
virtual void RunIteration(const driver_station::Data &data) = 0;
static void Quit(int /*signum*/);
static ::std::atomic<bool> run_;
+
+ EventLoop *event_loop_;
+ driver_station::Data data_;
+
+ int mode_;
};
// Class which will proxy joystick information from UDP packets to the queues.