diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2004-11-06 01:03:01 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2004-11-06 01:03:01 +0000 |
commit | 3b32b7a05d935dc75321a5f7bfab6aad19d07fff (patch) | |
tree | 70b49d647bf447ffab632894d1a423b5c1f113b2 | |
parent | c0cf43d9e8b028a899af16a16e81dfe4729b6c95 (diff) |
mice and joysticks work under MacOS X now, but there is much work left to be done in terms of translating HID Manager to Linux Input events.
svn path=/trunk/externals/hcs/hid/; revision=2220
-rw-r--r-- | doc/hid-help.pd | 130 | ||||
-rw-r--r-- | hid.c | 22 | ||||
-rw-r--r-- | hid.h | 30 | ||||
-rw-r--r-- | hid_darwin.c | 360 |
4 files changed, 287 insertions, 255 deletions
diff --git a/doc/hid-help.pd b/doc/hid-help.pd index c0f664a..c8bf113 100644 --- a/doc/hid-help.pd +++ b/doc/hid-help.pd @@ -1,30 +1,29 @@ -#N canvas 124 73 912 605 10; -#X msg 390 265 ev_key btn_left 0 1.09868e+09; +#N canvas 143 45 911 634 10; +#X msg 390 265 ev_abs abs_x 117 1.13626e+09; #X obj 390 244 prepend set; #X obj 149 473 route rel_x rel_y; #X floatatom 149 493 5 0 0 0 - - -; #X floatatom 206 493 5 0 0 0 - - -; #X msg 148 77 start; #X msg 174 96 stop; -#X floatatom 494 384 12 0 0 1 time - -; -#X obj 401 364 unpack s s f f; -#X msg 241 29 open 0; -#X msg 248 47 open 1; -#X msg 255 65 open 2; -#X msg 261 83 open 3; -#X msg 267 101 open 4; +#X floatatom 531 375 12 0 0 1 time - -; +#X obj 438 355 unpack s s f f; +#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 floatatom 206 454 7 0 0 0 - - -; #X floatatom 264 454 7 0 0 0 - - -; -#X obj 206 433 route abs_x abs_y; -#X obj 86 81 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 1; -#X floatatom 463 401 12 0 0 1 value - -; -#X symbolatom 431 418 10 0 0 1 eventcode - -; -#X symbolatom 401 437 15 0 0 1 eventtype - -; +#X obj 86 81 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 1 1; +#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 - -; #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 61 219 bng 35 250 50 0 empty empty event_received 38 18 1 8 +#X obj 71 241 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; @@ -51,54 +50,71 @@ #X floatatom 289 398 5 0 0 1 ev_syn - -; #X obj 262 397 +; #X msg 262 377 1; -#X msg 317 149 close; -#X msg 374 178 delay 20; -#X msg 312 177 delay 2; -#X msg 441 178 delay 200; +#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 361 149 probably not needed; -#X msg 282 127 refresh; -#X text 343 125 refresh device list; -#X obj 248 209 hid 2; +#X text 380 152 probably not needed; +#X msg 336 129 refresh; +#X text 397 127 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; +#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> +; +#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 473 602 $Author: eighthave $; +#X obj 206 433 route abs_x abs_y abs_z; +#X floatatom 322 454 7 0 0 0 - - -; #X connect 1 0 0 0; #X connect 2 0 3 0; #X connect 2 1 4 0; -#X connect 5 0 60 0; -#X connect 6 0 60 0; -#X connect 8 0 20 0; -#X connect 8 1 19 0; -#X connect 8 2 18 0; +#X connect 5 0 59 0; +#X connect 6 0 59 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 60 0; -#X connect 10 0 60 0; -#X connect 11 0 60 0; -#X connect 12 0 60 0; -#X connect 13 0 60 0; -#X connect 16 0 14 0; -#X connect 16 1 15 0; -#X connect 17 0 60 0; -#X connect 23 0 21 0; -#X connect 23 1 22 0; -#X connect 23 2 24 0; -#X connect 43 0 42 0; -#X connect 44 0 43 1; -#X connect 45 0 23 0; -#X connect 45 1 2 0; -#X connect 45 2 16 0; -#X connect 45 3 48 0; -#X connect 46 0 47 1; +#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 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 46 0 45 0; #X connect 47 0 46 0; -#X connect 48 0 47 0; -#X connect 49 0 60 0; -#X connect 50 0 60 0; -#X connect 51 0 60 0; -#X connect 52 0 60 0; -#X connect 58 0 60 0; -#X connect 60 0 43 0; -#X connect 60 0 25 0; -#X connect 60 0 45 0; -#X connect 60 0 1 0; -#X connect 60 0 8 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; @@ -35,6 +35,18 @@ #define DEFAULT_DELAY 5 /*------------------------------------------------------------------------------ + * FUNCTION PROTOTYPES + */ + +void hid_start(t_hid *x); +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); + +/*------------------------------------------------------------------------------ * IMPLEMENTATION */ @@ -68,6 +80,9 @@ t_int hid_close(t_hid *x) 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); @@ -82,10 +97,15 @@ 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); } +/* 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); } @@ -11,7 +11,7 @@ */ #include "input_arrays.h" -static char *version = "$Revision: 1.5 $"; +static char *version = "$Revision: 1.6 $"; /*------------------------------------------------------------------------------ * CLASS DEF @@ -29,9 +29,6 @@ typedef struct _hid t_int x_started; t_int x_delay; long x_locID; -/* these two are probably unnecessary */ - long x_vendorID; - long x_productID; } t_hid; @@ -39,7 +36,7 @@ typedef struct _hid * GLOBALS */ -/* what are these for again? */ +/* TODO: what are these for again? */ char *deviceList[64]; char *typeList[256]; char *codeList[256]; @@ -54,27 +51,4 @@ t_int hid_close_device(t_hid *x); t_int hid_devicelist_refresh(t_hid* x); t_int hid_output_events(t_hid *x) ; - - - - -#ifdef __APPLE__ -void releaseHIDDevices(void); -int prHIDBuildElementList(void); -int prHIDBuildDeviceList(void); -int prHIDGetValue(void); -void PushQueueEvents_RawValue(void); -void PushQueueEvents_CalibratedValue(void); -int prHIDReleaseDeviceList(void); -//int prHIDRunEventLoop(void); -int prHIDQueueDevice(void); -int prHIDQueueElement(void); -int prHIDDequeueElement(void); -int prHIDDequeueDevice(void); -//int prHIDStopEventLoop(void); -#endif /* #ifdef __APPLE__ */ - - - - #endif /* #ifndef _HID_H */ diff --git a/hid_darwin.c b/hid_darwin.c index a7d3bef..4a92958 100644 --- a/hid_darwin.c +++ b/hid_darwin.c @@ -58,8 +58,8 @@ #include "hid.h" -//#define DEBUG(x) -#define DEBUG(x) x +#define DEBUG(x) +//#define DEBUG(x) x /*============================================================================== * GLOBAL VARS @@ -81,17 +81,28 @@ EventLoopTimerRef gTimer = NULL; * FUNCTION PROTOTYPES *============================================================================== */ + +/* conversion functions */ 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 *============================================================================== */ -char *convertDarwinToLinuxType(IOHIDElementType type) +void convertDarwinToLinuxType(IOHIDElementType type, char *returnType) { - char *returnType = ""; - switch (type) { case kIOHIDElementTypeInput_Misc: @@ -119,12 +130,96 @@ char *convertDarwinToLinuxType(IOHIDElementType type) HIDReportErrorNum("Unknown element type : ", type); sprintf(returnType, "unknown"); } +} + +void convertAxis(pRecElement element, char *linux_type, char *linux_code, char axis) +{ + if (element->relative) + { + sprintf(linux_type,"ev_rel"); + sprintf(linux_code,"rel_%c",axis); + } + else + { + sprintf(linux_type,"ev_abs"); + sprintf(linux_code,"abs_%c",axis); + } +} + +void convertDarwinElementToLinuxTypeCode(pRecElement element, char *linux_type, char *linux_code) +{ + t_int button_offset = 0; + + switch(element->type) + { + case kIOHIDElementTypeInput_Button: + sprintf(linux_type, "ev_key"); + break; + } - return(returnType); + switch (element->usagePage) + { + case kHIDPage_GenericDesktop: + switch (element->usage) + { + case kHIDUsage_GD_X: convertAxis(element, linux_type, linux_code, 'x'); break; + case kHIDUsage_GD_Y: convertAxis(element, linux_type, linux_code, 'y'); break; + case kHIDUsage_GD_Z: convertAxis(element, linux_type, linux_code, 'z'); break; + case kHIDUsage_GD_Rx: convertAxis(element, linux_type, linux_code, 'x'); break; + case kHIDUsage_GD_Ry: convertAxis(element, linux_type, linux_code, 'y'); break; + case kHIDUsage_GD_Rz: convertAxis(element, linux_type, linux_code, 'z'); break; + } + break; + case kHIDPage_Button: + sprintf(linux_type, "ev_key"); + sprintf(linux_code, "btn_%ld", element->usage); + break; + } } /* ============================================================================== */ +/* DARWIN-SPECIFIC SUPPORT FUNCTIONS */ +/* ============================================================================== */ + +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); +} + +/* ============================================================================== */ /* Pd [hid] FUNCTIONS */ /* ============================================================================== */ @@ -135,53 +230,97 @@ t_int hid_output_events(t_hid *x) SInt32 value; pRecDevice pCurrentHIDDevice; pRecElement pCurrentHIDElement; -// char *type = ""; -// char *code = ""; + IOHIDEventStruct event; + char type[256]; + char code[256]; + char event_output_string[256]; t_atom event_data[4]; + int event_counter = 0; + Boolean result; + // look for the right device: pCurrentHIDDevice = HIDGetFirstDevice (); while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=x->x_locID)) pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); if(!pCurrentHIDDevice) return (1); - - /* get the first element */ - pCurrentHIDElement = HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeIO); - /* cycle thru all elements */ - while (pCurrentHIDElement) +// result = HIDGetEvent(pCurrentHIDDevice, (void*) &event); +// if(result) + while( (HIDGetEvent(pCurrentHIDDevice, (void*) &event)) && (event_counter < 64) ) { - value = HIDGetElementValue (pCurrentHIDDevice, pCurrentHIDElement); + value = event.value; + //post("found event: %d",value); + IOHIDElementCookie cookie = (IOHIDElementCookie) event.elementCookie; + + // find the pRecElement using the cookie + pCurrentHIDElement = HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeIO); + 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 ); */ - - /* type */ -// HIDGetTypeName(pCurrentHIDElement->type,type); -// SETSYMBOL(event_data, gensym(type)); - /* code */ -// HIDGetUsageName(pCurrentHIDElement->usagePage, pCurrentHIDElement->usage, code); -// SETSYMBOL(event_data + 1, gensym(code)); - /* value */ -// SETFLOAT(event_data + 2, (t_float)value); - /* time */ - // TODO temp space filler for testing, got to find where I get the event time -// SETFLOAT(event_data + 3, (t_float)value); -// SETFLOAT(event_data + 3, (t_float)(hid_input_event.time).tv_sec); -// outlet_anything(x->x_obj.te_outlet,atom_gensym(event_data),3,event_data+1); - } - pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeIO); +// 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); + + 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; } + DEBUG( + if(event_counter) + post("output %d events",event_counter); + ); +/* /\* get the first element *\/ */ +/* pCurrentHIDElement = HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeIO); */ +/* /\* cycle thru all elements *\/ */ +/* while (pCurrentHIDElement) */ +/* { */ +/* //value = HIDGetElementValue (pCurrentHIDDevice, pCurrentHIDElement); */ + +/* if (pCurrentHIDElement) */ +/* { */ +/* value = HIDGetElementValue (pCurrentHIDDevice, pCurrentHIDElement); */ +/* post("current value: %d", value); */ +/* // 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 ); *\/ */ + +/* /\* type *\/ */ +/* //HIDGetTypeName(pCurrentHIDElement->type,type); */ +/* convertDarwinToLinuxType((IOHIDElementType) pCurrentHIDElement->type, event_output_string); */ +/* SETSYMBOL(event_data, gensym(event_output_string)); */ +/* /\* code *\/ */ +/* HIDGetUsageName(pCurrentHIDElement->usagePage, pCurrentHIDElement->usage, event_output_string); */ +/* SETSYMBOL(event_data + 1, gensym(event_output_string)); */ +/* /\* value *\/ */ +/* SETFLOAT(event_data + 2, (t_float)value); */ +/* /\* time *\/ */ +/* // TODO temp space filler for testing, got to find where I get the event time */ +/* SETFLOAT(event_data + 3, (t_float)value); */ +/* // SETFLOAT(event_data + 3, (t_float)(hid_input_event.time).tv_sec); */ +/* outlet_anything(x->x_obj.te_outlet,atom_gensym(event_data),3,event_data+1); */ +/* } */ +/* pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeIO); */ +/* } */ return (0); } - t_int hid_open_device(t_hid *x, t_int device_number) { DEBUG(post("hid_open_device");); @@ -215,12 +354,15 @@ t_int hid_open_device(t_hid *x, t_int device_number) currentDevice = HIDGetNextDevice(currentDevice); x->x_locID = currentDevice->locID; -// TODO: buildElementList(), outputting text to console -// TODO: queue all elements except absolute axes post("[hid] opened device %d: %s %s", device_number, currentDevice->manufacturer, currentDevice->product); + hid_build_element_list(x); + + HIDQueueDevice(currentDevice); +// TODO: queue all elements except absolute axes + return (0); } @@ -229,8 +371,10 @@ t_int hid_close_device(t_hid *x) { DEBUG(post("hid_close_device");); - post("close_device %d",x->x_device_number); - releaseHIDDevices(); + post("[hid] close_device %d",x->x_device_number); + HIDReleaseAllDeviceQueues(); + HIDReleaseDeviceList(); + gNumberOfHIDDevices = 0; return (0); } @@ -240,7 +384,7 @@ t_int hid_devicelist_refresh(t_hid *x) DEBUG(post("hid_devicelist_refresh");); /* the device list should be refreshed here */ - if ( (prHIDBuildDeviceList()) && (prHIDBuildElementList()) ) + if ( (prHIDBuildDeviceList()) && (prHIDBuildElementList(x)) ) return (0); else return (1); @@ -249,7 +393,7 @@ t_int hid_devicelist_refresh(t_hid *x) /*============================================================================== - * HID UTILIES FUNCTIONS + * HID UTILIES FUNCTIONS FROM SC_HID.cpp *============================================================================== */ @@ -267,12 +411,11 @@ void releaseHIDDevices (void) gNumberOfHIDDevices = 0; } -int prHIDBuildElementList(void) +int prHIDBuildElementList(t_hid *x) { DEBUG(post("prHIDBuildElementList");); int locID = NULL; - int cookieNum = NULL; UInt32 i; pRecElement devElement; pRecDevice pCurrentHIDDevice; @@ -284,7 +427,7 @@ int prHIDBuildElementList(void) // look for the right device using locID pCurrentHIDDevice = HIDGetFirstDevice (); - while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=locID)) + while (pCurrentHIDDevice && (pCurrentHIDDevice->locID != x->x_locID)) pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); if(!pCurrentHIDDevice) return (1); @@ -305,10 +448,8 @@ int prHIDBuildElementList(void) //devstring = newPyrString(g->gc, cstrElementName, 0, true); //SetObject(devElementArray->slots+devElementArray->size++, devstring); //g->gc->GCWrite(devElementArray, (PyrObject*) devstring); - //cookie - post("Cookie: %d %d %d",devElement->cookie,devElement->min,devElement->max); - devElement = HIDGetNextDeviceElement (devElement, kHIDElementTypeInput); + devElement = HIDGetNextDeviceElement (devElement, kHIDElementTypeInput); } return (0); } @@ -536,112 +677,6 @@ void callback (void * target, IOReturn result, void * refcon, void * sender) /* return (0); */ /* } */ - -int prHIDQueueDevice(void) -{ - DEBUG(post("prHIDQueueDevice");); - - int locID = NULL; - int cookieNum = NULL; - - //PyrSlot *a = g->sp - 1; //class - //PyrSlot *b = g->sp; //locID device - //int err = slotIntVal(b, &locID); - //if (err) return err; - //look for the right device: - pRecDevice pCurrentHIDDevice = HIDGetFirstDevice (); - while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=locID)) - pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); - if(!pCurrentHIDDevice) return (1); - HIDQueueDevice(pCurrentHIDDevice); - return (0); -} - - -int prHIDQueueElement(void) -{ - DEBUG(post("prHIDQueueElement");); - - int locID = NULL; - int cookieNum = NULL; - - //PyrSlot *a = g->sp - 2; //class - //PyrSlot *b = g->sp - 1; //locID device - //PyrSlot *c = g->sp; //element cookie - //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) return (1); - HIDQueueElement(pCurrentHIDDevice, pCurrentHIDElement); - return (0); -} - - -int prHIDDequeueElement(void) -{ - DEBUG(post("prHIDDequeueElement");); - - int locID = NULL; - int cookieNum = NULL; - - //PyrSlot *a = g->sp - 2; //class - //PyrSlot *b = g->sp - 1; //locID device - //PyrSlot *c = g->sp; //element cookie - //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); - while (pCurrentHIDElement && (pCurrentHIDElement->cookie != cookie)) - pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeIO); - if(!pCurrentHIDElement) return (1); - HIDDequeueElement(pCurrentHIDDevice, pCurrentHIDElement); - return (0); -} - - -int prHIDDequeueDevice(void) -{ - DEBUG(post("prHIDDequeueDevice");); - - int locID = NULL; - int cookieNum = NULL; - - /* - PyrSlot *a = g->sp - 1; //class - PyrSlot *b = g->sp; //locID device - int err = slotIntVal(b, &locID); - if (err) return err; - */ - //look for the right device: - pRecDevice pCurrentHIDDevice = HIDGetFirstDevice (); - while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=locID)) - pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); - if(!pCurrentHIDDevice) return (1); - HIDDequeueDevice(pCurrentHIDDevice); - return (0); -} - - /* int prHIDStopEventLoop(void) */ /* { */ /* DEBUG(post("prHIDStopEventLoop");); */ @@ -654,19 +689,6 @@ int prHIDDequeueDevice(void) /* this is just a rough sketch */ -/* getEvents(t_hid *x) { */ -/* pRecDevice pCurrentHIDDevice = GetSetCurrentDevice (gWindow); */ -/* pRecElement pCurrentHIDElement = GetSetCurrenstElement (gWindow); */ - -/* // if we have a good device and element which is not a collecion */ -/* if (pCurrentHIDDevice && pCurrentHIDElement && (pCurrentHIDElement->type != kIOHIDElementTypeCollection)) */ -/* { */ -/* SInt32 value = HIDGetElementValue (pCurrentHIDDevice, pCurrentHIDElement); */ -/* SInt32 valueCal = HIDCalibrateValue (value, pCurrentHIDElement); */ -/* SInt32 valueScale = HIDScaleValue (valueCal, pCurrentHIDElement); */ -/* } */ -/* } */ - //void HIDGetUsageName (const long valueUsagePage, const long valueUsage, char * cstrName) char *convertEventsFromDarwinToLinux(pRecElement element) |