Update of /cvsroot/pure-data/externals/hcs/hid In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28595
Modified Files: TODO hid-help.pd hid.c hid.h hid_darwin.c hid_linux.c mouse-help.pd Log Message: cleaned up the code a fair amount, but there are still lots of bugs bugs bugs...
Index: hid-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid-help.pd,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** hid-help.pd 6 Nov 2004 21:15:04 -0000 1.7 --- hid-help.pd 7 Nov 2004 16:28:25 -0000 1.8 *************** *** 1,4 **** ! #N canvas 143 45 927 650 10; ! #X msg 390 265 ev_rel rel_x 0 4.08559e+09; #X obj 390 244 prepend set; #X obj 149 473 route rel_x rel_y; --- 1,4 ---- ! #N canvas 156 27 943 666 10; ! #X msg 390 265 ev_rel rel_x 2 3.57445e+09; #X obj 390 244 prepend set; #X obj 149 473 route rel_x rel_y; *************** *** 21,28 **** #X symbolatom 468 409 10 0 0 1 eventcode - -; #X symbolatom 438 428 15 0 0 1 eventtype - -; - #X floatatom 93 536 5 0 0 0 - - -; - #X floatatom 168 537 5 0 0 0 - - -; - #X obj 93 514 route key_f key_leftctrl btn_left; - #X floatatom 243 537 5 0 0 0 - - -; #X obj 177 296 bng 35 250 50 0 empty empty event_received 38 18 1 9 -225280 -1 -1; --- 21,24 ---- *************** *** 56,64 **** #X text 397 111 refresh device list; #X obj 248 225 hid 2; ! #X obj 337 514 unpack s f f; ! #X obj 376 532 tgl 25 0 empty empty any_button 27 13 1 9 -195568 -1 -1 0 1; ! #X obj 740 511 all_about_hid; ! #X text 631 512 For more info:; #X text 49 588 (C) Copyright 2004 Hans-Christoph Steiner hans@at.or.at ; --- 52,60 ---- #X text 397 111 refresh device list; #X obj 248 225 hid 2; ! #X obj 94 524 unpack s f f; ! #X obj 133 542 tgl 25 0 empty empty any_button 27 13 1 9 -195568 -1 -1 0 1; ! #X obj 746 556 all_about_hid; ! #X text 637 557 For more info:; #X text 49 588 (C) Copyright 2004 Hans-Christoph Steiner hans@at.or.at ; *************** *** 75,118 **** #X text 371 56 !!! This software is very much alpha , so any aspect of it could change without notice !!!; #X connect 1 0 0 0; #X connect 2 0 3 0; #X connect 2 1 4 0; ! #X connect 5 0 51 0; ! #X connect 6 0 51 0; #X connect 8 0 19 0; #X connect 8 1 18 0; #X connect 8 2 17 0; #X connect 8 3 7 0; ! #X connect 9 0 51 0; ! #X connect 10 0 51 0; ! #X connect 11 0 51 0; ! #X connect 12 0 51 0; ! #X connect 13 0 51 0; ! #X connect 16 0 51 0; ! #X connect 22 0 20 0; ! #X connect 22 1 21 0; ! #X connect 22 2 23 0; ! #X connect 22 3 52 0; #X connect 41 0 40 0; ! #X connect 41 0 24 0; ! #X connect 42 0 41 1; ! #X connect 43 0 22 0; ! #X connect 43 1 2 0; ! #X connect 43 2 60 0; ! #X connect 43 3 46 0; ! #X connect 44 0 45 1; ! #X connect 45 0 44 0; ! #X connect 46 0 45 0; ! #X connect 47 0 51 0; ! #X connect 49 0 51 0; ! #X connect 51 0 41 0; ! #X connect 51 0 43 0; ! #X connect 51 0 1 0; ! #X connect 51 0 8 0; ! #X connect 52 1 53 0; ! #X connect 60 0 14 0; ! #X connect 60 1 15 0; ! #X connect 60 2 61 0; ! #X connect 62 0 51 0; ! #X connect 63 0 51 0; ! #X connect 66 0 51 0; --- 71,161 ---- #X text 371 56 !!! This software is very much alpha , so any aspect of it could change without notice !!!; + #X text 650 400 REFRESH RATES; + #X text 660 415 ADB = 15.5 ms; + #X text 660 430 USB mice on Windows = 8-10 ms; + #X text 660 445 USB mice on GNU/Linux = 1-10 ms; + #X text 660 460 USB wireless mice = 12-20 ms; + #X text 660 475 PS/2 mouse = 5-25 ms; + #X text 660 490 P5 Glove = 22 ms; + #N canvas 0 22 454 304 JustFOrTestng 0; + #X msg 390 265 ev_rel rel_x 0 2.56485e+09; + #X obj 390 244 prepend set; + #X msg 148 77 start; + #X msg 174 96 stop; + #X msg 239 57 open 0; + #X msg 246 75 open 1; + #X msg 253 93 open 2; + #X msg 259 111 open 3; + #X msg 265 129 open 4; + #X obj 86 81 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 25 + ; + #X obj 223 266 spigot; + #X obj 269 266 tgl 17 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 + 1; + #X msg 336 136 close; + #X text 380 136 probably not needed; + #X msg 336 113 refresh; + #X text 397 111 refresh device list; + #X msg 398 180 poll 20; + #X msg 336 180 poll 2; + #X text 332 159 start polling and set the poll delay in ms; + #X msg 465 180 poll 2000; + #X text 371 56 !!! This software is very much alpha , so any aspect + of it could change without notice !!!; + #X obj 248 225 hid 1; + #X connect 1 0 0 0; + #X connect 2 0 21 0; + #X connect 3 0 21 0; + #X connect 4 0 21 0; + #X connect 5 0 21 0; + #X connect 6 0 21 0; + #X connect 7 0 21 0; + #X connect 8 0 21 0; + #X connect 9 0 21 0; + #X connect 11 0 10 1; + #X connect 12 0 21 0; + #X connect 14 0 21 0; + #X connect 16 0 21 0; + #X connect 17 0 21 0; + #X connect 19 0 21 0; + #X connect 21 0 10 0; + #X connect 21 0 1 0; + #X restore 446 483 pd JustFOrTestng; #X connect 1 0 0 0; #X connect 2 0 3 0; #X connect 2 1 4 0; ! #X connect 5 0 47 0; ! #X connect 6 0 47 0; #X connect 8 0 19 0; #X connect 8 1 18 0; #X connect 8 2 17 0; #X connect 8 3 7 0; ! #X connect 9 0 47 0; ! #X connect 10 0 47 0; ! #X connect 11 0 47 0; ! #X connect 12 0 47 0; ! #X connect 13 0 47 0; ! #X connect 16 0 47 0; ! #X connect 37 0 36 0; ! #X connect 37 0 20 0; ! #X connect 38 0 37 1; ! #X connect 39 0 48 0; ! #X connect 39 1 2 0; ! #X connect 39 2 56 0; ! #X connect 39 3 42 0; ! #X connect 40 0 41 1; #X connect 41 0 40 0; ! #X connect 42 0 41 0; ! #X connect 43 0 47 0; ! #X connect 45 0 47 0; ! #X connect 47 0 37 0; ! #X connect 47 0 39 0; ! #X connect 47 0 1 0; ! #X connect 47 0 8 0; ! #X connect 48 1 49 0; ! #X connect 56 0 14 0; ! #X connect 56 1 15 0; ! #X connect 56 2 57 0; ! #X connect 58 0 47 0; ! #X connect 59 0 47 0; ! #X connect 62 0 47 0;
Index: hid_linux.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_linux.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** hid_linux.c 25 Oct 2004 06:01:45 -0000 1.3 --- hid_linux.c 7 Nov 2004 16:28:25 -0000 1.4 *************** *** 38,44 **** */
! t_int hid_output_events(t_hid *x) { ! DEBUG(post("hid_output_events"););
/* for debugging, counts how many events are processed each time hid_read() is called */ --- 38,44 ---- */
! t_int hid_get_events(t_hid *x) { ! DEBUG(post("hid_get_events"););
/* for debugging, counts how many events are processed each time hid_read() is called */ *************** *** 218,224 **** }
! t_int hid_devicelist_refresh(t_hid *x) { ! DEBUG(post("hid_devicelist_refresh");); /* the device list should be refreshed here */ /* --- 218,224 ---- }
! t_int hid_build_device_list(t_hid *x) { ! DEBUG(post("hid_build_device_list");); /* the device list should be refreshed here */ /*
Index: hid.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** hid.c 6 Nov 2004 21:21:06 -0000 1.11 --- hid.c 7 Nov 2004 16:28:25 -0000 1.12 *************** *** 33,36 **** --- 33,46 ---- #define DEBUG(x) x
+ /* + * Various Max Refresh Rates: + ADB = 15.5 ms + USB mice on Windows = 8-10 ms + USB mice on GNU/Linux = 1-10 ms + USB wireless mice = 12-20 ms + PS/2 mouse = 5-25 ms + P5 Globe = 22 ms + */ + #define DEFAULT_DELAY 5
*************** *** 46,49 **** --- 56,97 ---- static void hid_float(t_hid* x, t_floatarg f);
+ + /*------------------------------------------------------------------------------ + * SUPPORT FUNCTIONS + */ + + void hid_output_event(t_hid *x, + char *type, char *code, t_float value, t_float timestamp) + { + t_atom event_data[4]; + + SETSYMBOL(event_data, gensym(type)); /* type */ + SETSYMBOL(event_data + 1, gensym(code)); /* code */ + SETFLOAT(event_data + 2, value); /* value */ + SETFLOAT(event_data + 3, timestamp); /* timestamp */ + + outlet_anything(x->x_obj.te_outlet,atom_gensym(event_data),3,event_data+1); + } + + void hid_set_from_float(t_hid *x, t_floatarg f) + { + /* values greater than 1 set the polling delay time */ + /* 1 and 0 for start/stop so you can use a [tgl] */ + if (f > 1) + { + x->x_delay = (t_int)f; + hid_start(x,f); + } + else if (f == 1) + { + if (! x->x_started) + hid_start(x,f); + } + else if (f == 0) + { + hid_stop(x); + } + } + /*------------------------------------------------------------------------------ * IMPLEMENTATION *************** *** 74,77 **** --- 122,126 ---- { post("[hid] closed device number %d",x->x_device_number); + x->x_device_open = 0; return (0); } *************** *** 81,115 ****
t_int hid_open(t_hid *x, t_float f) { DEBUG(post("hid_open"););
! /* store running state so that it can be restored after the device has been opened */ ! t_int started = x->x_started; ! ! hid_close(x);
! /* set obj device name to parameter ! * otherwise set to default ! */ ! if (f > 0) ! x->x_device_number = f; ! else ! x->x_device_number = 0;
! if (hid_open_device(x,x->x_device_number)) ! { ! error("[hid] can not open device %d",x->x_device_number); ! post("\=========================== [hid] ===========================/\n"); ! return (1); ! }
/* 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 ! */ ! hid_float(x,started);
! post("\=========================== [hid] ===========================/\n"); ! return (0); }
--- 130,172 ----
+ /* closed same device open */ + /* open same device no action */ + /* closed different device open */ + /* open different device close open */ + t_int hid_open(t_hid *x, t_float f) { DEBUG(post("hid_open"););
! /* store running state to be restored after the device has been opened */ ! t_int started = x->x_started;
! if ( (f != x->x_device_number) && (x->x_device_open) ) hid_close(x);
! /* set obj device name to parameter otherwise set to default */ ! if (f > 0) ! x->x_device_number = f; ! else ! x->x_device_number = 0; ! ! if (! x->x_device_open) ! if (hid_open_device(x,x->x_device_number)) ! { ! error("[hid] can not open device %d",x->x_device_number); ! post("\=========================== [hid] ===========================/\n"); ! return (1); ! } ! else ! { ! x->x_device_open = 1; ! }
/* 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 */ ! hid_set_from_float(x,started);
! ! post("\=========================== [hid] ===========================/\n"); ! return (0); }
*************** *** 117,121 **** t_int hid_read(t_hid *x,int fd) { ! hid_output_events(x); if (x->x_started) --- 174,180 ---- t_int hid_read(t_hid *x,int fd) { ! // DEBUG(post("hid_read");); ! ! hid_get_events(x); if (x->x_started) *************** *** 148,167 **** DEBUG(post("hid_float"););
! /* values greater than 1 set the polling delay time */ ! /* 1 and 0 for start/stop so you can use a [tgl] */ ! if(f > 1) ! { ! x->x_delay = (t_int)f; ! hid_start(x,f); ! } ! else if(f == 1) ! { ! if (! x->x_started) ! hid_start(x,f); ! } ! else if(f == 0) ! { ! hid_stop(x); ! } }
--- 207,211 ---- DEBUG(post("hid_float"););
! hid_set_from_float(x,f); }
*************** *** 195,198 **** --- 239,243 ----
/* init vars */ + x->x_device_open = 0; x->x_started = 0; x->x_delay = DEFAULT_DELAY; *************** *** 204,208 ****
/* find and report the list of devices */ ! hid_devicelist_refresh(x);
/* Open the device and save settings. If there is an error, return the object --- 249,253 ----
/* find and report the list of devices */ ! hid_build_device_list(x);
/* Open the device and save settings. If there is an error, return the object *************** *** 230,234 **** /* add inlet message methods */ ! class_addmethod(hid_class,(t_method) hid_devicelist_refresh,gensym("refresh"),0); class_addmethod(hid_class,(t_method) hid_open,gensym("open"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_close,gensym("close"),0); --- 275,279 ---- /* add inlet message methods */ ! class_addmethod(hid_class,(t_method) hid_build_device_list,gensym("refresh"),0); class_addmethod(hid_class,(t_method) hid_open,gensym("open"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_close,gensym("close"),0);
Index: TODO =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/TODO,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TODO 6 Nov 2004 21:15:04 -0000 1.2 --- TODO 7 Nov 2004 16:28:25 -0000 1.3 *************** *** 1,13 **** ============================================================================== ! = define generic event struct (probably Pd-ized input_event ) ! something like: ! ! struct input_event { ! struct timeval time; ! t_int type; ! t_int code; ! t_int value; ! }; !
The question is whether the timeval is needed at all. Linux and Darwin --- 1,4 ---- ============================================================================== ! = define generic event timestamp struct (probably Pd-ized input_event )
The question is whether the timeval is needed at all. Linux and Darwin *************** *** 23,30 ****
- Misc Input/Generic Desktop X == ev_rel/rel_x - Button Input/Button #1 == ev_key/btn_left - - LED UsagePage => ev_led LED Usages == Linux ev_led codes --- 14,17 ---- *************** *** 62,77 ****
============================================================================== - = raw values vs. calibrated - - - relative axes should probably be raw data, since its pixel data, but then - this causes problems with sensitivity across different mice. The mouse - sensitivity would probably best translate as resolution, ie calibrated data, - rather than sensitivity, ie raw data. - - - absolute axes should be calibrated, so that the same positions on different - devices map to the same value - - - ============================================================================== = pollfn for mouse-like devices
--- 49,52 ---- *************** *** 84,88 ****
- ============================================================================== = function return values --- 59,62 ----
Index: mouse-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/mouse-help.pd,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mouse-help.pd 6 Nov 2004 21:15:04 -0000 1.2 --- mouse-help.pd 7 Nov 2004 16:28:25 -0000 1.3 *************** *** 1,3 **** ! #N canvas 138 201 676 441 10; #X symbolatom 233 198 0 0 0 0 - - -; #X obj 200 36 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1 --- 1,3 ---- ! #N canvas 225 161 684 449 10; #X symbolatom 233 198 0 0 0 0 - - -; #X obj 200 36 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1 *************** *** 31,34 **** --- 31,62 ---- #X msg 255 61 open 2; #X obj 200 91 mouse 1; + #N canvas 462 248 604 514 mouse-noise 0; + #X obj 90 55 inlet; + #X obj 113 173 mouse $1; + #X obj 180 294 noise~; + #X obj 125 293 osc~; + #X obj 125 266 * 4000; + #X obj 113 367 *~; + #X msg 162 103 ; pd dsp 1; + #X obj 103 418 dac~; + #X obj 91 78 t f a b; + #X connect 0 0 8 0; + #X connect 1 0 5 0; + #X connect 1 1 4 0; + #X connect 2 0 5 1; + #X connect 3 0 5 1; + #X connect 4 0 3 0; + #X connect 5 0 7 0; + #X connect 5 0 7 1; + #X connect 8 0 5 0; + #X connect 8 1 1 0; + #X connect 8 2 6 0; + #X restore 464 163 pd mouse-noise 1; + #X msg 505 95 open 0; + #X msg 510 114 open 1; + #X msg 515 133 open 2; + #X obj 464 96 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 0 1 + ; + #X text 347 72 turn this on to make some noise with the mouse; #X connect 1 0 20 0; #X connect 9 0 6 0; *************** *** 49,50 **** --- 77,82 ---- #X connect 20 3 0 0; #X connect 20 4 2 0; + #X connect 22 0 21 0; + #X connect 23 0 21 0; + #X connect 24 0 21 0; + #X connect 25 0 21 0;
Index: hid.h =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** hid.h 6 Nov 2004 21:21:06 -0000 1.8 --- hid.h 7 Nov 2004 16:28:25 -0000 1.9 *************** *** 28,36 **** t_symbol *x_devname; t_int x_device_number; - long x_locID; t_clock *x_clock; t_int x_delay; t_int x_started; t_int x_device_open; } t_hid;
--- 28,36 ---- t_symbol *x_devname; t_int x_device_number; t_clock *x_clock; t_int x_delay; t_int x_started; t_int x_device_open; + t_int x_instance_count; } t_hid;
*************** *** 49,57 **** */
/* generic, cross-platform functions */ t_int hid_open_device(t_hid *x, t_int device_number); t_int hid_close_device(t_hid *x); ! t_int hid_devicelist_refresh(t_hid* x); ! t_int hid_output_events(t_hid *x) ; void hid_platform_specific_free(t_hid *x);
--- 49,61 ---- */
+ /* support functions */ + void hid_output_event(t_hid *x, + char *type, char *code, t_float value, t_float timestamp); + /* generic, cross-platform functions */ t_int hid_open_device(t_hid *x, t_int device_number); t_int hid_close_device(t_hid *x); ! t_int hid_build_device_list(t_hid* x); ! t_int hid_get_events(t_hid *x) ; void hid_platform_specific_free(t_hid *x);
Index: hid_darwin.c =================================================================== RCS file: /cvsroot/pure-data/externals/hcs/hid/hid_darwin.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** hid_darwin.c 6 Nov 2004 21:15:04 -0000 1.6 --- hid_darwin.c 7 Nov 2004 16:28:25 -0000 1.7 *************** *** 44,55 ****
#include "HID_Utilities_External.h" - #include "HID_Error_Handler.h"
- /* - #include <IOKit/IOKitLib.h> - #include <IOKit/IOCFPlugIn.h> - #include <IOKit/hid/IOHIDLib.h> - #include <IOKit/hid/IOHIDKeys.h> - */ #include <IOKit/hid/IOHIDUsageTables.h>
--- 44,48 ---- *************** *** 59,64 **** #include "hid.h"
! #define DEBUG(x) ! //#define DEBUG(x) x
/*============================================================================== --- 52,57 ---- #include "hid.h"
! //#define DEBUG(x) ! #define DEBUG(x) x
/*============================================================================== *************** *** 66,69 **** --- 59,63 ---- *======================================================================== */
+ /*============================================================================== * FUNCTION PROTOTYPES *************** *** 74,82 **** char *convertEventsFromDarwinToLinux(pRecElement element);
- /* IOKit HID Utilities functions from SC_HID.cpp */ - int prHIDBuildElementList(t_hid *x); - int prHIDBuildDeviceList(void); - int prHIDGetValue(void); - /*============================================================================== * EVENT TYPE/CODE CONVERSION FUNCTIONS --- 68,71 ---- *************** *** 84,118 **** */
- void convertDarwinToLinuxType(IOHIDElementType type, char *returnType) - { - switch (type) - { - case kIOHIDElementTypeInput_Misc: - sprintf(returnType, "ev_msc"); - break; - case kIOHIDElementTypeInput_Button: - sprintf(returnType, "ev_key"); - break; - case kIOHIDElementTypeInput_Axis: - sprintf(returnType, "ev_abs"); - break; - case kIOHIDElementTypeInput_ScanCodes: - sprintf(returnType, "undefined"); - break; - case kIOHIDElementTypeOutput: - sprintf(returnType, "undefined"); - break; - case kIOHIDElementTypeFeature: - sprintf(returnType, "undefined"); - break; - case kIOHIDElementTypeCollection: - sprintf(returnType, "undefined"); - break; - default: - HIDReportErrorNum("Unknown element type : ", type); - sprintf(returnType, "unknown"); - } - } - void convertAxis(pRecElement element, char *linux_type, char *linux_code, char axis) { --- 73,76 ---- *************** *** 129,132 **** --- 87,91 ---- }
+ void convertDarwinElementToLinuxTypeCode(pRecElement element, char *linux_type, char *linux_code) { *************** *** 151,154 **** --- 110,115 ---- case kHIDUsage_GD_Ry: convertAxis(element, linux_type, linux_code, 'y'); break; case kHIDUsage_GD_Rz: convertAxis(element, linux_type, linux_code, 'z'); break; + case kHIDUsage_GD_Wheel: + sprintf(linux_type,"ev_rel");sprintf(linux_code,"rel_wheel");break; } break; *************** *** 165,205 **** /* ============================================================================== */
- t_int hid_build_element_list(t_hid *x) - { - DEBUG(post("hid_build_element_list");); - - UInt32 i; - pRecElement devElement; - pRecDevice pCurrentHIDDevice; - UInt32 numElements; - char cstrElementName[256]; - - // look for the right device using locID - pCurrentHIDDevice = HIDGetFirstDevice (); - while (pCurrentHIDDevice && (pCurrentHIDDevice->locID != x->x_locID)) - pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); - if(!pCurrentHIDDevice) return (1); - - devElement = HIDGetFirstDeviceElement(pCurrentHIDDevice, kHIDElementTypeInput); - numElements = HIDCountDeviceElements(pCurrentHIDDevice, kHIDElementTypeInput); - - post("[hid] found %d elements:",numElements); - - for(i=0; i<numElements; i++) - { - //type - HIDGetTypeName((IOHIDElementType) devElement->type, cstrElementName); - post(" Type: %s %d 0x%x",cstrElementName,devElement->type,devElement->type); - convertDarwinToLinuxType((IOHIDElementType) devElement->type, cstrElementName); - post(" Type: %s %d 0x%x",cstrElementName,devElement->type,devElement->type); - //usage - HIDGetUsageName (devElement->usagePage, devElement->usage, cstrElementName); - post(" Usage/Code: %s %d 0x%x",cstrElementName,devElement->usage,devElement->usage); - - devElement = HIDGetNextDeviceElement (devElement, kHIDElementTypeInput); - } - return (0); - } - pRecDevice hid_get_device_by_number(t_int device_number) { --- 126,129 ---- *************** *** 228,238 **** }
/* ============================================================================== */ /* Pd [hid] FUNCTIONS */ /* ============================================================================== */
! t_int hid_output_events(t_hid *x) { ! DEBUG(post("hid_output_events"););
SInt32 value; --- 152,195 ---- }
+ t_int hid_build_element_list(t_hid *x) + { + DEBUG(post("hid_build_element_list");); + + UInt32 i; + pRecElement pCurrentHIDElement; + pRecDevice pCurrentHIDDevice; + UInt32 numElements; + char type[256]; + char code[256]; + char type_name[256]; + char usage_name[256]; + + pCurrentHIDDevice = hid_get_device_by_number(x->x_device_number); + if(!pCurrentHIDDevice) return (1); + + pCurrentHIDElement = HIDGetFirstDeviceElement(pCurrentHIDDevice, kHIDElementTypeInput); + numElements = HIDCountDeviceElements(pCurrentHIDDevice, kHIDElementTypeInput); + + DEBUG(post("[hid] found %d elements:",numElements);); + + for(i=0; i<numElements; i++) + { + convertDarwinElementToLinuxTypeCode(pCurrentHIDElement,type,code); + HIDGetTypeName((IOHIDElementType) pCurrentHIDElement->type, type_name); + HIDGetUsageName(pCurrentHIDElement->usagePage, pCurrentHIDElement->usage, usage_name); + post("\tType: %s \t code: %s \t event name: \t %s, %s",type,code,type_name,usage_name); + + pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeInput); + } + return (0); + } + /* ============================================================================== */ /* Pd [hid] FUNCTIONS */ /* ============================================================================== */
! t_int hid_get_events(t_hid *x) { ! //DEBUG(post("hid_get_events"););
SInt32 value; *************** *** 248,259 **** Boolean result;
! // look for the right device: ! pCurrentHIDDevice = HIDGetFirstDevice (); ! while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=x->x_locID)) ! pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); ! if(!pCurrentHIDDevice) return (1);
- // result = HIDGetEvent(pCurrentHIDDevice, (void*) &event); - // if(result) while( (HIDGetEvent(pCurrentHIDDevice, (void*) &event)) && (event_counter < 64) ) { --- 205,216 ---- Boolean result;
! pCurrentHIDDevice = hid_get_device_by_number(x->x_device_number); ! ! if(!pCurrentHIDDevice) ! { ! post("[hid] can't find current device %d. Was it unplugged?",x->x_device_number); ! return (1); ! }
while( (HIDGetEvent(pCurrentHIDDevice, (void*) &event)) && (event_counter < 64) ) { *************** *** 268,274 ****
DEBUG( - // convertDarwinToLinuxType((IOHIDElementType) pCurrentHIDElement->type, event_output_string); - HIDGetUsageName(pCurrentHIDElement->usagePage, pCurrentHIDElement->usage, event_output_string); - HIDGetElementNameFromVendorProductCookie( pCurrentHIDDevice->vendorID, pCurrentHIDDevice->productID, --- 225,228 ---- *************** *** 278,291 **** convertDarwinElementToLinuxTypeCode(pCurrentHIDElement,type,code); DEBUG(post("type: %s code: %s event name: %s",type,code,event_output_string);); - SETSYMBOL(event_data, gensym(type)); - /* code */ - SETSYMBOL(event_data + 1, gensym(code)); - /* value */ - SETFLOAT(event_data + 2, (t_float)value); - /* time */ - // TODO: convert this to a common time format, i.e. Linux struct timeval - SETFLOAT(event_data + 3, (t_float)(event.timestamp).lo);
! outlet_anything(x->x_obj.te_outlet,atom_gensym(event_data),3,event_data+1); ++event_counter; --- 232,238 ---- convertDarwinElementToLinuxTypeCode(pCurrentHIDElement,type,code); DEBUG(post("type: %s code: %s event name: %s",type,code,event_output_string););
! // TODO: convert this to a common time format, i.e. Linux struct timeval ! hid_output_event(x,type,code,(t_float)value,(t_float)(event.timestamp).lo); ++event_counter; *************** *** 345,350 **** currentDevice = hid_get_device_by_number(device_number);
- x->x_locID = currentDevice->locID; - post("[hid] opened device %d: %s %s", device_number, currentDevice->manufacturer, currentDevice->product); --- 292,295 ---- *************** *** 353,357 ****
HIDQueueDevice(currentDevice); ! // TODO: queue all elements except absolute axes
return (0); --- 298,302 ----
HIDQueueDevice(currentDevice); ! // TODO: queue all elements except absolute axes, those can just be polled
return (0); *************** *** 367,452 **** }
- t_int hid_devicelist_refresh(t_hid *x) - { - DEBUG(post("hid_devicelist_refresh");); - - /* the device list should be refreshed here */ - if ( (prHIDBuildDeviceList()) && (prHIDBuildElementList(x)) ) - return (0); - else - return (1); - } - - void hid_platform_specific_free(t_hid *x) - { - HIDReleaseAllDeviceQueues(); - HIDReleaseDeviceList(); - }
! /*============================================================================== ! * HID UTILIES FUNCTIONS FROM SC_HID.cpp ! *============================================================================== ! */ ! ! int prHIDBuildElementList(t_hid *x) ! { ! DEBUG(post("prHIDBuildElementList");); ! ! int locID = NULL; ! UInt32 i; ! pRecElement devElement; ! pRecDevice pCurrentHIDDevice; ! UInt32 numElements; ! char cstrElementName [256]; ! ! // Apple Trackpad locID for testing ! locID = 50397184; ! ! // look for the right device using locID ! pCurrentHIDDevice = HIDGetFirstDevice (); ! while (pCurrentHIDDevice && (pCurrentHIDDevice->locID != x->x_locID)) ! pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); ! if(!pCurrentHIDDevice) return (1); ! ! devElement = HIDGetFirstDeviceElement(pCurrentHIDDevice, kHIDElementTypeInput); ! numElements = HIDCountDeviceElements(pCurrentHIDDevice, kHIDElementTypeInput); ! ! post("[hid] found %d elements",numElements); ! ! for(i=0; i<numElements; i++) ! { ! //type ! HIDGetTypeName((IOHIDElementType) devElement->type, cstrElementName); ! post("Type: %s %d 0x%x",cstrElementName,devElement->type,devElement->type); ! //usage ! HIDGetUsageName (devElement->usagePage, devElement->usage, cstrElementName); ! post("Usage: %s %d 0x%x",cstrElementName,devElement->usage,devElement->usage); ! ! //devstring = newPyrString(g->gc, cstrElementName, 0, true); ! //SetObject(devElementArray->slots+devElementArray->size++, devstring); ! //g->gc->GCWrite(devElementArray, (PyrObject*) devstring); ! ! devElement = HIDGetNextDeviceElement (devElement, kHIDElementTypeInput); ! } ! return (0); ! } ! ! int prHIDBuildDeviceList(void) { ! DEBUG(post("prHIDBuildDeviceList"););
int i,err; UInt32 usagePage, usage; - pRecElement devElement; pRecDevice pCurrentHIDDevice;
- //pass in usage & usagepage - //kHIDUsage_GD_Joystick kHIDUsage_GD_GamePad - //usagePage = kHIDPage_GenericDesktop; - //usage = NULL; - Boolean result = HIDBuildDeviceList (NULL, NULL); // returns false if no device found - if(result) error("[hid]: no HID devices found\n"); --- 312,326 ---- }
! t_int hid_build_device_list(t_hid *x) { ! DEBUG(post("hid_build_device_list"););
int i,err; UInt32 usagePage, usage; pRecDevice pCurrentHIDDevice;
Boolean result = HIDBuildDeviceList (NULL, NULL); // returns false if no device found if(result) error("[hid]: no HID devices found\n"); *************** *** 455,524 **** if(!numdevs) return (0);
- post("number of devices: %d", numdevs); char cstrDeviceName [256]; ! pCurrentHIDDevice = HIDGetFirstDevice(); ! for(i=numdevs - 1; i >= 0; --i) { ! post("Device %d: '%s' '%s' version %d",i, ! pCurrentHIDDevice->manufacturer,pCurrentHIDDevice->product,pCurrentHIDDevice->version); //usage ! HIDGetUsageName (pCurrentHIDDevice->usagePage, pCurrentHIDDevice->usage, cstrDeviceName); post(" vendorID: %d productID: %d locID: %d", ! pCurrentHIDDevice->vendorID,pCurrentHIDDevice->productID,pCurrentHIDDevice->locID); ! pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); ! } ! ! UInt32 outnum = HIDCountDeviceElements (pCurrentHIDDevice, kHIDElementTypeOutput); ! post("number of outputs: %d \n", outnum);
! return (0); }
! ! int prHIDGetValue(void) { ! DEBUG(post("hid_output_events");); ! ! int locID = NULL; ! int cookieNum = NULL; ! SInt32 value; ! /* ! PyrSlot *a = g->sp - 2; //class ! PyrSlot *b = g->sp - 1; //locID device ! PyrSlot *c = g->sp; //element cookie ! int locID, cookieNum; ! int err = slotIntVal(b, &locID); ! if (err) return err; ! err = slotIntVal(c, &cookieNum); ! if (err) return err; ! */ ! IOHIDElementCookie cookie = (IOHIDElementCookie) cookieNum; ! // look for the right device: ! pRecDevice pCurrentHIDDevice = HIDGetFirstDevice (); ! while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=locID)) ! pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); ! if(!pCurrentHIDDevice) return (1); ! ! ! // look for the right element: ! pRecElement pCurrentHIDElement = HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeIO); ! // use gElementCookie to find current element ! while (pCurrentHIDElement && (pCurrentHIDElement->cookie != cookie)) ! pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeIO); ! ! ! if (pCurrentHIDElement) ! { ! value = HIDGetElementValue (pCurrentHIDDevice, pCurrentHIDElement); ! // if it's not a button and it's not a hatswitch then calibrate ! if(( pCurrentHIDElement->type != kIOHIDElementTypeInput_Button ) && ! ( pCurrentHIDElement->usagePage == 0x01 && pCurrentHIDElement->usage != kHIDUsage_GD_Hatswitch)) ! value = HIDCalibrateValue ( value, pCurrentHIDElement ); ! //SetInt(a, value); ! } ! //else SetNil(a); ! return (0); ! }
--- 329,359 ---- if(!numdevs) return (0);
char cstrDeviceName [256]; ! /* display device list in console */ ! for(i=0; i < numdevs; i++) { ! pCurrentHIDDevice = hid_get_device_by_number(i); ! post("Device %d: '%s' '%s' version %d",i,pCurrentHIDDevice->manufacturer, ! pCurrentHIDDevice->product,pCurrentHIDDevice->version); //usage ! HIDGetUsageName (pCurrentHIDDevice->usagePage, ! pCurrentHIDDevice->usage, ! cstrDeviceName); post(" vendorID: %d productID: %d locID: %d", ! pCurrentHIDDevice->vendorID, ! pCurrentHIDDevice->productID, ! pCurrentHIDDevice->locID);
! // TODO: display all of the element types/codes for each device ! } ! ! return (0); }
! void hid_platform_specific_free(t_hid *x) { ! HIDReleaseAllDeviceQueues(); ! HIDReleaseDeviceList(); }