-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouchscreen.cpp
More file actions
45 lines (39 loc) · 1.48 KB
/
touchscreen.cpp
File metadata and controls
45 lines (39 loc) · 1.48 KB
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
44
45
#include "touchscreen.h"
Touchscreen::Touchscreen(int width, int heigth)
{
dev = libevdev_new();
struct input_absinfo absInfoX = {
0, 0, width, 0, 0, 0
}, absInfoY = {
0, 0, heigth, 0, 0, 0
};
libevdev_set_name(dev, "waveshare");
libevdev_enable_event_type(dev, EV_KEY);
libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, 0);
libevdev_enable_event_type(dev, EV_ABS);
libevdev_enable_event_code(dev, EV_ABS, ABS_MT_POSITION_X, &absInfoX);
libevdev_enable_event_code(dev, EV_ABS, ABS_MT_POSITION_Y, &absInfoY);
libevdev_uinput_create_from_device(dev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uinput);
}
Touchscreen::~Touchscreen()
{
libevdev_uinput_destroy(uinput);
libevdev_free(dev);
}
void Touchscreen::handleMessage(const Message &message)
{
if(message.pressed()){
auto points = message.points();
libevdev_uinput_write_event(uinput, EV_KEY, BTN_TOUCH, 1);
for(auto& p : points){
libevdev_uinput_write_event(uinput, EV_ABS, ABS_MT_POSITION_X, p.x);
libevdev_uinput_write_event(uinput, EV_ABS, ABS_MT_POSITION_Y, p.y);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_MT_REPORT, 0);
}
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
}else{
libevdev_uinput_write_event(uinput, EV_KEY, BTN_TOUCH, 0);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_MT_REPORT, 0);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
}
}