blob: de5de04fdacc9e6a24b3050e8c634953e2631eb9 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#ifndef AOS_INPUT_JOYSTICK_INPUT_H_
2#define AOS_INPUT_JOYSTICK_INPUT_H_
3
4#include "FRCComm.h"
5
6namespace aos {
7
8// Class for implementing atom code that reads the joystick values from the
9// cRIO.
10// Designed for a subclass that implements RunIteration to be instantiated and
11// Runed.
12class JoystickInput {
13 private:
14 uint16_t buttons[4], old_buttons[4];
15 inline uint16_t MASK(int button) {
16 return 1 << ((button > 8) ? (button - 9) : (button + 7));
17 }
18 void SetupButtons();
19 protected:
20 FRCCommonControlData control_data_;
21
22 // Constants that retrieve data when used with joystick 0.
23 static const int ENABLED = 13;
24 static const int AUTONOMOUS = 14;
25 static const int FMS_ATTACHED = 15;
26 bool Pressed(int stick, int button) {
27 return buttons[stick] & MASK(button);
28 }
29 bool PosEdge(int stick, int button) {
30 return !(old_buttons[stick] & MASK(button)) && (buttons[stick] & MASK(button));
31 }
32 bool NegEdge(int stick, int button) {
33 return (old_buttons[stick] & MASK(button)) && !(buttons[stick] & MASK(button));
34 }
35
36 virtual void RunIteration() = 0;
37 public:
38 // Enters an infinite loop that reads values and calls RunIteration.
39 void Run();
40};
41
42} // namespace aos
43
44#endif
45