blob: 19eaa37904c03949fc8d100b72ba6e20bfb42b4c [file] [log] [blame]
James Kuszmaul7077d342021-06-09 20:23:58 -07001#include "frc971/input/joystick_input.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07002
Austin Schuhb58ceb62017-02-05 14:21:57 -08003#include <atomic>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cstring>
Brian Silvermanba3de7e2013-05-08 16:18:15 -07005
John Park33858a32018-09-28 23:05:48 -07006#include "aos/logging/logging.h"
James Kuszmaul7077d342021-06-09 20:23:58 -07007#include "frc971/input/robot_state_generated.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07008
Stephan Pleinesf63bde82024-01-13 15:59:33 -08009namespace frc971::input {
Brian Silvermanba3de7e2013-05-08 16:18:15 -070010
Alex Perrycb7da4b2019-08-28 19:35:56 -070011void JoystickInput::HandleData(const ::aos::JoystickState *joystick_state) {
Austin Schuh3e45c752019-02-02 12:19:11 -080012 data_.Update(joystick_state);
13
Alex Perrycb7da4b2019-08-28 19:35:56 -070014 mode_ = static_cast<int>(joystick_state->switch_left()) |
15 (static_cast<int>(joystick_state->scale_left()) << 1);
Austin Schuh3e45c752019-02-02 12:19:11 -080016
17 {
Austin Schuh3e45c752019-02-02 12:19:11 -080018 using driver_station::ButtonLocation;
James Kuszmaul7077d342021-06-09 20:23:58 -070019 using driver_station::JoystickFeature;
Austin Schuh3e45c752019-02-02 12:19:11 -080020 for (int joystick = 1; joystick <= JoystickFeature::kJoysticks;
21 ++joystick) {
22 for (int button = 1; button <= ButtonLocation::kButtons; ++button) {
23 ButtonLocation location(joystick, button);
24 if (data_.PosEdge(location)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070025 AOS_LOG(INFO, "PosEdge(%d, %d)\n", joystick, button);
Austin Schuh3e45c752019-02-02 12:19:11 -080026 }
27 if (data_.NegEdge(location)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070028 AOS_LOG(INFO, "NegEdge(%d, %d)\n", joystick, button);
Austin Schuh3e45c752019-02-02 12:19:11 -080029 }
30 }
31 if (data_.GetPOV(joystick) != data_.GetOldPOV(joystick)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070032 AOS_LOG(INFO, "POV %d %d->%d\n", joystick, data_.GetOldPOV(joystick),
33 data_.GetPOV(joystick));
Austin Schuh3e45c752019-02-02 12:19:11 -080034 }
35 }
36 }
37 {
38 using driver_station::ControlBit;
39 if (data_.PosEdge(ControlBit::kFmsAttached)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070040 AOS_LOG(INFO, "PosEdge(kFmsAttached)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080041 }
42 if (data_.NegEdge(ControlBit::kFmsAttached)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070043 AOS_LOG(INFO, "NegEdge(kFmsAttached)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080044 }
45 if (data_.PosEdge(ControlBit::kAutonomous)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070046 AOS_LOG(INFO, "PosEdge(kAutonomous)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080047 }
48 if (data_.NegEdge(ControlBit::kAutonomous)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070049 AOS_LOG(INFO, "NegEdge(kAutonomous)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080050 }
51 if (data_.PosEdge(ControlBit::kEnabled)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070052 AOS_LOG(INFO, "PosEdge(kEnabled)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080053 }
54 if (data_.NegEdge(ControlBit::kEnabled)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070055 AOS_LOG(INFO, "NegEdge(kEnabled)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080056 }
57 }
58
59 RunIteration(data_);
Brian Silvermanba3de7e2013-05-08 16:18:15 -070060}
61
Stephan Pleinesf63bde82024-01-13 15:59:33 -080062} // namespace frc971::input