blob: 313ad0a69e86841f9efbe24410c825684e83697d [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.
briansb642ffe2013-03-13 00:42:30 +000012// TODO(brians): rewrite this with OO buttons/fms state etc
brians343bc112013-02-10 01:53:46 +000013class JoystickInput {
14 private:
15 uint16_t buttons[4], old_buttons[4];
16 inline uint16_t MASK(int button) {
17 return 1 << ((button > 8) ? (button - 9) : (button + 7));
18 }
19 void SetupButtons();
20 protected:
21 FRCCommonControlData control_data_;
22
23 // Constants that retrieve data when used with joystick 0.
24 static const int ENABLED = 13;
25 static const int AUTONOMOUS = 14;
26 static const int FMS_ATTACHED = 15;
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