EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
XBox.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_HAL_XBOX_HPP_
2 #define ORG_EEROS_HAL_XBOX_HPP_
3 
4 #include <string>
5 #include <functional>
6 #include <linux/joystick.h>
7 #include <eeros/hal/Input.hpp>
8 #include <eeros/core/Thread.hpp>
9 
10 #define XBOX_BUTTON_COUNT (8)
11 #define XBOX_AXIS_COUNT (8)
12 
13 namespace eeros {
14  namespace hal {
15  struct XBoxState {
20 
21  static const double axis_max;
22  };
23 
24  struct XBoxController {
25  struct Axis {
26  static constexpr int LX = 0;
27  static constexpr int LY = 1;
28  static constexpr int LT = 2;
29  static constexpr int RY = 3;
30  static constexpr int RX = 4;
31  static constexpr int RT = 5;
32  static constexpr int CX = 6;
33  static constexpr int CY = 7;
34  };
35  struct Button {
36  static constexpr int A = 0;
37  static constexpr int B = 1;
38  static constexpr int X = 2;
39  static constexpr int Y = 3;
40  static constexpr int LB = 4;
41  static constexpr int RB = 5;
42  static constexpr int back = 6;
43  static constexpr int start = 7;
44  };
45  };
46 
47  class XBox : public eeros::Thread{
48  public:
49  explicit XBox(std::string dev);
50  ~XBox();
51  virtual void on_event(std::function<void(struct js_event)> action);
52  virtual void on_button(std::function<void(int, bool)> action);
53  virtual void on_axis(std::function<void(int, double)> action);
54  virtual std::string name();
55 
58 
59  private:
60  virtual void run();
61  virtual bool open(const char* device);
62  virtual void close();
63  int fd;
64  bool running;
65  std::function<void(struct js_event)> event_action;
66  std::function<void(int, bool)> button_action;
67  std::function<void(int, double)> axis_action;
69  };
70  }
71 }
72 
73 #endif // ORG_EEROS_HAL_XBOX_HPP_
#define XBOX_AXIS_COUNT
Definition: XBox.hpp:11
Definition: XBox.hpp:25
Definition: XBox.hpp:15
static const double axis_max
Definition: XBox.hpp:21
XBoxState current
Definition: XBox.hpp:57
Definition: Config.hpp:14
Definition: XBox.hpp:35
bool button_up[XBOX_BUTTON_COUNT]
Definition: XBox.hpp:18
Definition: XBox.hpp:24
bool button_down[XBOX_BUTTON_COUNT]
Definition: XBox.hpp:19
Definition: Thread.hpp:12
XBoxState last
Definition: XBox.hpp:56
double axis[XBOX_AXIS_COUNT]
Definition: XBox.hpp:16
volatile bool running
Definition: Executor.cpp:25
bool button_state[XBOX_BUTTON_COUNT]
Definition: XBox.hpp:17
#define XBOX_BUTTON_COUNT
Definition: XBox.hpp:10
Definition: XBox.hpp:47