James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 1 | #include "frc971/input/joystick_input.h" |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 2 | |
Austin Schuh | b58ceb6 | 2017-02-05 14:21:57 -0800 | [diff] [blame] | 3 | #include <atomic> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 4 | #include <cstring> |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 5 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 6 | #include "aos/logging/logging.h" |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 7 | #include "frc971/input/robot_state_generated.h" |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 8 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 9 | namespace frc971::input { |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 10 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 11 | void JoystickInput::HandleData(const ::aos::JoystickState *joystick_state) { |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 12 | data_.Update(joystick_state); |
| 13 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 14 | mode_ = static_cast<int>(joystick_state->switch_left()) | |
| 15 | (static_cast<int>(joystick_state->scale_left()) << 1); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 16 | |
| 17 | { |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 18 | using driver_station::ButtonLocation; |
James Kuszmaul | 7077d34 | 2021-06-09 20:23:58 -0700 | [diff] [blame] | 19 | using driver_station::JoystickFeature; |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 20 | 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 Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 25 | AOS_LOG(INFO, "PosEdge(%d, %d)\n", joystick, button); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 26 | } |
| 27 | if (data_.NegEdge(location)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 28 | AOS_LOG(INFO, "NegEdge(%d, %d)\n", joystick, button); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | if (data_.GetPOV(joystick) != data_.GetOldPOV(joystick)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 32 | AOS_LOG(INFO, "POV %d %d->%d\n", joystick, data_.GetOldPOV(joystick), |
| 33 | data_.GetPOV(joystick)); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | } |
| 37 | { |
| 38 | using driver_station::ControlBit; |
| 39 | if (data_.PosEdge(ControlBit::kFmsAttached)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 40 | AOS_LOG(INFO, "PosEdge(kFmsAttached)\n"); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 41 | } |
| 42 | if (data_.NegEdge(ControlBit::kFmsAttached)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 43 | AOS_LOG(INFO, "NegEdge(kFmsAttached)\n"); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 44 | } |
| 45 | if (data_.PosEdge(ControlBit::kAutonomous)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 46 | AOS_LOG(INFO, "PosEdge(kAutonomous)\n"); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 47 | } |
| 48 | if (data_.NegEdge(ControlBit::kAutonomous)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 49 | AOS_LOG(INFO, "NegEdge(kAutonomous)\n"); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 50 | } |
| 51 | if (data_.PosEdge(ControlBit::kEnabled)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 52 | AOS_LOG(INFO, "PosEdge(kEnabled)\n"); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 53 | } |
| 54 | if (data_.NegEdge(ControlBit::kEnabled)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 55 | AOS_LOG(INFO, "NegEdge(kEnabled)\n"); |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | RunIteration(data_); |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame^] | 62 | } // namespace frc971::input |