blob: 39759302fbaab9588f0e8f326be8d3015077e5bc [file] [log] [blame]
Brian Silverman14fd0fb2014-01-14 21:42:01 -08001#include "aos/prime/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 }
33 }
Brian Silverman6da04272014-05-18 18:47:48 -070034 }
35 {
Brian Silvermana7dec802013-11-04 20:53:19 -080036 using driver_station::ControlBit;
37 if (data.PosEdge(ControlBit::kFmsAttached)) {
38 LOG(INFO, "PosEdge(kFmsAttached)\n");
39 }
40 if (data.NegEdge(ControlBit::kFmsAttached)) {
41 LOG(INFO, "NegEdge(kFmsAttached)\n");
42 }
43 if (data.PosEdge(ControlBit::kAutonomous)) {
44 LOG(INFO, "PosEdge(kAutonomous)\n");
45 }
46 if (data.NegEdge(ControlBit::kAutonomous)) {
47 LOG(INFO, "NegEdge(kAutonomous)\n");
48 }
49 if (data.PosEdge(ControlBit::kEnabled)) {
50 LOG(INFO, "PosEdge(kEnabled)\n");
51 }
52 if (data.NegEdge(ControlBit::kEnabled)) {
53 LOG(INFO, "NegEdge(kEnabled)\n");
54 }
Brian Silvermanc25bc892013-05-09 19:09:34 -070055 }
Brian Silvermanba3de7e2013-05-08 16:18:15 -070056
57 RunIteration(data);
58 }
59}
60
61} // namespace input
62} // namespace aos