diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2004-11-06 21:15:04 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2004-11-06 21:15:04 +0000 |
commit | 97f8e42015cdefa311e734856e4f66323dc521cd (patch) | |
tree | 67a55fa7432cc6272187537cf831d285cd845e28 | |
parent | 3b32b7a05d935dc75321a5f7bfab6aad19d07fff (diff) |
things are working MacOS X, but there are lots of bugs
svn path=/trunk/externals/hcs/hid/; revision=2227
-rw-r--r-- | TODO | 69 | ||||
-rw-r--r-- | doc/hid-help.pd | 104 | ||||
-rw-r--r-- | doc/joystick-help.pd | 44 | ||||
-rw-r--r-- | doc/mouse-help.pd | 52 | ||||
-rw-r--r-- | hid.c | 82 | ||||
-rw-r--r-- | hid.h | 9 | ||||
-rw-r--r-- | hid_darwin.c | 246 | ||||
-rw-r--r-- | joystick.pd | 47 | ||||
-rw-r--r-- | mouse.pd | 26 |
9 files changed, 313 insertions, 366 deletions
@@ -54,8 +54,10 @@ Darwin (in SC_HID.c its locID and cookie) -it should probably just store the Pd arguments +- it should probably just store the Pd arguments +- this will have to be dealt with when the "mouse0", "joystick2" arguments are + implemented ============================================================================== @@ -69,13 +71,6 @@ it should probably just store the Pd arguments - absolute axes should be calibrated, so that the same positions on different devices map to the same value -- but then, I could just create an [autocal] object in Pd, and have [hid] - output only raw values. This would probably be best in keeping with the - idea of having [hid] giving as low level access as possible, then using - [mouse], [joystick], [tablet], etc. objects providing a nice, consistent - interface to the respective devices. - - ============================================================================== = pollfn for mouse-like devices @@ -90,47 +85,69 @@ it should probably just store the Pd arguments ============================================================================== -= make generic functions for the basic actions - - releaseDevices() - buildDeviceList() - buildElementList() - getEvent() += function return values - - make Darwin HID Manager -> Linux input event convertor functions +- most functions probably do not need return values +- return (1) seems to be the default on many functions ============================================================================== -= [close( message might be totally frivolous. += control input messages -- what does Max's [hi] do with that? +- the [delay( message should be replaced by the [poll( msg -- when would you need to close a device, yet still have the object there? - [open( closes the previous device anyway. +- should [poll( also start things, or should it just set polling time? +- are [start( and [stop( needed? is 0/1 enough? ============================================================================== -= function return values += ditch x_devname in hid_linux.c -- most functions probably do not need return values +- use sprintf(arg,"/dev/input/event%d",x_ddevice_number); instead -- return (1) seems to be the default on many functions ============================================================================== -= control input messages += consistent console output -- the [delay( message should be replaced by the [poll( msg +void hid_post(const char *format, const char *); -- should [poll( also start things, or should it just set polling time? -- are [start( and [stop( needed? is 0/1 enough? +============================================================================== += if device is closed and obj is started, open device and start + + +______________________________________________________________________________ +------------------------------------------------------------------------------ +BUGS +______________________________________________________________________________ +------------------------------------------------------------------------------ + +______________________________________________________________________________ +- BUG x->x_delay reset to default when device is opened + +______________________________________________________________________________ +- BUG: [mouse] and [joystick] arguments don't work to open device + +______________________________________________________________________________ +- BUG: [open('ing a device causes all other active [hid] objs to have their +devices closed +- this means only one [hid] object can have an open device at one time +- I thought this was due to the hid_close_device() call in hid_open(), which releases + the device list, but this doesn't seem to be the case. +______________________________________________________________________________ +- BUG: getting events from the queue doesn't output a 0 value event when the + motion stops, so when the mouse stops, the sound keeps playing. +This is probably only a problem on relative axes. + This will probably have to be implemented on a platform-specific level: + - On Darwin/MacOSX, I think that the HIDGetEvent() loop will have to be + followed by one call to HIDGetElementValue() diff --git a/doc/hid-help.pd b/doc/hid-help.pd index c8bf113..2b56758 100644 --- a/doc/hid-help.pd +++ b/doc/hid-help.pd @@ -1,5 +1,5 @@ -#N canvas 143 45 911 634 10; -#X msg 390 265 ev_abs abs_x 117 1.13626e+09; +#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; #X floatatom 149 493 5 0 0 0 - - -; @@ -15,7 +15,8 @@ #X msg 265 129 open 4; #X floatatom 206 454 7 0 0 0 - - -; #X floatatom 264 454 7 0 0 0 - - -; -#X obj 86 81 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 1 1; +#X obj 86 81 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 25 25 +; #X floatatom 500 392 12 0 0 1 value - -; #X symbolatom 468 409 10 0 0 1 eventcode - -; #X symbolatom 438 428 15 0 0 1 eventtype - -; @@ -23,12 +24,11 @@ #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 71 241 bng 35 250 50 0 empty empty event_received 38 18 1 9 +#X obj 177 296 bng 35 250 50 0 empty empty event_received 38 18 1 9 -225280 -1 -1; #X obj 2 2 cnv 15 900 20 empty empty [hid] 2 11 1 18 -233017 -66577 0; #X text 362 287 outlet message format:; -#X text 386 301 eventtype eventcode value timestamp; #X obj 742 104 ev-list; #X obj 742 155 ev_syn-list; #X obj 742 177 ev_key-list; @@ -42,27 +42,19 @@ #X obj 742 353 ev_ff_status-list; #X text 710 85 Event Types:; #X text 710 136 Event Codes:; -#X obj 208 302 print INPUT_EVENT; -#X obj 208 281 spigot; -#X obj 245 263 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +#X obj 223 287 print INPUT_EVENT; +#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 obj 93 345 route ev_key ev_rel ev_abs ev_syn; #X floatatom 289 398 5 0 0 1 ev_syn - -; #X obj 262 397 +; #X msg 262 377 1; -#X msg 336 152 close; -#X msg 398 180 delay 20; -#X msg 336 180 delay 2; -#X msg 465 180 delay 200; -#X text 383 40 new possibilities:; -#X msg 391 62 poll; -#X msg 431 62 poll 20; -#X msg 499 61 nopoll; -#X text 380 152 probably not needed; -#X msg 336 129 refresh; -#X text 397 127 refresh device list; +#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 obj 248 225 hid 2; -#X obj 590 143 loadbang; #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; @@ -71,50 +63,56 @@ #X text 49 588 (C) Copyright 2004 Hans-Christoph Steiner <hans@at.or.at> ; #X text 266 602 released under the GNU GPL; -#X text 472 589 $Revision: 1.6 $$Date: 2004-11-06 01:03:00 $; +#X text 472 589 $Revision: 1.7 $$Date: 2004-11-06 21:15:04 $; #X text 473 602 $Author: eighthave $; #X obj 206 433 route abs_x abs_y abs_z; #X floatatom 322 454 7 0 0 0 - - -; +#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 text 386 301 event_type event_code value timestamp; +#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 connect 1 0 0 0; #X connect 2 0 3 0; #X connect 2 1 4 0; -#X connect 5 0 59 0; -#X connect 6 0 59 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 59 0; -#X connect 10 0 59 0; -#X connect 11 0 59 0; -#X connect 12 0 59 0; -#X connect 13 0 59 0; -#X connect 16 0 59 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 61 0; -#X connect 42 0 41 0; -#X connect 43 0 42 1; -#X connect 44 0 22 0; -#X connect 44 1 2 0; -#X connect 44 2 69 0; -#X connect 44 3 47 0; -#X connect 45 0 46 1; +#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 46 0; -#X connect 48 0 59 0; -#X connect 49 0 59 0; -#X connect 50 0 59 0; -#X connect 51 0 59 0; -#X connect 57 0 59 0; -#X connect 59 0 42 0; -#X connect 59 0 24 0; -#X connect 59 0 44 0; -#X connect 59 0 1 0; -#X connect 59 0 8 0; -#X connect 60 0 51 0; -#X connect 61 1 62 0; -#X connect 69 0 14 0; -#X connect 69 1 15 0; -#X connect 69 2 70 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; diff --git a/doc/joystick-help.pd b/doc/joystick-help.pd new file mode 100644 index 0000000..6807228 --- /dev/null +++ b/doc/joystick-help.pd @@ -0,0 +1,44 @@ +#N canvas 182 322 672 437 10; +#X symbolatom 339 141 0 0 0 0 - - -; +#X obj 178 21 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 1 1 +; +#X floatatom 420 144 5 0 0 0 - - -; +#X floatatom 93 184 7 0 0 3 Y - -; +#X floatatom 39 184 7 0 0 3 X - -; +#X obj 158 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 203 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 248 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 294 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 178 74 joystick 3; +#X floatatom 153 184 5 0 0 0 - - -; +#X floatatom 196 184 5 0 0 0 - - -; +#X obj 158 271 route btn_1 btn_2 btn_3 btn_4 btn_5 btn_6 btn_7 btn_8 +btn_9; +#X obj 339 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 384 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 430 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 475 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 +1; +#X obj 338 115 unpack s f; +#X connect 1 0 9 0; +#X connect 9 0 4 0; +#X connect 9 1 3 0; +#X connect 9 2 10 0; +#X connect 9 3 11 0; +#X connect 12 0 5 0; +#X connect 12 1 6 0; +#X connect 12 2 7 0; +#X connect 12 3 8 0; +#X connect 12 4 13 0; +#X connect 12 5 14 0; +#X connect 12 6 15 0; +#X connect 12 7 16 0; +#X connect 17 0 0 0; +#X connect 17 1 2 0; diff --git a/doc/mouse-help.pd b/doc/mouse-help.pd index 79f07a8..3ec4b50 100644 --- a/doc/mouse-help.pd +++ b/doc/mouse-help.pd @@ -1,12 +1,11 @@ -#N canvas 127 178 668 433 10; -#X symbolatom 211 183 0 0 0 0 - - -; -#X obj 178 21 tgl 25 0 empty empty empty 0 -6 0 8 -225271 -1 -1 1 1 +#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 ; -#X floatatom 287 185 5 0 0 0 - - -; -#X floatatom 168 184 5 0 0 3 wheel - -; -#X floatatom 113 184 7 0 0 3 Y - -; -#X floatatom 59 184 7 0 0 3 X - -; -#X obj 178 76 mouse 4; +#X floatatom 309 200 5 0 0 0 - - -; +#X floatatom 190 199 5 0 0 3 wheel - -; +#X floatatom 135 199 7 0 0 3 Y - -; +#X floatatom 81 199 7 0 0 3 X - -; #X obj 28 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 1 ; #X obj 108 294 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 @@ -27,18 +26,25 @@ 1; #X obj 268 295 route btn_side btn_extra btn_forward btn_back btn_task ; -#X connect 1 0 6 0; -#X connect 6 0 5 0; -#X connect 6 1 4 0; -#X connect 6 2 3 0; -#X connect 6 3 0 0; -#X connect 6 4 2 0; -#X connect 10 0 7 0; -#X connect 10 1 8 0; -#X connect 10 2 9 0; -#X connect 10 3 17 0; -#X connect 17 0 12 0; -#X connect 17 1 13 0; -#X connect 17 2 14 0; -#X connect 17 3 15 0; -#X connect 17 4 16 0; +#X msg 245 23 open 0; +#X msg 250 42 open 1; +#X msg 255 61 open 2; +#X obj 200 91 mouse 1; +#X connect 1 0 20 0; +#X connect 9 0 6 0; +#X connect 9 1 7 0; +#X connect 9 2 8 0; +#X connect 9 3 16 0; +#X connect 16 0 11 0; +#X connect 16 1 12 0; +#X connect 16 2 13 0; +#X connect 16 3 14 0; +#X connect 16 4 15 0; +#X connect 17 0 20 0; +#X connect 18 0 20 0; +#X connect 19 0 20 0; +#X connect 20 0 5 0; +#X connect 20 1 4 0; +#X connect 20 2 3 0; +#X connect 20 3 0 0; +#X connect 20 4 2 0; @@ -38,12 +38,11 @@ * FUNCTION PROTOTYPES */ -void hid_start(t_hid *x); +void hid_start(t_hid *x, t_float f); void hid_stop(t_hid *x); t_int hid_open(t_hid *x, t_float f); t_int hid_close(t_hid *x); t_int hid_read(t_hid *x,int fd); -void hid_delay(t_hid *x, t_float f); static void hid_float(t_hid* x, t_floatarg f); /*------------------------------------------------------------------------------ @@ -71,9 +70,13 @@ t_int hid_close(t_hid *x) /* just to be safe, stop it first */ hid_stop(x); - post("[hid] closed device number %d",x->x_device_number); + if(! hid_close_device(x)) + { + post("[hid] closed device number %d",x->x_device_number); + return (0); + } - return (hid_close_device(x)); + return (1); } @@ -97,7 +100,7 @@ t_int hid_open(t_hid *x, t_float f) if (hid_open_device(x,x->x_device_number)) { error("[hid] can not open device %d",x->x_device_number); - post("\\================================ [hid] ================================/\n"); + post("\\=========================== [hid] ===========================/\n"); return (1); } @@ -106,7 +109,7 @@ t_int hid_open(t_hid *x, t_float f) */ hid_float(x,started); - post("\\================================ [hid] ================================/\n"); + post("\\=========================== [hid] ===========================/\n"); return (0); } @@ -120,33 +123,22 @@ t_int hid_read(t_hid *x,int fd) clock_delay(x->x_clock, x->x_delay); } - return 1; /* why is this 1? */ + // TODO: why is this 1? + return 1; } -/* Actions */ -void hid_delay(t_hid* x, t_float f) -{ - DEBUG(post("hid_DELAY %f",f);) - -/* if the user sets the delay less than zero, reset to default */ - if ( f > 0 ) - { - x->x_delay = (t_int)f; - } - else - { - x->x_delay = DEFAULT_DELAY; - } -} - -void hid_start(t_hid* x) +void hid_start(t_hid* x, t_float f) { DEBUG(post("hid_start");); +/* if the user sets the delay less than one, ignore */ + if ( f >= 1 ) + x->x_delay = (t_int)f; + if (!x->x_started) { - clock_delay(x->x_clock, DEFAULT_DELAY); - post("hid: polling started"); + clock_delay(x->x_clock, x->x_delay); + post("[hid]: polling started"); x->x_started = 1; } } @@ -154,11 +146,23 @@ void hid_start(t_hid* x) static void hid_float(t_hid* x, t_floatarg f) { DEBUG(post("hid_float");); - - if(f == 1) - hid_start(x); - else if(f == 0) + +/* 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); + } } /* setup functions */ @@ -167,7 +171,9 @@ static void hid_free(t_hid* x) DEBUG(post("hid_free");); hid_close(x); - + + hid_platform_specific_free(x); + clock_free(x->x_clock); } @@ -178,7 +184,7 @@ static void *hid_new(t_float f) DEBUG(post("hid_new");); - post("/================================ [hid] ================================\\"); + post("/=========================== [hid] ===========================\\"); post("[hid] %s, written by Hans-Christoph Steiner <hans@eds.org>",version); #if !defined(__linux__) && !defined(__APPLE__) error(" !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!"); @@ -187,7 +193,6 @@ static void *hid_new(t_float f) #endif /* init vars */ - x->x_read_ok = 1; x->x_started = 0; x->x_delay = DEFAULT_DELAY; @@ -202,8 +207,8 @@ static void *hid_new(t_float f) /* Open the device and save settings. If there is an error, return the object * anyway, so that the inlets and outlets are created, thus not breaking the * patch. */ -/* if (hid_open(x,f)) */ -/* error("[hid] device %d did not open",(t_int)f); */ + if (hid_open(x,f)) + error("[hid] device %d did not open",(t_int)f); return (x); } @@ -223,12 +228,11 @@ void hid_setup(void) class_addbang(hid_class,(t_method) hid_read); /* add inlet message methods */ - class_addmethod(hid_class,(t_method) hid_delay,gensym("delay"),A_DEFFLOAT,0); - class_addmethod(hid_class,(t_method) hid_open,gensym("open"),A_DEFFLOAT,0); 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); - class_addmethod(hid_class,(t_method) hid_start,gensym("start"),0); - class_addmethod(hid_class,(t_method) hid_start,gensym("poll"),0); + class_addmethod(hid_class,(t_method) hid_start,gensym("start"),A_DEFFLOAT,0); + class_addmethod(hid_class,(t_method) hid_start,gensym("poll"),A_DEFFLOAT,0); class_addmethod(hid_class,(t_method) hid_stop,gensym("stop"),0); class_addmethod(hid_class,(t_method) hid_stop,gensym("nopoll"),0); } @@ -11,7 +11,7 @@ */ #include "input_arrays.h" -static char *version = "$Revision: 1.6 $"; +static char *version = "$Revision: 1.7 $"; /*------------------------------------------------------------------------------ * CLASS DEF @@ -24,11 +24,11 @@ typedef struct _hid t_int x_fd; t_symbol *x_devname; t_int x_device_number; + long x_locID; t_clock *x_clock; - t_int x_read_ok; - t_int x_started; t_int x_delay; - long x_locID; + t_int x_started; + t_int x_device_open; } t_hid; @@ -50,5 +50,6 @@ 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); #endif /* #ifndef _HID_H */ diff --git a/hid_darwin.c b/hid_darwin.c index 4a92958..751c14e 100644 --- a/hid_darwin.c +++ b/hid_darwin.c @@ -65,18 +65,6 @@ * GLOBAL VARS *======================================================================== */ -/* count of total number of devices found */ -int gNumberOfHIDDevices = 0; - -/* - * an array of discovered devices, which is used for selecting the - * current device, by #, type, or name - */ -pRecDevice discoveredDevices[256]; - -/* timer for element data updates */ -EventLoopTimerRef gTimer = NULL; - /*============================================================================== * FUNCTION PROTOTYPES *============================================================================== @@ -86,15 +74,9 @@ EventLoopTimerRef gTimer = NULL; char *convertEventsFromDarwinToLinux(pRecElement element); /* IOKit HID Utilities functions from SC_HID.cpp */ -void releaseHIDDevices(void); int prHIDBuildElementList(t_hid *x); int prHIDBuildDeviceList(void); int prHIDGetValue(void); -void PushQueueEvents_RawValue(void); -void PushQueueEvents_CalibratedValue(void); -int prHIDReleaseDeviceList(void); -//int prHIDRunEventLoop(void); -//int prHIDStopEventLoop(void); /*============================================================================== * EVENT TYPE/CODE CONVERSION FUNCTIONS @@ -219,6 +201,32 @@ t_int hid_build_element_list(t_hid *x) return (0); } +pRecDevice hid_get_device_by_number(t_int device_number) +{ + pRecDevice currentDevice; + t_int i, numdevs; + +/* + * If the specified device is greater than the total number of devices, return + * an error. + */ + numdevs = (t_int) HIDCountDevices(); + if (device_number >= numdevs) { + error("[hid]: no such device, \"%d\", only %d devices found\n",device_number,numdevs); + return (NULL); + } +/* + * The most recently discovered HID is the first element of the list here. I + * want the oldest to be number 0 rather than the newest, so I use (numdevs - + * device_number - 1). + */ + currentDevice = HIDGetFirstDevice(); + for(i=0; i < numdevs - device_number - 1; ++i) + currentDevice = HIDGetNextDevice(currentDevice); + + return currentDevice; +} + /* ============================================================================== */ /* Pd [hid] FUNCTIONS */ /* ============================================================================== */ @@ -257,13 +265,15 @@ t_int hid_output_events(t_hid *x) pCurrentHIDElement = HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeIO); while (pCurrentHIDElement && (pCurrentHIDElement->cookie != cookie)) pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeIO); - + + DEBUG( // convertDarwinToLinuxType((IOHIDElementType) pCurrentHIDElement->type, event_output_string); HIDGetUsageName(pCurrentHIDElement->usagePage, pCurrentHIDElement->usage, event_output_string); HIDGetElementNameFromVendorProductCookie( pCurrentHIDDevice->vendorID, pCurrentHIDDevice->productID, (long) pCurrentHIDElement->cookie, event_output_string); + ); //end DEBUG convertDarwinElementToLinuxTypeCode(pCurrentHIDElement,type,code); DEBUG(post("type: %s code: %s event name: %s",type,code,event_output_string);); @@ -325,33 +335,14 @@ t_int hid_open_device(t_hid *x, t_int device_number) { DEBUG(post("hid_open_device");); - t_int i,err,result; + t_int err,result; pRecDevice currentDevice = NULL; result = HIDBuildDeviceList (NULL, NULL); // returns false if no device found if(result) error("[hid]: no HID devices found\n"); -/* - * If the specified device is greater than the total number of devices, return - * an error. - */ - int numdevs = HIDCountDevices(); - gNumberOfHIDDevices = numdevs; - if (device_number >= numdevs) { - error("[hid]: no such device, \"%d\", only %d devices found\n",device_number,numdevs); - return (1); - } - - currentDevice = HIDGetFirstDevice(); - -/* - * The most recently discovered HID is the first element of the list here. I - * want the oldest to be number 0 rather than the newest, so I use (numdevs - - * device_number - 1). - */ - for(i=0; i < numdevs - device_number - 1; ++i) - currentDevice = HIDGetNextDevice(currentDevice); + currentDevice = hid_get_device_by_number(device_number); x->x_locID = currentDevice->locID; @@ -371,12 +362,8 @@ t_int hid_close_device(t_hid *x) { DEBUG(post("hid_close_device");); - post("[hid] close_device %d",x->x_device_number); - HIDReleaseAllDeviceQueues(); - HIDReleaseDeviceList(); - gNumberOfHIDDevices = 0; - - return (0); + post("[hid] closing device %d",x->x_device_number); + return( HIDDequeueDevice( hid_get_device_by_number(x->x_device_number) ) ); } t_int hid_devicelist_refresh(t_hid *x) @@ -390,27 +377,17 @@ t_int hid_devicelist_refresh(t_hid *x) return (1); } - +void hid_platform_specific_free(t_hid *x) +{ + HIDReleaseAllDeviceQueues(); + HIDReleaseDeviceList(); +} /*============================================================================== * HID UTILIES FUNCTIONS FROM SC_HID.cpp *============================================================================== */ -void releaseHIDDevices (void) -{ - DEBUG(post("releaseHIDDevices");); - - if (gTimer) - { - RemoveEventLoopTimer(gTimer); - gTimer = NULL; - } - HIDReleaseAllDeviceQueues(); - HIDReleaseDeviceList(); - gNumberOfHIDDevices = 0; -} - int prHIDBuildElementList(t_hid *x) { DEBUG(post("prHIDBuildElementList");); @@ -474,7 +451,6 @@ int prHIDBuildDeviceList(void) if(result) error("[hid]: no HID devices found\n"); int numdevs = HIDCountDevices(); - gNumberOfHIDDevices = numdevs; // exit if no devices found if(!numdevs) return (0); @@ -482,7 +458,7 @@ int prHIDBuildDeviceList(void) char cstrDeviceName [256]; pCurrentHIDDevice = HIDGetFirstDevice(); - for(i=gNumberOfHIDDevices - 1; i >= 0; --i) + for(i=numdevs - 1; i >= 0; --i) { post("Device %d: '%s' '%s' version %d",i, pCurrentHIDDevice->manufacturer,pCurrentHIDDevice->product,pCurrentHIDDevice->version); @@ -546,150 +522,6 @@ int prHIDGetValue(void) } - -void PushQueueEvents_RawValue(void) -{ - DEBUG(post("PushQueueEvents_RawValue");); - - int i; - - IOHIDEventStruct event; - pRecDevice pCurrentHIDDevice = HIDGetFirstDevice (); - int numdevs = gNumberOfHIDDevices; - unsigned char result; - for(i=0; i< numdevs; i++) - { - result = HIDGetEvent(pCurrentHIDDevice, (void*) &event); - if(result) - { - SInt32 value = event.value; - int vendorID = pCurrentHIDDevice->vendorID; - int productID = pCurrentHIDDevice->productID; - int locID = pCurrentHIDDevice->locID; - IOHIDElementCookie cookie = (IOHIDElementCookie) event.elementCookie; - //set arguments: -// ++g->sp;SetInt(g->sp, vendorID); -// ++g->sp;SetInt(g->sp, productID); -// ++g->sp;SetInt(g->sp, locID); -// ++g->sp;SetInt(g->sp, (int) cookie); -// ++g->sp;SetInt(g->sp, value); - } - pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); - } -} - - -void PushQueueEvents_CalibratedValue(void) -{ - DEBUG(post("PushQueueEvents_CalibratedValue");); - - int i; - - IOHIDEventStruct event; - pRecDevice pCurrentHIDDevice = HIDGetFirstDevice (); - - int numdevs = gNumberOfHIDDevices; - unsigned char result; - for(i=0; i< numdevs; i++) - { - - result = HIDGetEvent(pCurrentHIDDevice, (void*) &event); - if(result) - { - SInt32 value = event.value; - int vendorID = pCurrentHIDDevice->vendorID; - int productID = pCurrentHIDDevice->productID; - int locID = pCurrentHIDDevice->locID; - IOHIDElementCookie cookie = (IOHIDElementCookie) event.elementCookie; - pRecElement pCurrentHIDElement = HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeIO); - // use gElementCookie to find current element - while (pCurrentHIDElement && ( (pCurrentHIDElement->cookie) != cookie)) - pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeIO); - - if (pCurrentHIDElement) - { - value = HIDCalibrateValue(value, pCurrentHIDElement); - //find element to calibrate - //set arguments: -// ++g->sp;SetInt(g->sp, vendorID); -// ++g->sp;SetInt(g->sp, productID); -// ++g->sp;SetInt(g->sp, locID); -// ++g->sp;SetInt(g->sp, (int) cookie); -// ++g->sp;SetInt(g->sp, value); - } - } - pCurrentHIDDevice = HIDGetNextDevice(pCurrentHIDDevice); - } -} - - -/* static pascal void IdleTimer(EventLoopTimerRef inTimer, void* userData) */ -/* { */ -/* DEBUG(post("IdleTimer");); */ - -/* #pragma unused (inTimer, userData) */ -/* PushQueueEvents_CalibratedValue (); */ -/* } */ - - -int prHIDReleaseDeviceList(void) -{ - DEBUG(post("prHIDReleaseDeviceList");); - - releaseHIDDevices(); - return (0); -} - - -/* static EventLoopTimerUPP GetTimerUPP(void) */ -/* { */ -/* DEBUG(post("GetTimerUPP");); */ - -/* static EventLoopTimerUPP sTimerUPP = NULL; */ -/* if (sTimerUPP == NULL) */ -/* sTimerUPP = NewEventLoopTimerUPP(IdleTimer); */ - -/* return sTimerUPP; */ -/* } */ - - -/* -typedef void (*IOHIDCallbackFunction) - (void * target, IOReturn result, void * refcon, void * sender); - -*/ -/* -void callback (void * target, IOReturn result, void * refcon, void * sender); -void callback (void * target, IOReturn result, void * refcon, void * sender) -{ -} -*/ - -/* int prHIDRunEventLoop(void) */ -/* { */ -/* DEBUG(post("prHIDRunEventLoop");); */ - -/* //PyrSlot *a = g->sp - 1; //class */ - -/* InstallEventLoopTimer(GetCurrentEventLoop(), 0, 0.001, GetTimerUPP (), 0, &gTimer); */ - -/* //HIDSetQueueCallback(pCurrentHIDDevice, callback); */ -/* return (0); */ -/* } */ - -/* int prHIDStopEventLoop(void) */ -/* { */ -/* DEBUG(post("prHIDStopEventLoop");); */ - -/* if (gTimer) */ -/* RemoveEventLoopTimer(gTimer); */ -/* gTimer = NULL; */ -/* return (0); */ -/* } */ - -/* this is just a rough sketch */ - - //void HIDGetUsageName (const long valueUsagePage, const long valueUsage, char * cstrName) char *convertEventsFromDarwinToLinux(pRecElement element) { diff --git a/joystick.pd b/joystick.pd new file mode 100644 index 0000000..830496b --- /dev/null +++ b/joystick.pd @@ -0,0 +1,47 @@ +#N canvas 353 77 803 591 10; +#X msg 96 64 start; +#X msg 105 83 stop; +#X obj 77 30 inlet; +#X obj 207 160 print UNKNOWN_JOYSTICK_EVENT_TYPE; +#X text 260 134 types (1=buttons 3=abs axes); +#X obj 218 286 print UNKNOWN_JOYSTICK_EVENT_CODE; +#X obj 38 508 outlet; +#X obj 143 327 outlet; +#X obj 164 307 outlet; +#X text 52 244 codes (0=X 1=Y 6=throttle 7=rudder \, 16=hat0X \, 17=hat0Y) +; +#X obj 411 417 outlet; +#X text 401 433 button_num; +#X text 492 434 button_value; +#X obj 511 418 outlet; +#X obj 77 107 hid \$1; +#X obj 38 264 route abs_x abs_y 7 16 17 6; +#X obj 38 489 autoscale -1 1; +#X obj 68 468 outlet; +#X obj 68 449 autoscale -1 1; +#X obj 99 428 outlet; +#X obj 99 409 autoscale -1 1; +#X obj 130 388 outlet; +#X obj 130 369 autoscale -1 1; +#X obj 79 139 route ev_abs ev_key; +#X obj 221 91 print RAW; +#X obj 411 351 unpack s f f; +#X connect 0 0 14 0; +#X connect 1 0 14 0; +#X connect 2 0 14 0; +#X connect 14 0 23 0; +#X connect 15 0 16 0; +#X connect 15 1 18 0; +#X connect 15 2 20 0; +#X connect 15 3 22 0; +#X connect 15 4 7 0; +#X connect 15 5 8 0; +#X connect 16 0 6 0; +#X connect 18 0 17 0; +#X connect 20 0 19 0; +#X connect 22 0 21 0; +#X connect 23 0 15 0; +#X connect 23 1 25 0; +#X connect 23 2 3 0; +#X connect 25 0 10 0; +#X connect 25 1 13 0; @@ -1,4 +1,4 @@ -#N canvas 305 189 689 434 10; +#N canvas 305 189 693 438 10; #X obj 125 38 inlet; #X obj 5 346 outlet; #X obj 110 346 outlet; @@ -19,29 +19,27 @@ #X msg 187 84 open \$1; #X obj 187 61 f \$1; #X obj 187 37 loadbang; -#X obj 125 115 hid; #X obj 5 283 autoscale -1 1; #X obj 110 283 autoscale -1 1; #X obj 220 284 autoscale -1 1; #X obj 67 233 route rel_x rel_y rel_wheel; #X obj 271 258 print MOUSE_UNIMPLEMENTED_EVENT; -#X connect 0 0 20 0; +#X text 343 139 this is for once this feature is implemented; +#X obj 125 115 hid \$1; +#X connect 0 0 26 0; #X connect 7 0 6 0; #X connect 8 0 7 0; #X connect 9 0 8 0; -#X connect 15 0 24 0; +#X connect 15 0 23 0; #X connect 15 1 16 0; -#X connect 15 2 25 0; #X connect 16 0 4 0; #X connect 16 1 5 0; -#X connect 17 0 20 0; #X connect 18 0 17 0; #X connect 19 0 18 0; -#X connect 20 0 15 0; -#X connect 21 0 1 0; -#X connect 22 0 2 0; -#X connect 23 0 3 0; -#X connect 24 0 21 0; -#X connect 24 1 22 0; -#X connect 24 2 23 0; -#X connect 24 3 25 0; +#X connect 20 0 1 0; +#X connect 21 0 2 0; +#X connect 22 0 3 0; +#X connect 23 0 20 0; +#X connect 23 1 21 0; +#X connect 23 2 22 0; +#X connect 26 0 15 0; |