blob: 9f85c31998d39b098a1c485b2bbed3843ccad32c [file] [log] [blame]
Brian Silvermanda45b6c2014-12-28 11:36:50 -08001#include "frc971/wpilib/joystick_sender.h"
2
3#include "aos/common/messages/robot_state.q.h"
4#include "aos/linux_code/init.h"
5#include "aos/common/network/team_number.h"
6#include "aos/common/logging/queue_logging.h"
7
8#include "DriverStation.h"
Brian Silverman6f7d5fe2015-01-01 15:45:41 -08009#include "HAL/HAL.hpp"
Brian Silvermanda45b6c2014-12-28 11:36:50 -080010
11namespace frc971 {
12namespace wpilib {
13
14void JoystickSender::operator()() {
15 DriverStation *ds = DriverStation::GetInstance();
Brian Silvermanbd925f92014-12-31 14:28:06 -080016 ::aos::SetCurrentThreadName("DSReader");
Brian Silvermanda45b6c2014-12-28 11:36:50 -080017 uint16_t team_id = ::aos::network::GetTeamNumber();
18
Brian Silvermanbd925f92014-12-31 14:28:06 -080019 ::aos::SetCurrentThreadRealtimePriority(29);
20
Brian Silvermanda45b6c2014-12-28 11:36:50 -080021 while (run_) {
22 ds->WaitForData();
23 auto new_state = ::aos::robot_state.MakeMessage();
24
Brian Silverman6f7d5fe2015-01-01 15:45:41 -080025 HALControlWord control_word;
26 HALGetControlWord(&control_word);
27 new_state->test_mode = control_word.test;
28 new_state->fms_attached = control_word.fmsAttached;
29 new_state->enabled = control_word.enabled;
30 new_state->autonomous = control_word.autonomous;
Brian Silvermanda45b6c2014-12-28 11:36:50 -080031 new_state->team_id = team_id;
32 new_state->fake = false;
33
34 for (int i = 0; i < 4; ++i) {
35 new_state->joysticks[i].buttons = 0;
36 for (int button = 0; button < 16; ++button) {
37 new_state->joysticks[i].buttons |= ds->GetStickButton(i, button + 1)
38 << button;
39 }
40 for (int j = 0; j < 4; ++j) {
41 new_state->joysticks[i].axis[j] = ds->GetStickAxis(i, j);
42 }
43 }
44 LOG_STRUCT(DEBUG, "robot_state", *new_state);
45
46 if (!new_state.Send()) {
47 LOG(WARNING, "sending robot_state failed\n");
48 }
49 }
50}
51
52} // namespace wpilib
53} // namespace frc971