blob: a6ada96d879ec0d8851f912929f94ec8d5038690 [file] [log] [blame]
Brian Silvermanc2065732015-11-28 22:55:30 +00001#include "aos/input/joystick_input.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07002
3#include <string.h>
4
Brian Silverman2ac0fbc2014-03-20 19:45:13 -07005#include "aos/common/messages/robot_state.q.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07006#include "aos/common/logging/logging.h"
Brian Silvermane155ebc2014-03-20 19:37:57 -07007#include "aos/common/logging/queue_logging.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07008
9namespace aos {
10namespace input {
11
Austin Schuh374fd172014-10-25 17:57:54 -070012void JoystickInput::Run() {
13 driver_station::Data data;
14 while (true) {
Brian Silverman699f0cb2015-02-05 19:45:01 -050015 joystick_state.FetchAnother();
Austin Schuh374fd172014-10-25 17:57:54 -070016
Brian Silverman699f0cb2015-02-05 19:45:01 -050017 data.Update(*joystick_state);
Brian Silvermanc25bc892013-05-09 19:09:34 -070018
19 {
20 using driver_station::JoystickFeature;
21 using driver_station::ButtonLocation;
Brian Silverman3d4b8972013-05-15 20:35:33 -070022 for (int joystick = 1; joystick <= JoystickFeature::kJoysticks;
Brian Silvermanc25bc892013-05-09 19:09:34 -070023 ++joystick) {
Brian Silverman3d4b8972013-05-15 20:35:33 -070024 for (int button = 1; button <= ButtonLocation::kButtons; ++button) {
Brian Silvermanc25bc892013-05-09 19:09:34 -070025 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 Silverman7b9ab672015-03-14 23:41:41 -070033 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 Silvermanc25bc892013-05-09 19:09:34 -070037 }
Brian Silverman6da04272014-05-18 18:47:48 -070038 }
39 {
Brian Silvermana7dec802013-11-04 20:53:19 -080040 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 Silvermanc25bc892013-05-09 19:09:34 -070059 }
Brian Silvermanba3de7e2013-05-08 16:18:15 -070060
61 RunIteration(data);
62 }
63}
64
65} // namespace input
66} // namespace aos