blob: 364929a8c4aa5a0fce219639646ca64628026d93 [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"
9
10namespace frc971 {
11namespace wpilib {
12
13void JoystickSender::operator()() {
14 DriverStation *ds = DriverStation::GetInstance();
Brian Silvermanbd925f92014-12-31 14:28:06 -080015 ::aos::SetCurrentThreadName("DSReader");
Brian Silvermanda45b6c2014-12-28 11:36:50 -080016 uint16_t team_id = ::aos::network::GetTeamNumber();
17
Brian Silvermanbd925f92014-12-31 14:28:06 -080018 ::aos::SetCurrentThreadRealtimePriority(29);
19
Brian Silvermanda45b6c2014-12-28 11:36:50 -080020 while (run_) {
21 ds->WaitForData();
22 auto new_state = ::aos::robot_state.MakeMessage();
23
24 new_state->test_mode = ds->IsAutonomous();
25 new_state->fms_attached = ds->IsFMSAttached();
26 new_state->enabled = ds->IsEnabled();
27 new_state->autonomous = ds->IsAutonomous();
28 new_state->team_id = team_id;
29 new_state->fake = false;
30
31 for (int i = 0; i < 4; ++i) {
32 new_state->joysticks[i].buttons = 0;
33 for (int button = 0; button < 16; ++button) {
34 new_state->joysticks[i].buttons |= ds->GetStickButton(i, button + 1)
35 << button;
36 }
37 for (int j = 0; j < 4; ++j) {
38 new_state->joysticks[i].axis[j] = ds->GetStickAxis(i, j);
39 }
40 }
41 LOG_STRUCT(DEBUG, "robot_state", *new_state);
42
43 if (!new_state.Send()) {
44 LOG(WARNING, "sending robot_state failed\n");
45 }
46 }
47}
48
49} // namespace wpilib
50} // namespace frc971