From bf05b861887b801816c0493bdc24932582623cda Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 5 May 2008 14:51:12 +0000 Subject: very basic output using Apple HID Utilities to a CUI IO v1.0 firmware, I got the LED to toggle properly svn path=/trunk/externals/io/hidio/; revision=9764 --- Makefile | 2 ++ hidio-help.pd | 80 +++++++++++++++++++++++++--------------------------------- hidio_darwin.c | 34 +++++++++++++++++-------- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 98be310..0c2f77c 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,8 @@ etags_Darwin: /System/Library/Frameworks/CoreServices.framework/Headers/*.h \ /System/Library/Frameworks/IOKit.framework/Headers/*.[ch] \ /System/Library/Frameworks/IOKit.framework/Headers/hid*/*.[ch] \ + /Users/hans/Documents/Research/HID/example\ code/CrossHID/*/*.h \ + /Users/hans/Documents/Research/HID/example\ code/CrossHID/*/*.cpp \ /usr/include/mach/*.h etags_Linux: diff --git a/hidio-help.pd b/hidio-help.pd index f1b0c7c..c97aeda 100644 --- a/hidio-help.pd +++ b/hidio-help.pd @@ -1,4 +1,4 @@ -#N canvas 637 32 886 611 10; +#N canvas 726 139 886 611 10; #X floatatom 27 445 5 0 0 0 - - -; #X floatatom 83 445 5 0 0 0 - - -; #X obj 191 164 tgl 35 0 empty empty empty 0 -6 0 8 -24198 -1 -1 0 25 @@ -9,9 +9,9 @@ #X obj 2 2 cnv 15 900 20 empty empty [hidio] 2 11 1 18 -233017 -66577 0; #X text 224 324 outlet message format:; -#X msg 374 140 close; -#X msg 374 119 refresh; -#X text 435 117 refresh device list; +#X msg 374 130 close; +#X msg 374 109 refresh; +#X text 435 107 refresh device list; #X text 537 487 For more info:; #X text 266 557 released under the GNU GPL; #X text 472 544 $Revision: 1.6 $$Date: 2007-07-26 07:31:38 $; @@ -223,9 +223,9 @@ of it could change without notice !!!; -66577 0; #X restore 698 114 pd Event_Values; #X floatatom 140 445 5 0 0 0 - - -; -#X msg 374 161 print; -#X text 437 141 close the device; -#X text 437 162 print the device and element lists; +#X msg 374 151 print; +#X text 437 131 close the device; +#X text 437 152 print the device and element lists; #X text 9 212 Any non-zero value starts polling \,; #X text 8 225 0 stops the polling. If the number; #X text 9 238 is greater than 1 \, then the poll; @@ -268,7 +268,7 @@ of it could change without notice !!!; #X obj 459 508 tgl 25 0 empty empty empty 0 -6 0 8 -195568 -1 -1 0 66455; #X msg 25 155 debug 9; -#X msg 298 145 info; +#X msg 298 135 info; #N canvas 743 25 411 235 see 0; #N canvas 108 318 543 264 route 0; #X obj 27 14 inlet; @@ -422,10 +422,10 @@ IDs (it is not case sensitive):; #X coords 0 -1 1 1 165 17 1 60 60; #X restore 25 134 pd serin; #N canvas 162 133 570 420 serin 0; -#X obj 286 61 cnv 15 30 15 empty \$0-open-canvas 2 4 8 0 14 -233017 +#X obj 286 61 cnv 15 30 15 empty \$0-open-canvas 0 4 8 0 14 -233017 -1 0; #X obj 60 61 hradio 15 1 1 15 empty empty empty 0 -6 0 8 -225271 -1 --1 2; +-1 0; #X obj 60 13 inlet; #X msg 200 202 label \$1; #X obj 200 180 makefilename %d; @@ -448,9 +448,9 @@ IDs (it is not case sensitive):; #X connect 9 0 7 0; #X connect 10 0 8 0; #X coords 0 -1 1 1 257 17 1 60 60; -#X restore 262 93 pd serin; +#X restore 262 83 pd serin; #X obj 646 486 pddp/open all_about_hid; -#X obj 306 235 hidio; +#X obj 306 244 hidio; #X obj 226 290 flatspace/prepend set; #X obj 544 315 unpack symbol symbol float float; #X floatatom 683 336 2 0 0 1 instance - -; @@ -485,7 +485,7 @@ i_key j_key k_key l_key m_key n_key o_key p_key; #X obj 189 192 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X obj 292 122 spigot; -#X obj 333 99 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +#X obj 333 99 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; #X obj 354 45 inlet; #X obj 290 162 print RAW; @@ -502,40 +502,30 @@ i_key j_key k_key l_key m_key n_key o_key p_key; #X connect 10 0 9 0; #X restore 408 294 pd raw; #X floatatom 63 401 6 0 0 0 - - -; -#X obj 455 295 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 -1; -#X msg 262 114 open 2; -#N canvas 0 0 450 300 output 1; -#X obj 170 265 outlet; -#X msg 228 233 write 0x11 0x01 0 \$1; -#X obj 228 212 tgl 15 0 empty empty empty 0 -6 0 10 -262144 -1 -1 0 -1; -#X obj 213 171 tgl 15 0 empty empty empty 0 -6 0 10 -262144 -1 -1 0 +#X obj 455 295 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; -#X msg 213 192 write 0x11 0x00 0 \$1; -#X text 344 190 numlock; -#X text 359 231 capslock; -#X msg 163 134 write 0x15 \$1 0 \$2; -#X obj 161 97 pack symbol float; -#X symbolatom 171 65 10 0 0 0 - - -; -#X obj 151 40 makefilename 0x%d; -#X obj 154 13 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 10 -262144 --1 -1 1000 1; -#X obj 260 68 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 10 -262144 --1 -1 1200 1; -#X floatatom 277 89 5 0 0 0 - - -; -#X connect 1 0 0 0; -#X connect 2 0 1 0; -#X connect 3 0 4 0; -#X connect 4 0 0 0; +#X msg 262 104 open 0; +#N canvas 121 220 450 300 output 1; +#X obj 93 235 outlet; +#X obj 57 71 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1 +; +#X msg 112 70 255; +#X obj 108 112 pack 0 16; +#X obj 159 92 + 16; +#X obj 157 68 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144 -1 +-1 0; +#X floatatom 171 114 5 0 0 0 - - -; +#X msg 108 143 write 0xFACE 0xFACE \$2 \$1; +#X obj 125 175 pddp/print; +#X connect 1 0 3 0; +#X connect 2 0 3 0; +#X connect 3 0 7 0; +#X connect 4 0 3 1; +#X connect 4 0 6 0; +#X connect 5 0 4 0; #X connect 7 0 0 0; -#X connect 8 0 7 0; -#X connect 10 0 9 0; -#X connect 10 0 8 0; -#X connect 11 0 10 0; -#X connect 12 0 8 1; -#X connect 12 0 13 0; -#X restore 372 210 pd output support; +#X connect 7 0 8 0; +#X restore 373 211 pd output support; #X connect 2 0 60 0; #X connect 8 0 60 0; #X connect 9 0 60 0; diff --git a/hidio_darwin.c b/hidio_darwin.c index 9712036..d44f121 100644 --- a/hidio_darwin.c +++ b/hidio_darwin.c @@ -98,7 +98,7 @@ static char *convertEventsFromDarwinToLinux(pRecElement element); static void convert_axis_to_symbols(pRecElement pCurrentHIDElement, t_hid_element *new_element, int array_index) { - if (pCurrentHIDElement->relative) + if (pCurrentHIDElement->relative) { new_element->type = ps_relative; new_element->name = relative_symbols[array_index]; @@ -395,7 +395,7 @@ static void hidio_build_element_list(t_hidio *x) pRecElement pCurrentHIDElement; pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number]; t_hid_element *new_element; - + element_count[x->x_device_number] = 0; if( HIDIsValidDevice(pCurrentHIDDevice) ) { @@ -403,8 +403,7 @@ static void hidio_build_element_list(t_hidio *x) * try queuing the whole device, then removing specific elements from * the queue */ HIDQueueDevice(pCurrentHIDDevice); - pCurrentHIDElement = HIDGetFirstDeviceElement( pCurrentHIDDevice, - kHIDElementTypeInput ); + pCurrentHIDElement = HIDGetFirstDeviceElement( pCurrentHIDDevice, kHIDElementTypeIO ); /* TODO: axes should be the first elements in the array since they * produce many more events than buttons. This will save loop cycles @@ -476,7 +475,7 @@ static void hidio_build_element_list(t_hidio *x) pCurrentHIDElement->min,pCurrentHIDElement->max); element[x->x_device_number][element_count[x->x_device_number]] = new_element; ++element_count[x->x_device_number]; - pCurrentHIDElement = HIDGetNextDeviceElement(pCurrentHIDElement, kHIDElementTypeInput); + pCurrentHIDElement = HIDGetNextDeviceElement(pCurrentHIDElement, kHIDElementTypeIO); } } } @@ -652,7 +651,7 @@ void hidio_platform_specific_info(t_hidio *x) void hidio_get_events(t_hidio *x) { - unsigned int i,j; + unsigned int i; pRecDevice pCurrentHIDDevice; t_hid_element *current_element; IOHIDEventStruct event; @@ -676,12 +675,13 @@ void hidio_get_events(t_hidio *x) // debug_post(LOG_DEBUG,"output this: %s %s %d prev %d",current_element->type->s_name, // current_element->name->s_name, current_element->value, // current_element->previous_value); - timestamp = * (uint64_t *) &(event.timestamp); - difference = calculate_event_latency(timestamp,0); - debug_post(LOG_DEBUG,"timestamp: %llu %llu", timestamp, difference); - now = mach_absolute_time(); + timestamp = * (uint64_t *) &(event.timestamp); /* // temp hack for measuring latency + difference = calculate_event_latency(timestamp,0); + debug_post(LOG_DEBUG,"timestamp: %llu %llu", timestamp, difference); + now = mach_absolute_time(); + difference = calculate_event_latency(now, timestamp); if( latency_i < LATENCY_MAX) { @@ -717,7 +717,19 @@ void hidio_write_event(t_hidio *x, t_symbol *type, t_symbol *code, t_float instance, t_float value) { debug_post(LOG_DEBUG,"hidio_write_event"); - + IOHIDEventStruct event; + pRecDevice pCurrentHIDDevice = device_pointer[x->x_device_number]; + pRecElement elem = HIDGetFirstDeviceElement(pCurrentHIDDevice, kHIDElementTypeOutput); + int cookie = (int) instance; + while(elem && ((int)elem->cookie != cookie)) + elem = HIDGetNextDeviceElement(elem, kHIDElementTypeOutput); + + post("element usage page and usage: 0x%04x 0x%04x", elem->usagePage, elem->usage); + event.elementCookie = (IOHIDElementCookie)cookie; + event.value = (SInt32)value; + post("elem->cookie, cookie, event.value, value: %d %d %d %f", + elem->cookie, cookie, event.value, value); + HIDSetElementValue(pCurrentHIDDevice, elem, &event); } -- cgit v1.2.1