Brian Silverman | c206573 | 2015-11-28 22:55:30 +0000 | [diff] [blame] | 1 | #include "aos/input/joystick_input.h" |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 2 | |
| 3 | #include <string.h> |
Austin Schuh | b58ceb6 | 2017-02-05 14:21:57 -0800 | [diff] [blame] | 4 | #include <atomic> |
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/robot_state/robot_state.q.h" |
| 7 | #include "aos/logging/logging.h" |
| 8 | #include "aos/logging/queue_logging.h" |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 9 | |
| 10 | namespace aos { |
| 11 | namespace input { |
| 12 | |
Austin Schuh | 3e45c75 | 2019-02-02 12:19:11 -0800 | [diff] [blame] | 13 | void JoystickInput::HandleData(const ::aos::JoystickState &joystick_state) { |
| 14 | data_.Update(joystick_state); |
| 15 | |
| 16 | mode_ = static_cast<int>(joystick_state.switch_left) | |
| 17 | (static_cast<int>(joystick_state.scale_left) << 1); |
| 18 | |
| 19 | { |
| 20 | using driver_station::JoystickFeature; |
| 21 | using driver_station::ButtonLocation; |
| 22 | for (int joystick = 1; joystick <= JoystickFeature::kJoysticks; |
| 23 | ++joystick) { |
| 24 | for (int button = 1; button <= ButtonLocation::kButtons; ++button) { |
| 25 | ButtonLocation location(joystick, button); |
| 26 | if (data_.PosEdge(location)) { |
| 27 | LOG(INFO, "PosEdge(%d, %d)\n", joystick, button); |
| 28 | } |
| 29 | if (data_.NegEdge(location)) { |
| 30 | LOG(INFO, "NegEdge(%d, %d)\n", joystick, button); |
| 31 | } |
| 32 | } |
| 33 | if (data_.GetPOV(joystick) != data_.GetOldPOV(joystick)) { |
| 34 | LOG(INFO, "POV %d %d->%d\n", joystick, data_.GetOldPOV(joystick), |
| 35 | data_.GetPOV(joystick)); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | { |
| 40 | using driver_station::ControlBit; |
| 41 | if (data_.PosEdge(ControlBit::kFmsAttached)) { |
| 42 | LOG(INFO, "PosEdge(kFmsAttached)\n"); |
| 43 | } |
| 44 | if (data_.NegEdge(ControlBit::kFmsAttached)) { |
| 45 | LOG(INFO, "NegEdge(kFmsAttached)\n"); |
| 46 | } |
| 47 | if (data_.PosEdge(ControlBit::kAutonomous)) { |
| 48 | LOG(INFO, "PosEdge(kAutonomous)\n"); |
| 49 | } |
| 50 | if (data_.NegEdge(ControlBit::kAutonomous)) { |
| 51 | LOG(INFO, "NegEdge(kAutonomous)\n"); |
| 52 | } |
| 53 | if (data_.PosEdge(ControlBit::kEnabled)) { |
| 54 | LOG(INFO, "PosEdge(kEnabled)\n"); |
| 55 | } |
| 56 | if (data_.NegEdge(ControlBit::kEnabled)) { |
| 57 | LOG(INFO, "NegEdge(kEnabled)\n"); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | RunIteration(data_); |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } // namespace input |
| 65 | } // namespace aos |