blob: 41609edd171242be8dc2c753e5530e470dfdce86 [file] [log] [blame]
Brian Silvermanba3de7e2013-05-08 16:18:15 -07001#ifndef AOS_COMMON_INPUT_DRIVER_STATION_DATA_H_
2#define AOS_COMMON_INPUT_DRIVER_STATION_DATA_H_
3
4// This file defines several types to support nicely looking at the data
5// received from the driver's station.
6
7#include <memory>
8
9#include "aos/externals/WPILib/WPILib/NetworkRobot/NetworkRobotValues.h"
10
11namespace aos {
12namespace input {
13namespace driver_station {
14
15// Represents a feature of a joystick (a button or an axis).
16// All indices are 1-based.
17class JoystickFeature {
18 public:
19 JoystickFeature(int joystick, int number)
20 : joystick_(joystick), number_(number) {}
21
22 // Which joystick number this is (1-based).
23 int joystick() const { return joystick_; }
24 // Which feature on joystick() this is (1-based).
25 int number() const { return number_; }
26
27 private:
28 const int joystick_, number_;
29};
30
31// Represents the location of a button.
32// Use Data to actually get the value.
33// Safe for static initialization.
34class ButtonLocation : public JoystickFeature {
35 public:
36 ButtonLocation(int joystick, int number)
37 : JoystickFeature(joystick, number) {}
38};
39
40// Represents various bits of control information that the DS sends.
41// Use Data to actually get the value.
42enum class ControlBit {
43 kTestMode, kFmsAttached, kAutonomous, kEnabled
44};
45
46// Represents a single axis of a joystick.
47// Use Data to actually get the value.
48// Safe for static initialization.
49class JoystickAxis : public JoystickFeature {
50 public:
51 JoystickAxis(int joystick, int number)
52 : JoystickFeature(joystick, number) {}
53};
54
55class Data {
56 public:
57 // Initializes the data to all buttons and control bits off and all joysticks
58 // at 0.
59 Data();
60
61 // Updates the current information with a new set of values.
62 void Update(const NetworkRobotJoysticks &new_values);
63
64 bool IsPressed(ButtonLocation location) const;
65 bool PosEdge(ButtonLocation location) const;
66 bool NegEdge(ButtonLocation location) const;
67
68 bool GetControlBit(ControlBit bit) const;
69 bool PosEdge(ControlBit bit) const;
70 bool NegEdge(ControlBit bit) const;
71
72 // Returns the value in the range [-1.0, 1.0].
73 float GetAxis(JoystickAxis axis) const;
74
75 private:
76 NetworkRobotJoysticks current_values_, old_values_;
77};
78
79} // namespace driver_station
80} // namespace input
81} // namespace aos
82
83#endif // AOS_COMMON_INPUT_DRIVER_STATION_DATA_H_