so, I'm back to trying to get the hid object work on my machine. the "hid" object will recognize my device which is enumerated as a joystick and mapped to /dev/input/event2
I can open the device fine with "hid". It prints out
[hid] opened device 2 (/dev/input/event2): Microchip Technology Inc.
I then start the "hid" object with a "start" message and it prints out the following and then segfaults:
[hid] polling started
I've narrowed it down with gdb to be crashing due to a call to strcpy in the function hid_get_events(t_hid *x) in hid_linux.c
strcpy(hid_code, event_names[hid_input_event.type][hid_input_event.code]);
any ideas how to fix this?
-august.
I think I've narrowed it down further.
I can see that it crashes when the event.typ is 3 and the event.code is greater than 41. 41 is the default max that is generated for the ev_abs enumeration by the make-arrays-from-input.h.pl script. however, it seems like my usb device is sending abs event.codes that are greater than 41 in the enumeration.
so, to keep it from crashing I put the follwoing code into hid_linux.c
if (hid_input_event.code < 41) { strcpy(hid_code, event_names[hid_input_event.type][hid_input_event.code] ); }
this keeps it from crashing, but I can only retrieve valueds from 6 of my 10 axises of my USB device.
could it be that make-arrays-from-input.h.pl is generating the wrong amount of ev_abs?
in input_arrays.c I see:
int ev_abs_total = 41; /* # of elements in array */ char *ev_abs[41] = { "abs_x","abs_y","abs_z","abs_rx","abs_ry","abs_rz", "abs_throttle","abs_rudder","abs_wheel","abs_gas","abs_brake",NULL, NULL,NULL,NULL,NULL,"abs_hat0x","abs_hat0y", "abs_hat1x","abs_hat1y","abs_hat2x","abs_hat2y","abs_hat3x","abs_hat3y", "abs_pressure","abs_distance","abs_tilt_x","abs_tilt_y","abs_tool_width",NULL, NULL,NULL,"abs_volume",NULL,NULL,NULL,
....and I crash at the strcpy call if hid_input_event.type = 3 (ev_abs) AND hid_input_event.code > 41.
suggestions? thanks in advance -august.
Wow, thanks for debugging this, I'll definitely fix it now. This
illustrates a common problem with HID devices: lots of non-standard HID
implementations. There can be a total of this many axes:
#define ABS_MAX 0x3f
But the input_arrays.c array only goes to 0x28 since that is the last
one that is named in the linux system. It looks like your device is
using non-standard axes names/numbers. This used to happen to me when
I used my Force Feedback joystick with linux and the force feedback was
not detected, so I might be the linux system misrecognizing your device
as well.
.hc
On Jun 4, 2005, at 10:10 PM, august wrote:
I think I've narrowed it down further.
I can see that it crashes when the event.typ is 3 and the event.code is greater than 41. 41 is the default max that is generated for the
ev_abs enumeration by the make-arrays-from-input.h.pl script. however, it
seems like my usb device is sending abs event.codes that are greater than 41
in the enumeration.so, to keep it from crashing I put the follwoing code into hid_linux.c
if (hid_input_event.code < 41) { strcpy(hid_code,
event_names[hid_input_event.type][hid_input_event.code] ); }this keeps it from crashing, but I can only retrieve valueds from 6 of my 10 axises of my USB device.
could it be that make-arrays-from-input.h.pl is generating the wrong amount of ev_abs?
in input_arrays.c I see:
int ev_abs_total = 41; /* # of elements in array */ char *ev_abs[41] = { "abs_x","abs_y","abs_z","abs_rx","abs_ry","abs_rz", "abs_throttle","abs_rudder","abs_wheel","abs_gas","abs_brake",NULL, NULL,NULL,NULL,NULL,"abs_hat0x","abs_hat0y", "abs_hat1x","abs_hat1y","abs_hat2x","abs_hat2y","abs_hat3x","abs_hat3y" , "abs_pressure","abs_distance","abs_tilt_x","abs_tilt_y","abs_tool_width ",NULL, NULL,NULL,"abs_volume",NULL,NULL,NULL,
....and I crash at the strcpy call if hid_input_event.type = 3 (ev_abs) AND hid_input_event.code > 41.
suggestions? thanks in advance -august.
PD-list@iem.at mailing list UNSUBSCRIBE and account-management ->
http://lists.puredata.info/listinfo/pd-list
"[W]e have invented the technology to eliminate scarcity, but we are
deliberately throwing it
away to benefit those who profit from scarcity."
-John Gilmore
'nother thing. it seems to crash whenever it gets a null reference from ev_abs...so here is the else statement I have in hid_linux.c for that code chunk:
else { if (event_names[hid_input_event.type][hid_input_event.code] == NULL) { return 0; } if (hid_input_event.code < 41) { strcpy(hid_code, event_names[hid_input_event.type][hid_input_event.code] ); } }
another question: is there any benefit to using the HID descriptor names such as abs_x, abs_y, etc.....or would it be possible to just use numbers? it seems to me that the usb devices are pretty random in what controls they assign to what descriptor. and, AFAIK, the "hi" object in MAX just outputs lists with numbers for the initial control descriptors.
-august.
On Jun 5, 2005, at 2:46 PM, august wrote:
'nother thing. it seems to crash whenever it gets a null reference
from ev_abs...so here is the else statement I have in hid_linux.c for that
code chunk:else { if (event_names[hid_input_event.type][hid_input_event.code] == NULL)
{ return 0; } if (hid_input_event.code < 41) { strcpy(hid_code,
event_names[hid_input_event.type][hid_input_event.code] ); } }
Instead I am actually going to make fake names, like abs_41, rel_16,
etc. using the event type and code number. Then those strange HID
elements will still be usable with the [hid] object, though not the
[joystick], [mouse], etc. objects (abstractions).
another question: is there any benefit to using the HID descriptor
names such as abs_x, abs_y, etc.....or would it be possible to just use
numbers? it seems to me that the usb devices are pretty random in what controls they assign to what descriptor. and, AFAIK, the "hi" object in MAX
just outputs lists with numbers for the initial control descriptors.
There are two key reasons why [hid] has the event scheme the way it is
as compared to Max's [hi]. First, [hi] numbers the elements
sequentially as it finds them. That means your patch is tied to that
exact make/model of joystick, rather than working with any joystick.
Second, I could have used standardized numbers, instead of names, ie
code 1 always = x-axis. But I thought I'd try using descriptive names
so that you would not need to consult a lookup table in order to use
the data from [hid]. It does use more CPU power, but I think its worth
it. If thru experience, it proves not to be worth it, I'll change the
names to numbers.
If you are interested in know more about my thinking behind the design
of this, check out my thesis paper:
http://at.or.at/hans/misc/itp/thesis/
.hc
"The arc of history bends towards justice."
Dr.
Martin Luther King, Jr.