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> |
| 4 | |
Brian Silverman | 2ac0fbc | 2014-03-20 19:45:13 -0700 | [diff] [blame] | 5 | #include "aos/common/messages/robot_state.q.h" |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 6 | #include "aos/common/logging/logging.h" |
Brian Silverman | e155ebc | 2014-03-20 19:37:57 -0700 | [diff] [blame] | 7 | #include "aos/common/logging/queue_logging.h" |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 8 | |
| 9 | namespace aos { |
| 10 | namespace input { |
| 11 | |
Austin Schuh | 374fd17 | 2014-10-25 17:57:54 -0700 | [diff] [blame] | 12 | void JoystickInput::Run() { |
| 13 | driver_station::Data data; |
| 14 | while (true) { |
Brian Silverman | 699f0cb | 2015-02-05 19:45:01 -0500 | [diff] [blame] | 15 | joystick_state.FetchAnother(); |
Austin Schuh | 374fd17 | 2014-10-25 17:57:54 -0700 | [diff] [blame] | 16 | |
Brian Silverman | 699f0cb | 2015-02-05 19:45:01 -0500 | [diff] [blame] | 17 | data.Update(*joystick_state); |
Brian Silverman | c25bc89 | 2013-05-09 19:09:34 -0700 | [diff] [blame] | 18 | |
| 19 | { |
| 20 | using driver_station::JoystickFeature; |
| 21 | using driver_station::ButtonLocation; |
Brian Silverman | 3d4b897 | 2013-05-15 20:35:33 -0700 | [diff] [blame] | 22 | for (int joystick = 1; joystick <= JoystickFeature::kJoysticks; |
Brian Silverman | c25bc89 | 2013-05-09 19:09:34 -0700 | [diff] [blame] | 23 | ++joystick) { |
Brian Silverman | 3d4b897 | 2013-05-15 20:35:33 -0700 | [diff] [blame] | 24 | for (int button = 1; button <= ButtonLocation::kButtons; ++button) { |
Brian Silverman | c25bc89 | 2013-05-09 19:09:34 -0700 | [diff] [blame] | 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 | } |
Brian Silverman | 7b9ab67 | 2015-03-14 23:41:41 -0700 | [diff] [blame] | 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 | } |
Brian Silverman | c25bc89 | 2013-05-09 19:09:34 -0700 | [diff] [blame] | 37 | } |
Brian Silverman | 6da0427 | 2014-05-18 18:47:48 -0700 | [diff] [blame] | 38 | } |
| 39 | { |
Brian Silverman | a7dec80 | 2013-11-04 20:53:19 -0800 | [diff] [blame] | 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 | } |
Brian Silverman | c25bc89 | 2013-05-09 19:09:34 -0700 | [diff] [blame] | 59 | } |
Brian Silverman | ba3de7e | 2013-05-08 16:18:15 -0700 | [diff] [blame] | 60 | |
| 61 | RunIteration(data); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | } // namespace input |
| 66 | } // namespace aos |