blob: c92d567f02ebedc1f9872d6e92933adf5d7d8d94 [file] [log] [blame]
James Kuszmaul7077d342021-06-09 20:23:58 -07001#include "frc971/input/joystick_input.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07002
3#include <string.h>
James Kuszmaul7077d342021-06-09 20:23:58 -07004
Austin Schuhb58ceb62017-02-05 14:21:57 -08005#include <atomic>
Brian Silvermanba3de7e2013-05-08 16:18:15 -07006
John Park33858a32018-09-28 23:05:48 -07007#include "aos/logging/logging.h"
James Kuszmaul7077d342021-06-09 20:23:58 -07008#include "frc971/input/robot_state_generated.h"
Brian Silvermanba3de7e2013-05-08 16:18:15 -07009
James Kuszmaul7077d342021-06-09 20:23:58 -070010namespace frc971 {
Brian Silvermanba3de7e2013-05-08 16:18:15 -070011namespace input {
12
Alex Perrycb7da4b2019-08-28 19:35:56 -070013void JoystickInput::HandleData(const ::aos::JoystickState *joystick_state) {
Austin Schuh3e45c752019-02-02 12:19:11 -080014 data_.Update(joystick_state);
15
Alex Perrycb7da4b2019-08-28 19:35:56 -070016 mode_ = static_cast<int>(joystick_state->switch_left()) |
17 (static_cast<int>(joystick_state->scale_left()) << 1);
Austin Schuh3e45c752019-02-02 12:19:11 -080018
19 {
Austin Schuh3e45c752019-02-02 12:19:11 -080020 using driver_station::ButtonLocation;
James Kuszmaul7077d342021-06-09 20:23:58 -070021 using driver_station::JoystickFeature;
Austin Schuh3e45c752019-02-02 12:19:11 -080022 for (int joystick = 1; joystick <= JoystickFeature::kJoysticks;
23 ++joystick) {
24 for (int button = 1; button <= ButtonLocation::kButtons; ++button) {
25 ButtonLocation location(joystick, button);
26 if (data_.PosEdge(location)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070027 AOS_LOG(INFO, "PosEdge(%d, %d)\n", joystick, button);
Austin Schuh3e45c752019-02-02 12:19:11 -080028 }
29 if (data_.NegEdge(location)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070030 AOS_LOG(INFO, "NegEdge(%d, %d)\n", joystick, button);
Austin Schuh3e45c752019-02-02 12:19:11 -080031 }
32 }
33 if (data_.GetPOV(joystick) != data_.GetOldPOV(joystick)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070034 AOS_LOG(INFO, "POV %d %d->%d\n", joystick, data_.GetOldPOV(joystick),
35 data_.GetPOV(joystick));
Austin Schuh3e45c752019-02-02 12:19:11 -080036 }
37 }
38 }
39 {
40 using driver_station::ControlBit;
41 if (data_.PosEdge(ControlBit::kFmsAttached)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070042 AOS_LOG(INFO, "PosEdge(kFmsAttached)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080043 }
44 if (data_.NegEdge(ControlBit::kFmsAttached)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070045 AOS_LOG(INFO, "NegEdge(kFmsAttached)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080046 }
47 if (data_.PosEdge(ControlBit::kAutonomous)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070048 AOS_LOG(INFO, "PosEdge(kAutonomous)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080049 }
50 if (data_.NegEdge(ControlBit::kAutonomous)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070051 AOS_LOG(INFO, "NegEdge(kAutonomous)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080052 }
53 if (data_.PosEdge(ControlBit::kEnabled)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070054 AOS_LOG(INFO, "PosEdge(kEnabled)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080055 }
56 if (data_.NegEdge(ControlBit::kEnabled)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070057 AOS_LOG(INFO, "NegEdge(kEnabled)\n");
Austin Schuh3e45c752019-02-02 12:19:11 -080058 }
59 }
60
61 RunIteration(data_);
Brian Silvermanba3de7e2013-05-08 16:18:15 -070062}
63
64} // namespace input
James Kuszmaul7077d342021-06-09 20:23:58 -070065} // namespace frc971