blob: ddb0388bdcad852a64b1743bcfeea6b97f395306 [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;
brians6591d582013-03-03 05:31:53 +000026 static const int TEST_MODE = 16;
brians343bc112013-02-10 01:53:46 +000027 bool Pressed(int stick, int button) {
28 return buttons[stick] & MASK(button);
29 }
30 bool PosEdge(int stick, int button) {
31 return !(old_buttons[stick] & MASK(button)) && (buttons[stick] & MASK(button));
32 }
33 bool NegEdge(int stick, int button) {
34 return (old_buttons[stick] & MASK(button)) && !(buttons[stick] & MASK(button));
35 }
36
37 virtual void RunIteration() = 0;
38 public:
39 // Enters an infinite loop that reads values and calls RunIteration.
40 void Run();
41};
42
43} // namespace aos
44
45#endif
46