EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Joystick.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_HAL_JOYSTICK_HPP_
2 #define ORG_EEROS_HAL_JOYSTICK_HPP_
3 
4 #include <string>
5 #include <functional>
6 #include <linux/joystick.h>
7 
8 #define JOYSTICK_BUTTON_COUNT (16)
9 #define JOYSTICK_AXIS_COUNT (8)
10 
11 namespace eeros {
12  namespace hal {
14  {
19 
20  static const double axis_max;
21  };
22 
23  class Joystick
24  {
25  public:
26  explicit Joystick();
27  ~Joystick();
28  virtual bool open(const char* device);
29  virtual void close();
30  virtual void loop();
31  virtual void on_event(std::function<void(struct js_event)> action);
32  virtual void on_button(std::function<void(int, bool)> action);
33  virtual void on_axis(std::function<void(int, double)> action);
34 
35  virtual std::string name();
36 
39 
40  private:
41  int fd;
42  std::function<void(struct js_event)> event_action;
43  std::function<void(int, bool)> button_action;
44  std::function<void(int, double)> axis_action;
45  };
46  }
47 }
48 
49 #endif // ORG_EEROS_HAL_JOYSTICK_HPP_
Definition: Joystick.hpp:13
virtual void on_axis(std::function< void(int, double)> action)
Definition: Joystick.cpp:72
#define JOYSTICK_AXIS_COUNT
Definition: Joystick.hpp:9
double axis[JOYSTICK_AXIS_COUNT]
Definition: Joystick.hpp:15
virtual void on_event(std::function< void(struct js_event)> action)
Definition: Joystick.cpp:62
virtual void close()
Definition: Joystick.cpp:41
virtual bool open(const char *device)
Definition: Joystick.cpp:35
bool button_state[JOYSTICK_BUTTON_COUNT]
Definition: Joystick.hpp:16
virtual void loop()
Definition: Joystick.cpp:78
virtual void on_button(std::function< void(int, bool)> action)
Definition: Joystick.cpp:67
~Joystick()
Definition: Joystick.cpp:30
bool button_down[JOYSTICK_BUTTON_COUNT]
Definition: Joystick.hpp:18
Joystick()
Definition: Joystick.cpp:11
Definition: Joystick.hpp:23
virtual std::string name()
Definition: Joystick.cpp:46
JoystickState current
Definition: Joystick.hpp:38
static const double axis_max
Definition: Joystick.hpp:20
JoystickState last
Definition: Joystick.hpp:37
#define JOYSTICK_BUTTON_COUNT
Definition: Joystick.hpp:8
bool button_up[JOYSTICK_BUTTON_COUNT]
Definition: Joystick.hpp:17