Update of /cvsroot/pure-data/externals/hcs/hid In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9582
Modified Files: TODO hid.c hid.h hid_darwin.c hid_linux.c hid_windows.c Log Message: added some status reporting, and got all the different methods for opening working on Mac OS X; time to fix GNU/Linux now...
Index: hid.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** hid.c 27 May 2006 16:41:59 -0000 1.23 --- hid.c 27 May 2006 23:12:51 -0000 1.24 *************** *** 86,89 **** --- 86,113 ---- }
+ + static void output_status(t_hid *x, t_symbol *selector, t_float output_value) + { + t_atom *output_atom = getbytes(sizeof(t_atom)); + SETFLOAT(output_atom, output_value); + outlet_anything( x->x_status_outlet, selector, 1, output_atom); + freebytes(output_atom,sizeof(t_atom)); + } + + static void output_open_status(t_hid *x) + { + output_status(x, gensym("open"), x->x_device_open); + } + + static void output_device_number(t_hid *x) + { + output_status(x, gensym("device"), x->x_device_number); + } + + static void output_poll_time(t_hid *x) + { + output_status(x, gensym("poll"), x->x_delay); + } + static unsigned int name_to_usage(char *usage_name) { // output usagepage << 16 + usage *************** *** 134,138 **** else if(argc == 2) { - post("two arg"); first_argument = atom_getsymbolarg(0,argc,argv); second_argument = atom_getsymbolarg(1,argc,argv); --- 158,161 ---- *************** *** 149,153 **** else { /* two symbols means idVendor and idProduct in hex */ - post("idVendor and idProduct"); vendor_id = (unsigned short) strtol(first_argument->s_name, NULL, 16); product_id = (unsigned short) strtol(second_argument->s_name, NULL, 16); --- 172,175 ---- *************** *** 158,169 **** }
! ! void hid_output_event(t_hid *x, char *type, char *code, t_float value) { t_atom event_data[3]; ! SETSYMBOL(event_data, gensym(type)); /* type */ ! SETSYMBOL(event_data + 1, gensym(code)); /* code */ ! SETFLOAT(event_data + 2, value); /* value */
outlet_anything(x->x_data_outlet,atom_gensym(event_data),2,event_data+1); --- 180,190 ---- }
! void hid_output_event(t_hid *x, t_symbol *type, t_symbol *code, t_float value) { t_atom event_data[3]; ! SETSYMBOL(event_data, type); ! SETSYMBOL(event_data + 1, code); ! SETFLOAT(event_data + 2, value);
outlet_anything(x->x_data_outlet,atom_gensym(event_data),2,event_data+1); *************** *** 273,281 **** } } /* restore the polling state so that when I [tgl] is used to start/stop [hid], * the [tgl]'s state will continue to accurately reflect [hid]'s state */ if(started) hid_set_from_float(x,x->x_delay); ! debug_print(LOG_DEBUG,"[hid] done device# to %d",device_number); }
--- 294,305 ---- } } + else debug_print(LOG_WARNING,"[hid] device does not exist"); /* restore the polling state so that when I [tgl] is used to start/stop [hid], * the [tgl]'s state will continue to accurately reflect [hid]'s state */ if(started) hid_set_from_float(x,x->x_delay); ! debug_print(LOG_DEBUG,"[hid] set device# to %d",device_number); ! output_open_status(x); ! output_device_number(x); }
*************** *** 315,318 **** --- 339,350 ---- */
+ static void hid_info(t_hid *x) + { + output_open_status(x); + output_device_number(x); + output_poll_time(x); + hid_platform_specific_info(x); + } + static void hid_float(t_hid* x, t_floatarg f) { *************** *** 374,378 **** /* create anything outlet used for HID data */ x->x_data_outlet = outlet_new(&x->x_obj, 0); ! x->x_device_name_outlet = outlet_new(&x->x_obj, 0);
x->x_device_number = get_device_number_from_arguments(argc, argv); --- 406,410 ---- /* create anything outlet used for HID data */ x->x_data_outlet = outlet_new(&x->x_obj, 0); ! x->x_status_outlet = outlet_new(&x->x_obj, 0);
x->x_device_number = get_device_number_from_arguments(argc, argv);
Index: hid_windows.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_windows.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** hid_windows.c 27 May 2006 00:57:15 -0000 1.2 --- hid_windows.c 27 May 2006 23:12:51 -0000 1.3 *************** *** 180,185 **** strcat ( device_name, " "); strcat( device_name, product ); ! // outlet_anything( x->x_device_name_outlet, gensym( device_name ),0,NULL ); ! outlet_symbol( x->x_device_name_outlet, gensym( device_name ) ); }
--- 180,185 ---- strcat ( device_name, " "); strcat( device_name, product ); ! // outlet_anything( x->x_status_outlet, gensym( device_name ),0,NULL ); ! outlet_symbol( x->x_status_outlet, gensym( device_name ) ); }
Index: hid.h =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** hid.h 27 May 2006 16:41:59 -0000 1.21 --- hid.h 27 May 2006 23:12:51 -0000 1.22 *************** *** 35,39 **** t_int x_device_open; t_outlet *x_data_outlet; ! t_outlet *x_device_name_outlet; } t_hid;
--- 35,39 ---- t_int x_device_open; t_outlet *x_data_outlet; ! t_outlet *x_status_outlet; } t_hid;
*************** *** 65,69 **** void debug_print(t_int debug_level, const char *fmt, ...); void debug_error(t_hid *x, t_int debug_level, const char *fmt, ...); ! void hid_output_event(t_hid *x, char *type, char *code, t_float value);
/* generic, cross-platform functions implemented in a separate file for each --- 65,69 ---- void debug_print(t_int debug_level, const char *fmt, ...); void debug_error(t_hid *x, t_int debug_level, const char *fmt, ...); ! void hid_output_event(t_hid *x, t_symbol *type, t_symbol *code, t_float value);
/* generic, cross-platform functions implemented in a separate file for each *************** *** 74,83 **** void hid_build_device_list(void); t_int hid_get_events(t_hid *x); - void hid_info(t_hid* x); /* output device info on the status outlet */ void hid_print(t_hid* x); /* print info to the console */ void hid_platform_specific_free(t_hid *x); t_int get_device_number_by_id(unsigned short vendor_id, unsigned short product_id); t_int get_device_number_from_usage_list(t_int device_number, ! unsigned short usage_page, unsigned short usage);
--- 74,84 ---- void hid_build_device_list(void); t_int hid_get_events(t_hid *x); void hid_print(t_hid* x); /* print info to the console */ + void hid_platform_specific_info(t_hid* x); /* device info on the status outlet */ void hid_platform_specific_free(t_hid *x); t_int get_device_number_by_id(unsigned short vendor_id, unsigned short product_id); t_int get_device_number_from_usage_list(t_int device_number, ! unsigned short usage_page, ! unsigned short usage);
Index: hid_darwin.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_darwin.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** hid_darwin.c 27 May 2006 16:41:59 -0000 1.20 --- hid_darwin.c 27 May 2006 23:12:51 -0000 1.21 *************** *** 206,211 **** t_int get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) { ! // TODO: implement! (check usbhid.c) ! return(-1); }
--- 206,237 ---- t_int get_device_number_by_id(unsigned short vendor_id, unsigned short product_id) { ! debug_print(LOG_DEBUG,"get_device_number_from_usage_list"); ! ! pRecDevice pCurrentHIDDevice; ! t_int i; ! t_int return_device_number = -1; ! ! if( !HIDHaveDeviceList() ) hid_build_device_list(); ! ! pCurrentHIDDevice = HIDGetFirstDevice(); ! i = HIDCountDevices(); ! while(pCurrentHIDDevice != NULL) ! { ! --i; ! debug_print(LOG_INFO,"compare 0x%04x == 0x%04x 0x%04x == 0x%04x", ! pCurrentHIDDevice->vendorID, ! vendor_id, ! pCurrentHIDDevice->productID, ! product_id); ! if( (pCurrentHIDDevice->vendorID == vendor_id) && ! (pCurrentHIDDevice->productID == product_id) ) ! { ! return_device_number = i; ! pCurrentHIDDevice = NULL; ! } ! else ! pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); ! } ! return(return_device_number); }
*************** *** 217,221 **** pRecDevice pCurrentHIDDevice; t_int i; ! t_int device_count; t_int total_devices = 0; char cstrDeviceName[MAXPDSTRING]; --- 243,247 ---- pRecDevice pCurrentHIDDevice; t_int i; ! t_int return_device_number = -1; t_int total_devices = 0; char cstrDeviceName[MAXPDSTRING]; *************** *** 223,229 **** if( !HIDHaveDeviceList() ) hid_build_device_list();
- /* TODO: check that this function doesn't return a number that is higher - * than the highest device of this type */ - pCurrentHIDDevice = HIDGetFirstDevice(); while(pCurrentHIDDevice != NULL) --- 249,252 ---- *************** *** 237,245 **** } i = total_devices; ! device_count = HIDCountDevices(); pCurrentHIDDevice = HIDGetFirstDevice(); while( (pCurrentHIDDevice != NULL) && (i > device_number) ) { ! device_count--; if( (pCurrentHIDDevice->usagePage == usage_page) && (pCurrentHIDDevice->usage == usage) ) --- 260,268 ---- } i = total_devices; ! return_device_number = HIDCountDevices(); pCurrentHIDDevice = HIDGetFirstDevice(); while( (pCurrentHIDDevice != NULL) && (i > device_number) ) { ! return_device_number--; if( (pCurrentHIDDevice->usagePage == usage_page) && (pCurrentHIDDevice->usage == usage) ) *************** *** 249,255 **** pCurrentHIDDevice->usage, cstrDeviceName); ! debug_print(LOG_DEBUG,"[hid]: found a %s at %d: %s %s" ,cstrDeviceName, i, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product); --- 272,279 ---- pCurrentHIDDevice->usage, cstrDeviceName); ! debug_print(LOG_DEBUG,"[hid]: found a %s at %d/%d: %s %s" ,cstrDeviceName, i, + total_devices, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product); *************** *** 257,262 **** pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } ! if(device_count < total_devices) ! return(device_count); else return(-1); --- 281,286 ---- pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); } ! if(i < total_devices) ! return(return_device_number); else return(-1); *************** *** 390,416 **** * ============================================================================== */
! void hid_info(t_hid *x) ! { ! t_atom output_atoms[4]; ! ! SETSYMBOL(output_atoms,gensym("open")); ! SETFLOAT(output_atoms + 1, x->x_device_open); ! outlet_anything( x->x_device_name_outlet, gensym( device_name ),0,NULL ); ! } ! ! ! void hid_output_device_name(t_hid *x, char *manufacturer, char *product) { ! char *device_name; ! // t_symbol *device_name_symbol;
! device_name = malloc( strlen(manufacturer) + 1 + strlen(product) + 1 ); ! // device_name = malloc( 7 + strlen(manufacturer) + 1 + strlen(product) + 1 ); ! // strcpy( device_name, "append " ); ! strcat( device_name, manufacturer ); ! strcat ( device_name, " "); ! strcat( device_name, product ); ! // outlet_anything( x->x_device_name_outlet, gensym( device_name ),0,NULL ); ! outlet_symbol( x->x_device_name_outlet, gensym( device_name ) ); }
--- 414,468 ---- * ============================================================================== */
! void hid_platform_specific_info(t_hid *x) { ! pRecDevice pCurrentHIDDevice = NULL; ! char vendor_id_pointer[7]; ! char product_id_pointer[7]; ! t_symbol *output_symbol; ! t_atom *output_atom = getbytes(sizeof(t_atom));
! if(x->x_device_number > -1) ! { ! pCurrentHIDDevice = hid_get_device_by_number(x->x_device_number); ! if(pCurrentHIDDevice != NULL) ! { ! /* product */ ! SETSYMBOL(output_atom, gensym(pCurrentHIDDevice->product)); ! outlet_anything( x->x_status_outlet, gensym("product"), ! 1, output_atom); ! /* manufacturer */ ! SETSYMBOL(output_atom, gensym(pCurrentHIDDevice->manufacturer)); ! outlet_anything( x->x_status_outlet, gensym("manufacturer"), ! 1, output_atom); ! /* serial */ ! if(pCurrentHIDDevice->serial != NULL) ! { ! output_symbol = gensym(pCurrentHIDDevice->serial); ! if( output_symbol != &s_ ) ! { /* the serial is rarely used on USB devices, so test for it */ ! SETSYMBOL(output_atom, output_symbol); ! outlet_anything( x->x_status_outlet, gensym("serial"), ! 1, output_atom); ! } ! } ! /* transport */ ! SETSYMBOL(output_atom, gensym(pCurrentHIDDevice->transport)); ! outlet_anything( x->x_status_outlet, gensym("transport"), ! 1, output_atom); ! /* vendor id */ ! sprintf(vendor_id_pointer,"0x%04x", ! (unsigned int)pCurrentHIDDevice->vendorID); ! SETSYMBOL(output_atom, gensym(vendor_id_pointer)); ! outlet_anything( x->x_status_outlet, gensym("vendorID"), ! 1, output_atom); ! /* product id */ ! sprintf(product_id_pointer,"0x%04x", ! (unsigned int)pCurrentHIDDevice->productID); ! SETSYMBOL(output_atom, gensym(product_id_pointer)); ! outlet_anything( x->x_status_outlet, gensym("productID"), ! 1, output_atom); ! } ! } ! freebytes(output_atom,sizeof(t_atom)); }
*************** *** 606,658 **** case 0: sprintf(code,"abs_hat0y");value = 1; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = 0; break; case 1: sprintf(code,"abs_hat0y");value = 1; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = 1; break; case 2: sprintf(code,"abs_hat0y");value = 0; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = 1; break; case 3: sprintf(code,"abs_hat0y");value = -1; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = 1; break; case 4: sprintf(code,"abs_hat0y");value = -1; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = 0; break; case 5: sprintf(code,"abs_hat0y");value = -1; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = -1; break; case 6: sprintf(code,"abs_hat0y");value = 0; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = -1; break; case 7: sprintf(code,"abs_hat0y");value = 1; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = -1; break; case 8: sprintf(code,"abs_hat0y");value = 0; ! hid_output_event(x,type,code,(t_float)value); sprintf(code,"abs_hat0x");value = 0; break; } ! hid_output_event(x,type,code,(t_float)value); break; default: convertDarwinElementToLinuxTypeCode(pCurrentHIDElement,type,code); ! hid_output_event(x,type,code,(t_float)value); }
--- 658,710 ---- case 0: sprintf(code,"abs_hat0y");value = 1; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = 0; break; case 1: sprintf(code,"abs_hat0y");value = 1; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = 1; break; case 2: sprintf(code,"abs_hat0y");value = 0; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = 1; break; case 3: sprintf(code,"abs_hat0y");value = -1; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = 1; break; case 4: sprintf(code,"abs_hat0y");value = -1; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = 0; break; case 5: sprintf(code,"abs_hat0y");value = -1; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = -1; break; case 6: sprintf(code,"abs_hat0y");value = 0; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = -1; break; case 7: sprintf(code,"abs_hat0y");value = 1; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = -1; break; case 8: sprintf(code,"abs_hat0y");value = 0; ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); sprintf(code,"abs_hat0x");value = 0; break; } ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); break; default: convertDarwinElementToLinuxTypeCode(pCurrentHIDElement,type,code); ! hid_output_event(x,gensym(type),gensym(code),(t_float)value); }
*************** *** 723,733 **** else { ! debug_error(x,"[hid]: device %d is not a valid device\n",device_number); return(1); } ! ! hid_output_device_name( x, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product ); ! ! post("[hid] opened device %d: %s %s", device_number, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product);
--- 775,782 ---- else { ! debug_error(x,LOG_ERR,"[hid]: device %d is not a valid device\n",device_number); return(1); } ! debug_print(LOG_WARNING,"[hid] opened device %d: %s %s", device_number, pCurrentHIDDevice->manufacturer, pCurrentHIDDevice->product);
Index: hid_linux.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_linux.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** hid_linux.c 27 May 2006 00:57:15 -0000 1.15 --- hid_linux.c 27 May 2006 23:12:51 -0000 1.16 *************** *** 390,394 **** } if( hid_code && hid_input_event.type != EV_SYN ) ! hid_output_event(x, ev[hid_input_event.type], hid_code->s_name, (t_float)hid_input_event.value); DEBUG(++event_counter;); --- 390,394 ---- } if( hid_code && hid_input_event.type != EV_SYN ) ! hid_output_event(x, gensym(ev[hid_input_event.type]), hid_code, (t_float)hid_input_event.value); DEBUG(++event_counter;);
Index: TODO =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/TODO,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** TODO 27 May 2006 16:41:59 -0000 1.22 --- TODO 27 May 2006 23:12:51 -0000 1.23 *************** *** 2,10 ****
============================================================================== = output device data on open
- Logical Min/Max i.e. [range -127 127( - - open 1/0 i.e. [open 1( - - vendor/product id i.e. [id 0x1234 0x4567( - device string [name Trackpad(
--- 2,12 ----
============================================================================== + = make second inlet for poll # (for [human->pd] + + + ============================================================================== = output device data on open
- Logical Min/Max i.e. [range -127 127( - device string [name Trackpad(