Update of /cvsroot/pure-data/externals/hcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2426
Modified Files: usbhid.c usbhid-help.pd Log Message: lots of string bullshit, reports name now
Index: usbhid-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/usbhid-help.pd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** usbhid-help.pd 18 May 2006 12:00:47 -0000 1.1 --- usbhid-help.pd 18 May 2006 16:00:46 -0000 1.2 *************** *** 1,3 **** ! #N canvas 338 93 593 471 10; #X obj 111 373 usbhid; #X msg 125 14 bang; --- 1,3 ---- ! #N canvas 338 93 597 475 10; #X obj 111 373 usbhid; #X msg 125 14 bang; *************** *** 11,18 **** #X text 233 258 GARBAGE FOR TESTING; #X msg 250 292 set read 1 30 word 1 31 1 38; - #X msg 205 182 set read 1 30 1 31 12 38; #X msg 198 142 print; #X msg 177 78 open 1149 16392; #X text 298 78 Gravis/Destroyer Tiltpad; #X connect 0 0 4 0; #X connect 0 1 5 0; --- 11,18 ---- #X text 233 258 GARBAGE FOR TESTING; #X msg 250 292 set read 1 30 word 1 31 1 38; #X msg 198 142 print; #X msg 177 78 open 1149 16392; #X text 298 78 Gravis/Destroyer Tiltpad; + #X msg 205 182 set read 1 30 1 31; #X connect 0 0 4 0; #X connect 0 1 5 0; *************** *** 24,26 **** #X connect 11 0 0 0; #X connect 12 0 0 0; ! #X connect 13 0 0 0; --- 24,26 ---- #X connect 11 0 0 0; #X connect 12 0 0 0; ! #X connect 14 0 0 0;
Index: usbhid.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/usbhid.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** usbhid.c 18 May 2006 12:00:47 -0000 1.1 --- usbhid.c 18 May 2006 16:00:46 -0000 1.2 *************** *** 1,5 **** /* --------------------------------------------------------------------------*/ /* */ ! /* Pd interface to the USB HID API using libhid */ /* Written by Hans-Christoph Steiner hans@at.or.at */ /* */ --- 1,5 ---- /* --------------------------------------------------------------------------*/ /* */ ! /* Pd interface to the USB HID API using libhid, which is built on libusb */ /* Written by Hans-Christoph Steiner hans@at.or.at */ /* */ *************** *** 35,39 **** */
! /* NOTE: included from libusb/usbi.h. UGLY, i know, but so is libusb! */ struct usb_dev_handle { int fd; --- 35,41 ---- */
! /* NOTE: included from libusb/usbi.h. UGLY, i know, but so is libusb! ! * this struct doesn't seem to be defined in usb.h, only prototyped ! */ struct usb_dev_handle { int fd; *************** *** 57,61 **** t_int usbhid_instance_count;
! char *hid_id[32]; /* FIXME: 32 devices MAX */ t_int hid_id_count;
--- 59,64 ---- t_int usbhid_instance_count;
! #define HID_ID_MAX 32 ! char *hid_id[HID_ID_MAX]; /* FIXME: 32 devices MAX */ t_int hid_id_count;
*************** *** 87,92 ****
- - /*------------------------------------------------------------------------------ * LOCAL DEFINES --- 90,93 ---- *************** *** 101,108 **** --- 102,113 ---- static t_class *usbhid_class;
+ /* for USB strings */ + #define STRING_BUFFER_LENGTH 256 + #define SEND_PACKET_LENGTH 1 #define RECEIVE_PACKET_LENGTH 6 #define PATH_LENGTH 3
+ /*------------------------------------------------------------------------------ * SUPPORT FUNCTIONS *************** *** 114,118 **** */ static bool device_iterator (struct usb_dev_handle const* usbdev, void* custom, ! unsigned int len) { bool ret = false; --- 119,123 ---- */ static bool device_iterator (struct usb_dev_handle const* usbdev, void* custom, ! unsigned int length) { bool ret = false; *************** *** 122,126 **** /* only here to prevent the unused warning */ /* TODO remove */ ! len = *((unsigned long*)custom);
/* Obtain the device's full path */ --- 127,131 ---- /* only here to prevent the unused warning */ /* TODO remove */ ! length = *((unsigned long*)custom);
/* Obtain the device's full path */ *************** *** 139,147 **** hid_id[i] = (char *) malloc(strlen(usbdev->device->filename) + strlen(usbdev->bus->dirname) ); sprintf(hid_id[i], "%s/%s", usbdev->bus->dirname, usbdev->device->filename); - post("bus %s device %s: %d %d", - usbdev->bus->dirname, - usbdev->device->filename, - usbdev->device->descriptor.idVendor, - usbdev->device->descriptor.idProduct); } else /* device already seen */ --- 144,147 ---- *************** *** 154,160 **** --- 154,172 ---- && usbdev->device->config && usbdev->device->config->interface->altsetting->bInterfaceClass == USB_CLASS_HID) + { + + post("bus %s device %s: %d %d", + usbdev->bus->dirname, + usbdev->device->filename, + usbdev->device->descriptor.idVendor, + usbdev->device->descriptor.idProduct); ret = true; + } + else + { ret = false; + } +
return ret; *************** *** 165,175 **** * serial number. */ ! /* static bool match_serial_number(struct usb_dev_handle* usbdev, void* custom, unsigned int len) */ /* { */ /* bool ret; */ ! /* char* buffer = (char*)malloc(len); */ /* usb_get_string_simple(usbdev, usb_device(usbdev)->descriptor.iSerialNumber, */ ! /* buffer, len); */ ! /* ret = strncmp(buffer, (char*)custom, len) == 0; */ /* free(buffer); */ /* return ret; */ --- 177,187 ---- * serial number. */ ! /* static bool match_serial_number(struct usb_dev_handle* usbdev, void* custom, unsigned int length) */ /* { */ /* bool ret; */ ! /* char* buffer = (char*)malloc(length); */ /* usb_get_string_simple(usbdev, usb_device(usbdev)->descriptor.iSerialNumber, */ ! /* buffer, length); */ ! /* ret = strncmp(buffer, (char*)custom, length) == 0; */ /* free(buffer); */ /* return ret; */ *************** *** 178,186 ****
/* -------------------------------------------------------------------------- */ ! /* static HIDInterface* get_device_by_number(t_int device_number) */ /* { */ ! /* HIDInterface* return_hid; */ ! /* return return_hid; */ /* } */
--- 190,201 ----
/* -------------------------------------------------------------------------- */ ! /* static bool get_device_by_number(struct usb_dev_handle* usbdev, */ ! /* void* custom, */ ! /* unsigned int length) */ /* { */ ! /* bool ret; */ ! ! /* return ret; */ /* } */
*************** *** 209,212 **** --- 224,285 ----
+ static t_int get_device_string(HIDInterface *hidif, char *device_string) + { + int length; + t_int ret = 0; + char buffer[STRING_BUFFER_LENGTH]; + + if ( !hid_is_opened(hidif) ) + return(0); + + if (hidif->device->descriptor.iManufacturer) { + length = usb_get_string_simple(hidif->dev_handle, + hidif->device->descriptor.iManufacturer, + buffer, + STRING_BUFFER_LENGTH); + if (length > 0) + { + strncat(device_string, buffer, STRING_BUFFER_LENGTH - strlen(device_string)); + strncat(device_string, " ",1); + ret = 1; + } + else + { + post("(unable to fetch manufacturer string)"); + } + } + + if (hidif->device->descriptor.iProduct) { + length = usb_get_string_simple(hidif->dev_handle, + hidif->device->descriptor.iProduct, + buffer, + STRING_BUFFER_LENGTH); + if (length > 0) + { + strncat(device_string, buffer, STRING_BUFFER_LENGTH - strlen(device_string)); + strncat(device_string, " ",1); + ret = 1; + } + else + { + post("(unable to fetch product string)"); + } + } + + if (hidif->device->descriptor.iSerialNumber) { + length = usb_get_string_simple(hidif->dev_handle, + hidif->device->descriptor.iSerialNumber, + buffer, + STRING_BUFFER_LENGTH); + if (length > 0) + strncat(device_string, buffer, STRING_BUFFER_LENGTH - strlen(device_string)); + else + post("(unable to fetch product string)"); + } + + return ret; + } + + /*------------------------------------------------------------------------------ * IMPLEMENTATION *************** *** 217,220 **** --- 290,294 ---- { DEBUG(post("usbhid_open");); + char string_buffer[STRING_BUFFER_LENGTH]; HIDInterfaceMatcher matcher = { (unsigned short)vendor_id, *************** *** 227,231 **** { x->x_hid_return = hid_force_open(x->x_hidinterface, 0, &matcher, 3); ! if (x->x_hid_return != HID_RET_SUCCESS) { error("[usbhid] hid_force_open failed with return code %d\n", x->x_hid_return); } --- 301,311 ---- { x->x_hid_return = hid_force_open(x->x_hidinterface, 0, &matcher, 3); ! if (x->x_hid_return == HID_RET_SUCCESS) ! { ! if (get_device_string(x->x_hidinterface,string_buffer)) ! post("[usbhid]: opened %s",string_buffer); ! } ! else ! { error("[usbhid] hid_force_open failed with return code %d\n", x->x_hid_return); } *************** *** 240,244 **** DEBUG(post("usbhid_read");); /* int const PATH_IN[PATH_LENGTH] = { 0xffa00001, 0xffa00002, 0xffa10003 }; */ ! int const PATH_OUT[PATH_LENGTH] = { 0x00010030, 0x00010031, 0x00010038 };
char packet[RECEIVE_PACKET_LENGTH]; --- 320,324 ---- DEBUG(post("usbhid_read");); /* int const PATH_IN[PATH_LENGTH] = { 0xffa00001, 0xffa00002, 0xffa10003 }; */ ! int const PATH_OUT[2] = { 0x00010030, 0x00010031 };
char packet[RECEIVE_PACKET_LENGTH]; *************** *** 252,256 **** x->x_hid_return = hid_get_input_report(x->x_hidinterface, PATH_OUT, ! PATH_LENGTH, packet, RECEIVE_PACKET_LENGTH); --- 332,336 ---- x->x_hid_return = hid_get_input_report(x->x_hidinterface, PATH_OUT, ! 2, packet, RECEIVE_PACKET_LENGTH); *************** *** 258,266 **** error("[usbhid] hid_get_input_report failed with return code %d\n", x->x_hid_return); ! /* } */ }
/* -------------------------------------------------------------------------- */ /* set the HID packet for which elements to read */ --- 338,347 ---- error("[usbhid] hid_get_input_report failed with return code %d\n", x->x_hid_return); ! /* } */ }
+ /* -------------------------------------------------------------------------- */ /* set the HID packet for which elements to read */ *************** *** 328,331 **** --- 409,414 ---- { DEBUG(post("usbhid_close");); + t_int ret; + char string_buffer[STRING_BUFFER_LENGTH];
/* just to be safe, stop it first */ *************** *** 334,342 **** if ( hid_is_opened(x->x_hidinterface) ) { x->x_hid_return = hid_close(x->x_hidinterface); if (x->x_hid_return == HID_RET_SUCCESS) ! post("[usbhid] closed device %d",x->x_device_number); else error("[usbhid] could not close %d, error #%d",x->x_device_number,x->x_hid_return); } } --- 417,430 ---- if ( hid_is_opened(x->x_hidinterface) ) { + ret = get_device_string(x->x_hidinterface,string_buffer); x->x_hid_return = hid_close(x->x_hidinterface); if (x->x_hid_return == HID_RET_SUCCESS) ! { ! if (ret) post("[usbhid]: closed %s",string_buffer); ! } else + { error("[usbhid] could not close %d, error #%d",x->x_device_number,x->x_hid_return); + } } } *************** *** 348,352 **** DEBUG(post("usbhid_print");); t_int i; ! t_atom event_data[3];
for ( i = 0 ; ( hid_id[i] != NULL ) ; i++ ) --- 436,441 ---- DEBUG(post("usbhid_print");); t_int i; ! char string_buffer[STRING_BUFFER_LENGTH]; ! /* t_atom event_data[3]; */
for ( i = 0 ; ( hid_id[i] != NULL ) ; i++ ) *************** *** 355,358 **** --- 444,450 ---- post("hid_id[%d]: %s",i,hid_id[i]); } + if (get_device_string(x->x_hidinterface,string_buffer)) + post("%s is currently open",string_buffer); + /* SETSYMBOL(event_data, gensym(type)); /* type */ */ /* SETSYMBOL(event_data + 1, gensym(code)); /* code */ */ *************** *** 413,424 **** /* hid_write_library_config(stdout); */ ! /* hid_set_debug(HID_DEBUG_NOTRACES); */ ! // hid_set_debug(HID_DEBUG_NONE); ! /* hid_set_debug(HID_DEBUG_ALL); */ ! hid_set_debug_stream(stderr); hid_set_usb_debug(0); /* data init */ ! for (i = 0 ; i < 32 ; i++) hid_id[i] = NULL;
--- 505,516 ---- /* hid_write_library_config(stdout); */ ! //hid_set_debug(HID_DEBUG_NONE); ! hid_set_debug(HID_DEBUG_NOTRACES); ! //hid_set_debug(HID_DEBUG_ALL); ! hid_set_debug_stream(stdout); hid_set_usb_debug(0); /* data init */ ! for (i = 0 ; i < HID_ID_MAX ; i++) hid_id[i] = NULL;