20 #include <linux/input.h> 73 #define EVIO_LBIT (8*sizeof(long)) 74 #define EVIO_BITSTOLONGS(bnr) (((bnr) + EVIO_LBIT - 1) / EVIO_LBIT) 77 #define EVIO_TESTBIT(bnr, array) \ 78 (((1UL << ((bnr)&(EVIO_LBIT-1))) & ((array)[(bnr)/EVIO_LBIT]))!=0) 84 struct input_id devid;
90 struct input_event inpev;
99 if ((fd = open(devpath, O_RDONLY, 0)) < 0) {
100 printf(
"Failed to open device '%s' ...\n", devpath);
104 evp = (
evio *) calloc(1,
sizeof(
evio));
109 printf(
"Error) EVIOCGNAME ...\n");
114 if ((ioctl(evp->
fd, EVIOCGBIT(0,
sizeof(evp->
evbit)), evp->
evbit) < 0) ||
115 (ioctl(evp->
fd, EVIOCGBIT(EV_KEY,
sizeof(evp->
keybit)), evp->
keybit) < 0) ||
116 (ioctl(evp->
fd, EVIOCGBIT(EV_ABS,
sizeof(evp->
absbit)), evp->
absbit) < 0) ||
117 (ioctl(evp->
fd, EVIOCGBIT(EV_REL,
sizeof(evp->
relbit)), evp->
relbit) < 0)) {
118 printf(
"Error) ioctl() calls ...\n");
160 if (ioctl(evp->
fd, EVIOCGID, &evp->
devid) < 0) {
161 printf(
"Error) EVIOCGID ...\n");
166 fcntl(evp->
fd, F_SETFL, O_NONBLOCK);
220 }
while (bcnt == -1 && errno == EINTR);
223 switch (evp->
inpev.type) {
225 printf(
"EV_SYN: '%s' %ld:%ld s \n",
226 (evp->
inpev.code == SYN_REPORT) ?
"SYN_REPORT" :
"Other",
227 evp->
inpev.time.tv_sec, evp->
inpev.time.tv_usec);
232 printf(
"EV_KEY[0x%04x]: %d \n",
238 printf(
"EV_ABS[%d]: %d \n",
244 printf(
"EV_REL[%d]: %d \n",
250 printf(
"EV_MSC[%d] \n", evp->
inpev.code);
255 printf(
"Unknown event type: 0x%x \n",
256 evp->
inpev.code - REL_X);
263 if (errno != EAGAIN) {
264 printf(
"Error reading events from input device\n");
274 int evio_print_absinfo(
void) {
275 printf(
"REL_X Values = { %d, %d, %d, %d, %d }\n",
276 absinfo.value, absinfo.minimum, absinfo.maximum,
277 absinfo.fuzz, absinfo.flat);
283 int val = absinfo->value - absinfo->minimum;
284 int range = absinfo->maximum - absinfo->minimum;
285 return 2.0f * ((float) val / (
float) range) - 1.0f;
301 float *abs_x2,
float *abs_y2,
int *buttons) {
302 struct input_absinfo absinfo;
307 memset(&absinfo, 0,
sizeof(absinfo));
315 if (ioctl(evp->
fd, EVIOCGABS(ABS_X), &absinfo) < 0) {
321 if (ioctl(evp->
fd, EVIOCGABS(ABS_Y), &absinfo) < 0) {
347 if (ioctl(evp->
fd, EVIOCGABS(xax2), &absinfo) < 0) {
353 if (ioctl(evp->
fd, EVIOCGABS(yax2), &absinfo) < 0) {
380 for (i=0; i<31; i++) {
401 struct input_absinfo absinfo;
413 memset(&absinfo, 0,
sizeof(absinfo));
415 if (ioctl(evp->fd, EVIOCGABS(REL_X), &absinfo) < 0) {
419 *rel_x = absinfo.value;
421 if (ioctl(evp->fd, EVIOCGABS(REL_Y), &absinfo) < 0) {
425 *rel_y = absinfo.value;
427 if (ioctl(evp->fd, EVIOCGABS(REL_Z), &absinfo) < 0) {
431 *rel_z = absinfo.value;
434 if (ioctl(evp->fd, EVIOCGABS(
REL_RX), &absinfo) < 0) {
438 *rel_rx = absinfo.value;
440 if (ioctl(evp->fd, EVIOCGABS(
REL_RY), &absinfo) < 0) {
444 *rel_ry = absinfo.value;
446 if (ioctl(evp->fd, EVIOCGABS(
REL_RZ), &absinfo) < 0) {
450 *rel_rz = absinfo.value;
454 if (ioctl(evp->fd, EVIOCGBIT(EV_KEY,
sizeof(evp->keybit)), evp->keybit) >= 0) {
456 for (i=0; i<31; i++) {
472 printf(
"Unrecognized device type\n");
476 if (evp->
devid.bustype == BUS_USB) {
478 }
else if (evp->
devid.bustype == BUS_BLUETOOTH) {
479 busstr =
"Bluetooth";
480 }
else if (evp->
devid.bustype == BUS_PCI) {
487 printf(
"Joystick at '%s':\n", evp->
devpath);
489 printf(
"Spaceball at '%s':\n", evp->
devpath);
492 printf(
" '%s'\n", evp->
devname);
493 printf(
" bus: %s ", busstr);
494 printf(
" vendor: 0x%x", evp->
devid.vendor);
495 printf(
" product: 0x%x \n", evp->
devid.product);
502 #if defined(TEST_MAIN) 504 int dev_valid(
const char *devpath) {
512 printf(
"Unrecognized device type: '%s' (%s)\n", evp->
devpath, evp->
devname);
520 int dev_test(
const char *devpath) {
526 printf(
"Unrecognized device type: '%s' (%s)\n", evp->
devpath, evp->
devname);
531 printf(
"Running loop test on device '%s'...\n", devpath);
536 float ax1, ay1, ax2, ay2;
539 printf(
"Joystick: %5.2f %5.2f %5.2f %5.2f 0x%08x \r",
540 ax1, ay1, ax2, ay2, buttons);
551 int tx, ty, tz, rx, ry, rz, buttons;
553 &rx, &ry, &rz, &buttons)) {
554 printf(
"Spaceball: %6d %6d %6d %6d %6d %6d 0x%08x \r",
555 tx, ty, tz, rx, ry, rz, buttons);
574 printf(
"End of event report\n");
584 int main(
int argc,
char **argv) {
588 for (i=0; i<40; i++) {
590 sprintf(devpath,
"/dev/input/event%d", i);
595 for (i=1; i<argc; i++) {
596 char *devpath=argv[i];
int evio_get_button_status(evio_handle v, int evbtn, int btnflag)
#define EVENTIO_GAMEPAD_X
int evio_read_events(evio_handle v)
#define EVIO_TESTBIT(bnr, array)
unsigned long absbit[EVIO_BITSTOLONGS(ABS_MAX)]
unsigned long keybit[EVIO_BITSTOLONGS(KEY_MAX)]
#define EVIO_BITSTOLONGS(bnr)
#define EVENTIO_GAMEPAD_B
int main(int argc, char **argv)
#define EVENTIO_GAMEPAD_A
float evio_absinfo2float(struct input_absinfo *absinfo)
int evio_dev_joystick(evio_handle v)
int evio_get_joystick_status(evio_handle v, float *abs_x1, float *abs_y1, float *abs_x2, float *abs_y2, int *buttons)
evio_handle evio_open(const char *devpath)
int evio_dev_spaceball(evio_handle v)
unsigned long relbit[EVIO_BITSTOLONGS(REL_MAX)]
#define EVENTIO_JOYSTICK_LOGIF310
int evio_close(evio_handle v)
#define EVENTIO_JOYSTICK_STD
unsigned long keystate[EVIO_BITSTOLONGS(KEY_MAX)]
#define EVENTIO_SPACEBALL_STD
int evio_print_devinfo(evio_handle v)
#define EVENTIO_JOYSTICK_NYKO
unsigned long evbit[EVIO_BITSTOLONGS(EV_MAX)]
#define EVENTIO_GAMEPAD_Y
int evio_dev_recognized(evio_handle v)
int evio_get_spaceball_status(evio_handle v, int *rel_x, int *rel_y, int *rel_z, int *rel_rx, int *rel_ry, int *rel_rz, int *buttons)