-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoystick-gateway.h
43 lines (33 loc) · 1 KB
/
joystick-gateway.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef JSEVENT_H
#define JSEVENT_H
#include "JoystickEvent.h"
#include <atomic>
#include <string>
namespace DoJoyStick {
/**
* @brief The JoystickGateway class
* Reads Joystick events and propagates through EventHandler
*/
class JoystickGateway {
public:
explicit JoystickGateway(std::string joyStickDeviceName = "/dev/input/js0");
virtual ~JoystickGateway();
typedef void (*clickHandler)(JoystickEvent, void *data);
void js_event_loop();
void setEventHandler(clickHandler handler, void *data = 0);
static void jsdiag(js_event js);
void stop() { shouldRun = false; }
private:
// TODO allow to set parameters
int holdTime = 700;
int dblTime = 250;
const char *deviceName;
clickHandler _handler = 0;
void *_handlerData = 0;
int joy_fd = -1;
std::atomic<bool> shouldRun = true;
bool open_joystick();
int close_joystick();
};
}// namespace DoJoyStick
#endif