-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrumble-test.c
83 lines (68 loc) · 1.66 KB
/
rumble-test.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* very simple test tool for vibrator strength
*
* License: LGPL 2.1
* Copyright: Collabora Ltd.
* Author: Sebastian Reichel <[email protected]>
*
*/
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv) {
const char * device_file_name;
unsigned int strength;
struct input_event event = {
.type = EV_FF,
};
struct ff_effect effect = {
.type = FF_RUMBLE,
.id = -1,
.u.rumble.strong_magnitude = 0x0000,
.u.rumble.weak_magnitude = 0x0000,
.replay.length = 5000,
.replay.delay = 1000,
};
int fd, err;
if (argc != 3) {
fprintf(stderr, "%s /dev/input/event<num> <strength>\n", argv[0]);
return 1;
}
device_file_name = argv[1];
strength = strtol(argv[2], NULL, 0);
fd = open(device_file_name, O_RDWR);
if (fd == -1) {
fprintf(stderr, "could not open %s: %d\n", device_file_name, errno);
return 1;
}
effect.u.rumble.strong_magnitude = strength;
printf("Upload rumble effect... ");
fflush(stdout);
err = ioctl(fd, EVIOCSFF, &effect);
if (err == -1) {
printf("failed\n");
fprintf(stderr, "ioctl error: %d\n", errno);
return 1;
}
printf("id=%d\n", effect.id);
event.code = effect.id;
event.value = 1;
err = write(fd, (const void*) &event, sizeof(event));
if (err == -1) {
fprintf(stderr, "failed to start rumble effect (err=%d)\n", errno);
return 1;
}
sleep(5);
event.value = 0;
err = write(fd, (const void*) &event, sizeof(event));
if (err == -1) {
fprintf(stderr, "failed to stop rumble effect (err=%d)\n", errno);
return 1;
}
return 0;
}