Revision: 10112 http://pure-data.svn.sourceforge.net/pure-data/?rev=10112&view=rev Author: eighthave Date: 2008-06-26 13:27:43 -0700 (Thu, 26 Jun 2008)
Log Message: ----------- - fixed "evdev EVIOCGABS ioctl: Invalid argument" error by only trying the ioctl(EVIOCGABS) on existing elements. This means it is a pretty substantial change in how the code works, but it was necessary to fix the bug. Plus it should make it use a lot less memory and CPU. I just hope it doesn't break anything.
Modified Paths: -------------- branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c
Modified: branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd =================================================================== --- branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd 2008-06-26 20:23:24 UTC (rev 10111) +++ branches/pd-extended/v0-40/externals/hcs/hid/doc/hid-help.pd 2008-06-26 20:27:43 UTC (rev 10112) @@ -1,4 +1,4 @@ -#N canvas 202 51 715 555 10; +#N canvas 366 51 715 555 10; #X floatatom 27 439 5 0 0 0 - - -; #X floatatom 83 439 5 0 0 0 - - -; #X floatatom 63 395 6 0 0 0 - - -;
Modified: branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c =================================================================== --- branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c 2008-06-26 20:23:24 UTC (rev 10111) +++ branches/pd-extended/v0-40/externals/hcs/hid/hid_linux.c 2008-06-26 20:27:43 UTC (rev 10112) @@ -30,8 +30,8 @@ #define NBITS(x) (((x)/BITS_PER_LONG)+1) #define LONG(x) ((x)/BITS_PER_LONG) #define test_bit(bit, array) ((array[LONG(bit)] >> (bit%BITS_PER_LONG)) & 1) +#define ISBITSET(x,i) ((x[i>>3] & (1<<(i&7)))!=0)
- /* * from an email from Vojtech: * @@ -297,34 +297,39 @@ t_hid_element *new_element = NULL; t_int i, j;
+ if( x->x_fd < 0 ) + return; + element_count[x->x_device_number] = 0; - if( x->x_fd ) + + /* get bitmask representing supported elements (axes, keys, etc.) */ + memset(element_bitmask, 0, sizeof(element_bitmask)); + if( ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), element_bitmask[0]) < 0 ) + perror("[hid] error: evdev ioctl: element_bitmask"); + memset(abs_bitmask, 0, sizeof(abs_bitmask)); + if( ioctl(x->x_fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0 ) + perror("[hid] error: evdev ioctl: abs_bitmask"); + for( i = 1; i < EV_MAX; i++ ) { - /* get bitmask representing supported elements (axes, keys, etc.) */ - memset(element_bitmask, 0, sizeof(element_bitmask)); - if( ioctl(x->x_fd, EVIOCGBIT(0, EV_MAX), element_bitmask[0]) < 0 ) - perror("[hid] error: evdev ioctl: element_bitmask"); - memset(abs_bitmask, 0, sizeof(abs_bitmask)); - if( ioctl(x->x_fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0 ) - perror("[hid] error: evdev ioctl: abs_bitmask"); - for( i = 1; i < EV_MAX; i++ ) + if(test_bit(i, element_bitmask[0])) { - if(test_bit(i, element_bitmask[0])) + /* get bitmask representing supported elements */ + ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), element_bitmask[i]); + /* cycle through all possible event codes (axes, keys, etc.) + * testing to see which are supported. + */ + for(j = 0; j < KEY_MAX; j++) { - /* get bitmask representing supported button types */ - ioctl(x->x_fd, EVIOCGBIT(i, KEY_MAX), element_bitmask[i]); - /* cycle through all possible event codes (axes, keys, etc.) - * testing to see which are supported. - * i = i j = j - */ - for(j = 0; j < KEY_MAX; j++) + if(test_bit(j, element_bitmask[i])) { - new_element = getbytes(sizeof(t_hid_element)); - if( (i == EV_ABS) && (test_bit(j, abs_bitmask)) ) + new_element = getbytes(sizeof(t_hid_element)); + if( (i == EV_ABS) && (j < ABS_MAX) && (test_bit(j, abs_bitmask)) ) { - /* this means that the bit is set in the axes list */ - if(ioctl(x->x_fd, EVIOCGABS(j), &abs_features)) - perror("evdev EVIOCGABS ioctl"); + if(ioctl(x->x_fd, EVIOCGABS(j), &abs_features) < 0) + { + post("[hid]: EVIOCGABS ioctl error for element: 0x%03x", j, j); + perror("[hid]: EVIOCGABS ioctl error:"); + } new_element->min = abs_features.minimum; new_element->max = abs_features.maximum; } @@ -333,29 +338,26 @@ new_element->min = 0; new_element->max = 0; } - if(test_bit(j, element_bitmask[i])) + new_element->linux_type = i; /* the int from linux/input.h */ + new_element->type = gensym(ev[i] ? ev[i] : "?"); /* the symbol */ + new_element->linux_code = j; + if((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) { - new_element->linux_type = i; /* the int from linux/input.h */ - new_element->type = gensym(ev[i] ? ev[i] : "?"); /* the symbol */ - new_element->linux_code = j; - if((i == EV_KEY) && (j >= BTN_MISC) && (j < KEY_OK) ) - { - new_element->name = hid_convert_linux_buttons_to_numbers(j); - } - else - { - new_element->name = gensym(event_names[i][j] ? event_names[i][j] : "?"); - } - if( i == EV_REL ) - new_element->relative = 1; - else - new_element->relative = 0; - element[x->x_device_number][element_count[x->x_device_number]] = new_element; - ++element_count[x->x_device_number]; + new_element->name = hid_convert_linux_buttons_to_numbers(j); } + else + { + new_element->name = gensym(event_names[i][j] ? event_names[i][j] : "?"); + } + if( i == EV_REL ) + new_element->relative = 1; + else + new_element->relative = 0; + element[x->x_device_number][element_count[x->x_device_number]] = new_element; + ++element_count[x->x_device_number]; } - } - } + } + } } }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.