/* Simple joystick test program. Mappings on my Genius “MaxFighter * F-16U” joystick: * * - Left-right axis is axis 0, from -26688 at the left to +12836 at * the right, with zero at rest position; quantized to units of 337 * or 338, giving about 120 distinct positions. * - Front-back axis is axis 1, from -21958 full forward to +12836 * full back, with zero at rest position; quantized to units of 337 * or 338, giving about 100 distinct positions. * - Thumbwheel is axis 2, from -32767 full forward to +12836 full * back. There is some dead space at each end of travel. Seems to * be quantized to units of 337 or 338, giving about 140 distinct * positions. * - Trigger is button 0. * - Thumb button on stem is button 1. * - When not in autorepeat mode (TA/TB), the C thumb button is button * 2 and the D thumb button is button 3. * * As the docs say, the buttons have value 1 when depressed, 0 when * released. * * Note that, even today, the joystick driver checks to see if you’re * doing a 12-byte read() in order to see if it should give you the * two-axis, two-button joystick API used before Linux 1.0 with 8-bit * resolution. */ #include #include #include #include /* From Documentation/input/joystick-api.txt.gz. This duplicates * linux/joystick.h. */ struct js_event { uint32_t time; int16_t value; uint8_t type, number; }; int main(int argc, char **argv) { if (argc == 1) { fprintf(stderr, "usage: %s /dev/input/js0 (or similar\n", argv[0]); return 1; } int fd = open(argv[1], O_RDONLY); if (fd < 0) { perror(argv[1]); return 2; } for (;;) { struct js_event e; read(fd, &e, sizeof e); int type = e.type & 0x7f; printf("%10d %6d %d (%s) on axis/button %d\n", e.time, e.value, e.type, type == 1 ? "button" : type == 2 ? "axis" : "???", e.number); } return 0; }