switched from fitpc/atom to prime/linux
Also removed a few old things that had nothing reasonable to be changed
to.
diff --git a/aos/prime/input/input.gyp b/aos/prime/input/input.gyp
new file mode 100644
index 0000000..8aba065
--- /dev/null
+++ b/aos/prime/input/input.gyp
@@ -0,0 +1,21 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'joystick_input',
+ 'type': 'static_library',
+ 'sources': [
+ 'joystick_input.cc',
+ ],
+ 'dependencies': [
+ '<(AOS)/common/input/input.gyp:driver_station_data',
+ '<(AOS)/common/messages/messages.gyp:aos_queues',
+ '<(AOS)/common/network/network.gyp:socket',
+ '<(EXTERNALS):WPILib-NetworkRobotValues',
+ '<(AOS)/build/aos.gyp:logging',
+ ],
+ 'export_dependent_settings': [
+ '<(AOS)/common/input/input.gyp:driver_station_data',
+ ],
+ },
+ ],
+}
diff --git a/aos/prime/input/joystick_input.cc b/aos/prime/input/joystick_input.cc
new file mode 100644
index 0000000..6439dbc
--- /dev/null
+++ b/aos/prime/input/joystick_input.cc
@@ -0,0 +1,92 @@
+#include "aos/prime/input/joystick_input.h"
+
+#include <string.h>
+
+#include "aos/externals/WPILib/WPILib/NetworkRobot/NetworkRobotValues.h"
+
+#include "aos/common/network_port.h"
+#include "aos/common/network/ReceiveSocket.h"
+#include "aos/common/messages/RobotState.q.h"
+#include "aos/common/logging/logging.h"
+
+namespace aos {
+namespace input {
+
+void JoystickInput::Run() {
+ ReceiveSocket sock(NetworkPort::kDS);
+
+ NetworkRobotJoysticks joysticks;
+ char buffer[sizeof(joysticks) + ::buffers::kOverhead];
+ driver_station::Data data;
+
+ while (true) {
+ int received = sock.Receive(buffer, sizeof(buffer));
+ if (received == -1) {
+ LOG(WARNING, "socket receive failed with %d: %s\n",
+ errno, strerror(errno));
+ continue;
+ }
+
+ if (!joysticks.DeserializeFrom(buffer, received)) {
+ LOG(WARNING, "deserializing data from %zd bytes failed\n", received);
+ continue;
+ }
+
+ if (!robot_state.MakeWithBuilder()
+ .enabled(joysticks.control.enabled())
+ .autonomous(joysticks.control.autonomous())
+ .team_id(joysticks.team_number)
+ .Send()) {
+ LOG(WARNING, "sending robot_state failed\n");
+ } else {
+ LOG(DEBUG, "sent robot_state{%s, %s, %hu}\n",
+ joysticks.control.enabled() ? "enabled" : "disabled",
+ joysticks.control.autonomous() ? "auto" : "not auto",
+ joysticks.team_number);
+ }
+
+ data.Update(joysticks);
+
+ {
+ using driver_station::JoystickFeature;
+ using driver_station::ButtonLocation;
+ for (int joystick = 1; joystick <= JoystickFeature::kJoysticks;
+ ++joystick) {
+ for (int button = 1; button <= ButtonLocation::kButtons; ++button) {
+ ButtonLocation location(joystick, button);
+ if (data.PosEdge(location)) {
+ LOG(INFO, "PosEdge(%d, %d)\n", joystick, button);
+ }
+ if (data.NegEdge(location)) {
+ LOG(INFO, "NegEdge(%d, %d)\n", joystick, button);
+ }
+ }
+ }
+
+ using driver_station::ControlBit;
+ if (data.PosEdge(ControlBit::kFmsAttached)) {
+ LOG(INFO, "PosEdge(kFmsAttached)\n");
+ }
+ if (data.NegEdge(ControlBit::kFmsAttached)) {
+ LOG(INFO, "NegEdge(kFmsAttached)\n");
+ }
+ if (data.PosEdge(ControlBit::kAutonomous)) {
+ LOG(INFO, "PosEdge(kAutonomous)\n");
+ }
+ if (data.NegEdge(ControlBit::kAutonomous)) {
+ LOG(INFO, "NegEdge(kAutonomous)\n");
+ }
+ if (data.PosEdge(ControlBit::kEnabled)) {
+ LOG(INFO, "PosEdge(kEnabled)\n");
+ }
+ if (data.NegEdge(ControlBit::kEnabled)) {
+ LOG(INFO, "NegEdge(kEnabled)\n");
+ }
+ }
+
+ RunIteration(data);
+ }
+}
+
+} // namespace input
+} // namespace aos
diff --git a/aos/prime/input/joystick_input.h b/aos/prime/input/joystick_input.h
new file mode 100644
index 0000000..17fdbbe
--- /dev/null
+++ b/aos/prime/input/joystick_input.h
@@ -0,0 +1,26 @@
+#ifndef AOS_LINUX_CODE_INPUT_JOYSTICKS_INPUT_H_
+#define AOS_LINUX_CODE_INPUT_JOYSTICKS_INPUT_H_
+
+#include "aos/common/input/driver_station_data.h"
+
+namespace aos {
+namespace input {
+
+// A class for handling joystick packet values.
+// It will call RunIteration each time a new packet is received.
+//
+// This class automatically handles updating ::aos::robot_state and logging (at
+// INFO) button edges.
+class JoystickInput {
+ public:
+ void Run();
+
+ private:
+ // Subclasses should do whatever they want with data here.
+ virtual void RunIteration(const driver_station::Data &data) = 0;
+};
+
+} // namespace input
+} // namespace aos
+
+#endif // AOS_LINUX_CODE_INPUT_JOYSTICKS_INPUT_H_