-
Notifications
You must be signed in to change notification settings - Fork 4
/
mp709.c
74 lines (60 loc) · 1.19 KB
/
mp709.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
#include <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
typedef int bool;
#define true 1
#define false 0
int main(int argc, char **argv) {
int fd, res;
char buf[256];
char dev_name[32];
bool has_device = false;
struct stat st;
int i;
for (i=0; i<9; ++i) {
sprintf(dev_name, "/dev/hidraw%i", i);
if (stat(dev_name, &st))
break;
fd = open(dev_name, O_RDWR|O_NONBLOCK);
if (fd < 0) {
perror("Unable to open device");
continue;
};
res = ioctl(fd, HIDIOCGRAWNAME(256), buf);
if (res < 0)
perror("Cannot get device name");
else
printf("/dev/hidraw%i: %s\n", i, buf);
if (strstr(buf, "MP709") != NULL) {
has_device = true;
break;
} else {
close(fd);
};
};
if (!has_device) {
printf("No device found\n");
return 1;
};
buf[0] = 0xE7;
if (argc > 1 && strcasecmp(argv[1], "on") == 0)
buf[1] = 0x0;
else
buf[1] = 0x19;
res = write(fd, buf, 2);
if (res < 0) {
printf("Error: %d\n", errno);
perror("write");
};
close(fd);
return 0;
}