mirror of https://github.com/nirenjan/libx52.git
Add readjoy to read joystick events from userspace
Also fix a bit of formatting in the joystick driver file.pull/3/head
parent
9ac96dae97
commit
a32cc47097
|
@ -221,6 +221,7 @@ static int to_hex(const char c)
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t set_brightness(struct device *dev, const char *buf,
|
||||
size_t count, u8 target)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
readjoy: readjoy.c
|
||||
gcc -o $@ $<
|
||||
|
||||
all: readjoy
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f readjoy
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/joystick.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct js_event joy_event;
|
||||
int fd;
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s /dev/input/jsX\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (!fd) {
|
||||
fprintf(stderr, "Error: Unable to open %s!\n", argv[1]);
|
||||
return -2;
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
if (read(fd, &joy_event, sizeof(joy_event)) != sizeof(joy_event)) {
|
||||
fprintf(stderr, "Error: Unable to read from joystick!\n");
|
||||
return -3;
|
||||
} else {
|
||||
if (joy_event.type & JS_EVENT_INIT) {
|
||||
printf("*");
|
||||
}
|
||||
|
||||
if (joy_event.type & JS_EVENT_BUTTON) {
|
||||
printf("B");
|
||||
} else if (joy_event.type & JS_EVENT_AXIS) {
|
||||
printf("A");
|
||||
} else {
|
||||
printf("?");
|
||||
}
|
||||
printf("%u: %d\n", joy_event.number, joy_event.value);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue