You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
61 lines
1.2 KiB
13 years ago
|
#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>
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
int fd;
|
||
|
int res = 0;
|
||
|
char buf[256];
|
||
|
|
||
|
if (argc != 5) {
|
||
|
printf("set_led takes 4 arguments\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/* Open the Device with non-blocking reads. In real life,
|
||
|
don't use a hard coded path; use libudev instead. */
|
||
|
fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK);
|
||
|
|
||
|
if (fd < 0) {
|
||
|
perror("Unable to open device");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
memset(buf, 0x0, sizeof(buf));
|
||
|
|
||
|
|
||
|
|
||
|
if (argv[1][0] == '1') buf[2] = 0xff;
|
||
|
if (argv[1][1] == '1') buf[3] = 0xff;
|
||
|
if (argv[1][2] == '1') buf[2] = 0xff;
|
||
|
if (argv[1][3] == '1') buf[5] = 0xff;
|
||
|
|
||
|
/* Send a Report to the Device */
|
||
|
buf[0] = 0x00; /* Report Number */
|
||
|
buf[1] = 0x00; /* Report ID */
|
||
|
/*buf[2] = 0x00; Buzzer 1 */
|
||
|
/*buf[3] = 0x00; Buzzer 2 */
|
||
|
/*buf[4] = 0x00; Buzzer 3 */
|
||
|
/*buf[5] = 0x00; Buzzer 4 */
|
||
|
res = write(fd, buf, 6);
|
||
|
if (res < 0) {
|
||
|
printf("Error: %d\n", errno);
|
||
|
perror("write");
|
||
|
} else {
|
||
|
/*printf("write() wrote %d bytes\n", res); */
|
||
|
}
|
||
|
|
||
|
close(fd);
|
||
|
return 0;
|
||
|
}
|