blob: b6d0ceb01e4ca8b31fcb3b48f0d6d7ffc4f42e9c [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
Alex Perrycb7da4b2019-08-28 19:35:56 -07006#include "aos/events/event_loop.h"
James Kuszmaul7077d342021-06-09 20:23:58 -07007#include "frc971/input/driver_station_data.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07008
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -08009namespace frc971::input {
Brian Silvermanba3de7e2013-05-08 16:18:15 -070010
Brian Silvermanc25bc892013-05-09 19:09:34 -070011// A class for handling joystick packet values.
12// It will call RunIteration each time a new packet is received.
13//
Brian Silverman699f0cb2015-02-05 19:45:01 -050014// This class automatically handles updating ::aos::joystick_state and logging
15// (at INFO) button edges.
Brian Silvermanba3de7e2013-05-08 16:18:15 -070016class JoystickInput {
17 public:
Austin Schuh3e45c752019-02-02 12:19:11 -080018 explicit JoystickInput(::aos::EventLoop *event_loop)
19 : event_loop_(event_loop) {
20 event_loop_->MakeWatcher(
Austin Schuhed5b26d2019-12-05 20:51:59 -080021 "/aos", [this](const ::aos::JoystickState &joystick_state) {
Alex Perrycb7da4b2019-08-28 19:35:56 -070022 this->HandleData(&joystick_state);
Austin Schuh3e45c752019-02-02 12:19:11 -080023 });
Austin Schuh094d09b2020-11-20 23:26:52 -080024 event_loop->SetRuntimeRealtimePriority(28);
Austin Schuh3e45c752019-02-02 12:19:11 -080025 }
26
Austin Schuh3e45c752019-02-02 12:19:11 -080027 protected:
28 int mode() const { return mode_; }
29
Brian Silvermanba3de7e2013-05-08 16:18:15 -070030 private:
Alex Perrycb7da4b2019-08-28 19:35:56 -070031 void HandleData(const ::aos::JoystickState *joystick_state);
Austin Schuh3e45c752019-02-02 12:19:11 -080032
Brian Silvermanc25bc892013-05-09 19:09:34 -070033 // Subclasses should do whatever they want with data here.
Brian Silvermanba3de7e2013-05-08 16:18:15 -070034 virtual void RunIteration(const driver_station::Data &data) = 0;
Austin Schuhb58ceb62017-02-05 14:21:57 -080035
James Kuszmaul7077d342021-06-09 20:23:58 -070036 ::aos::EventLoop *event_loop_;
Austin Schuh3e45c752019-02-02 12:19:11 -080037 driver_station::Data data_;
38
39 int mode_;
Brian Silvermanba3de7e2013-05-08 16:18:15 -070040};
41
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080042} // namespace frc971::input
Brian Silvermanba3de7e2013-05-08 16:18:15 -070043
Brian Silvermanc2065732015-11-28 22:55:30 +000044#endif // AOS_INPUT_JOYSTICK_INPUT_H_