blob: ca4a033b45c6d989b47ffe683a9c556a2aa1737c [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 LOG_STRUCT(DEBUG, "sending", *joystick_state);
Austin Schuh374fd172014-10-25 17:57:54 -070018
Brian Silverman699f0cb2015-02-05 19:45:01 -050019 data.Update(*joystick_state);
Brian Silvermanc25bc892013-05-09 19:09:34 -070020
21 {
22 using driver_station::JoystickFeature;
23 using driver_station::ButtonLocation;
Brian Silverman3d4b8972013-05-15 20:35:33 -070024 for (int joystick = 1; joystick <= JoystickFeature::kJoysticks;
Brian Silvermanc25bc892013-05-09 19:09:34 -070025 ++joystick) {
Brian Silverman3d4b8972013-05-15 20:35:33 -070026 for (int button = 1; button <= ButtonLocation::kButtons; ++button) {
Brian Silvermanc25bc892013-05-09 19:09:34 -070027 ButtonLocation location(joystick, button);
28 if (data.PosEdge(location)) {
29 LOG(INFO, "PosEdge(%d, %d)\n", joystick, button);
30 }
31 if (data.NegEdge(location)) {
32 LOG(INFO, "NegEdge(%d, %d)\n", joystick, button);
33 }
34 }
35 }
Brian Silverman6da04272014-05-18 18:47:48 -070036 }
37 {
Brian Silvermana7dec802013-11-04 20:53:19 -080038 using driver_station::ControlBit;
39 if (data.PosEdge(ControlBit::kFmsAttached)) {
40 LOG(INFO, "PosEdge(kFmsAttached)\n");
41 }
42 if (data.NegEdge(ControlBit::kFmsAttached)) {
43 LOG(INFO, "NegEdge(kFmsAttached)\n");
44 }
45 if (data.PosEdge(ControlBit::kAutonomous)) {
46 LOG(INFO, "PosEdge(kAutonomous)\n");
47 }
48 if (data.NegEdge(ControlBit::kAutonomous)) {
49 LOG(INFO, "NegEdge(kAutonomous)\n");
50 }
51 if (data.PosEdge(ControlBit::kEnabled)) {
52 LOG(INFO, "PosEdge(kEnabled)\n");
53 }
54 if (data.NegEdge(ControlBit::kEnabled)) {
55 LOG(INFO, "NegEdge(kEnabled)\n");
56 }
Brian Silvermanc25bc892013-05-09 19:09:34 -070057 }
Brian Silvermanba3de7e2013-05-08 16:18:15 -070058
59 RunIteration(data);
60 }
61}
62
63} // namespace input
64} // namespace aos