diff --git a/driver/x52joy.c b/driver/x52joy.c index 770cc7e..8756b66 100644 --- a/driver/x52joy.c +++ b/driver/x52joy.c @@ -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) { diff --git a/user/Makefile b/user/Makefile new file mode 100644 index 0000000..eabbba3 --- /dev/null +++ b/user/Makefile @@ -0,0 +1,10 @@ + +readjoy: readjoy.c + gcc -o $@ $< + +all: readjoy + +.PHONY: clean +clean: + rm -f readjoy + diff --git a/user/readjoy.c b/user/readjoy.c new file mode 100644 index 0000000..2540f84 --- /dev/null +++ b/user/readjoy.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +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; +}