From 4831402603a1a78939216974c09dfa45e1d7c03d Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 30 Jul 2007 22:50:13 +0000 Subject: got strtol working (baby steps), but I can't find the magic combo to get output working svn path=/trunk/externals/hcs/; revision=8293 --- usbhid/Makefile | 15 ++++- usbhid/usbhid-help.pd | 149 +++++++++++++++++++++++++++----------------------- usbhid/usbhid.c | 64 ++++++++++++++++++++-- 3 files changed, 155 insertions(+), 73 deletions(-) diff --git a/usbhid/Makefile b/usbhid/Makefile index 4b68f67..01a6fee 100644 --- a/usbhid/Makefile +++ b/usbhid/Makefile @@ -13,6 +13,17 @@ clean: test_locations: make -C $(EXTERNALS_ROOT) test_locations +# for emacs etags: - etags *.[ch] ../../../pd/src/*.[ch] libhid-svn/*/*.? \ - /usr/include/*.h /usr/include/sys/*.h + etags --language=c *.[ch] ../../../pd/src/*.[ch] \ + /usr/include/*.h /usr/include/sys/*.h \ + /sw/include/*.h /sw/include/*/*.h \ + libhid-svn/*/*.? + +#etags_Darwin: +# etags --append /sw/include/*.h /sw/include/*/*.h + +etags_Linux: + etags --append libhid-svn/*/*.? + + diff --git a/usbhid/usbhid-help.pd b/usbhid/usbhid-help.pd index 1f85b95..951e58e 100644 --- a/usbhid/usbhid-help.pd +++ b/usbhid/usbhid-help.pd @@ -1,10 +1,9 @@ -#N canvas 127 169 633 586 10; -#X obj 132 406 usbhid; -#X msg 194 120 close; -#X msg 194 146 reset; -#X text 240 337 GARBAGE FOR TESTING; -#X msg 207 184 print; -#X text 317 72 Gravis/Destroyer Tiltpad; +#N canvas 5 85 797 703 10; +#X obj 182 516 usbhid; +#X msg 284 190 close; +#X msg 284 216 reset; +#X msg 297 254 print; +#X text 367 72 Gravis/Destroyer Tiltpad; #N canvas 0 22 462 312 buttons 0; #X obj 99 36 inlet; #X obj 63 108 & 1; @@ -21,7 +20,7 @@ #X obj 223 130 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 32; #X obj 263 130 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 -1; +64; #X obj 303 130 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 128; #X obj 93 108 & 2; @@ -47,21 +46,21 @@ #X connect 14 0 7 0; #X connect 15 0 8 0; #X connect 16 0 9 0; -#X restore 65 545 pd buttons test; -#X obj 127 492 unpack float float float float; -#X obj 44 113 metro 400; -#X obj 46 87 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +#X restore 115 655 pd buttons test; +#X obj 177 602 unpack float float float float; +#X obj 94 183 metro 400; +#X obj 96 157 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 ; -#X floatatom 186 529 5 0 0 0 - - -; -#X floatatom 256 530 5 0 0 0 - - -; -#X floatatom 336 525 5 0 0 0 - - -; -#X msg 20 5 open vendorId productId; -#X msg 176 71 open 0x047D 0x4008; -#X floatatom 125 526 5 0 0 0 - - -; -#X msg 239 303 debug \$1; -#X obj 239 281 hradio 15 1 0 10 empty empty empty 0 -6 0 8 -262144 +#X floatatom 236 639 5 0 0 0 - - -; +#X floatatom 306 640 5 0 0 0 - - -; +#X floatatom 386 635 5 0 0 0 - - -; +#X msg 70 5 open vendorId productId; +#X msg 226 71 open 0x047D 0x4008; +#X floatatom 175 636 5 0 0 0 - - -; +#X msg 329 373 debug \$1; +#X obj 329 351 hradio 15 1 0 10 empty empty empty 0 -6 0 8 -262144 -1 -1 0; -#X obj 27 471 print data; +#X obj 77 581 print data; #N canvas 458 151 458 489 parsing 0; #X obj 77 6 inlet; #X obj 80 101 route float symbol; @@ -89,57 +88,73 @@ #X connect 9 1 10 0; #X connect 10 0 2 1; #X connect 10 1 11 0; -#X restore 226 448 pd parsing; -#X text 8 152 how many bytes to read; -#X msg 204 165 refresh; -#X text 269 166 reinit and refresh device list; -#X text 243 146 resets device (don't really know what that does tho) +#X restore 276 558 pd parsing; +#X text 58 222 how many bytes to read; +#X msg 294 235 refresh; +#X text 359 236 reinit and refresh device list; +#X text 333 216 resets device (don't really know what that does tho) ; -#X obj 171 449 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +#X obj 221 559 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1; -#X obj 171 427 route open device; -#X msg 44 134 get 4; -#X msg 82 167 get 2; -#X msg 212 209 descriptor; -#X text 291 209 get descriptor; -#X msg 219 243 descriptor 1 30 1 31 1 38; -#X text 398 242 [descriptor page# usage# ...(; -#X text 218 227 for writing to the device:; -#X msg 25 238 set 2; -#X msg 237 353 close \, open 0x045e 0x0039 \, descriptor; -#X text 183 412 <- status outlet; -#X text 21 413 data outlet ->; -#X msg 163 49 open 0x046d 0xc01d; -#X text 305 49 Logitech USB-PS/2 Optical Mouse; -#X msg 156 25 open 0x1043 0x0015; -#X text 294 26 CUI v1.0; -#X msg 181 96 open 0x077d 0x0410; -#X text 311 97 Griffin Technology PowerMate; -#X connect 0 0 7 0; -#X connect 0 0 18 0; -#X connect 0 1 25 0; +#X obj 221 537 route open device; +#X msg 132 237 get 2; +#X msg 302 279 descriptor; +#X text 381 279 get descriptor; +#X msg 309 313 descriptor 1 30 1 31 1 38; +#X text 488 312 [descriptor page# usage# ...(; +#X text 308 297 for writing to the device:; +#X msg 75 308 set 2; +#X text 233 522 <- status outlet; +#X text 71 523 data outlet ->; +#X msg 213 49 open 0x046d 0xc01d; +#X text 355 49 Logitech USB-PS/2 Optical Mouse; +#X msg 206 25 open 0x1043 0x0015; +#X text 344 26 CUI v1.0; +#X msg 231 96 open 0x077d 0x0410; +#X text 361 97 Griffin Technology PowerMate; +#X text 375 125 Logitech RumblePad 2 USB; +#X msg 253 125 open 0x046d 0xc218; +#X msg 94 204 get 8; +#X msg 392 431 write 0x0 0x0 \$1; +#X obj 390 409 int; +#X obj 394 387 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 10 -262144 +-1 -1 0 1; +#X obj 362 562 print ELSE; +#X msg 451 459 write 0x0001 0x0004 5; +#X msg 449 479 write 0xff00 0x0001 5; +#X msg 449 499 write 0xff00 0x0002 5; +#X connect 0 0 6 0; +#X connect 0 0 17 0; +#X connect 0 1 24 0; #X connect 1 0 0 0; #X connect 2 0 0 0; -#X connect 4 0 0 0; -#X connect 7 0 6 0; -#X connect 7 0 15 0; -#X connect 7 1 10 0; -#X connect 7 2 11 0; -#X connect 7 3 12 0; -#X connect 8 0 26 0; -#X connect 9 0 8 0; -#X connect 14 0 0 0; -#X connect 16 0 0 0; -#X connect 17 0 16 0; -#X connect 21 0 0 0; -#X connect 25 0 24 0; -#X connect 25 1 19 0; +#X connect 3 0 0 0; +#X connect 6 0 5 0; +#X connect 6 0 14 0; +#X connect 6 1 9 0; +#X connect 6 2 10 0; +#X connect 6 3 11 0; +#X connect 7 0 42 0; +#X connect 8 0 7 0; +#X connect 13 0 0 0; +#X connect 15 0 0 0; +#X connect 16 0 15 0; +#X connect 20 0 0 0; +#X connect 24 0 23 0; +#X connect 24 1 18 0; +#X connect 24 2 46 0; +#X connect 25 0 0 0; #X connect 26 0 0 0; -#X connect 27 0 0 0; #X connect 28 0 0 0; -#X connect 30 0 0 0; -#X connect 33 0 0 0; +#X connect 31 0 0 0; #X connect 34 0 0 0; -#X connect 37 0 0 0; -#X connect 39 0 0 0; +#X connect 36 0 0 0; +#X connect 38 0 0 0; #X connect 41 0 0 0; +#X connect 42 0 0 0; +#X connect 43 0 0 0; +#X connect 44 0 43 0; +#X connect 45 0 44 0; +#X connect 47 0 0 0; +#X connect 48 0 0 0; +#X connect 49 0 0 0; diff --git a/usbhid/usbhid.c b/usbhid/usbhid.c index 14b6ee2..da8d6b6 100644 --- a/usbhid/usbhid.c +++ b/usbhid/usbhid.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include "m_pd.h" @@ -486,23 +488,75 @@ static void usbhid_set(t_usbhid *x, t_float length_arg) error("[usbhid] device not open, can't set data"); return; } - x->x_hid_return = hid_set_output_report(x->x_hidinterface, +/* x->x_hid_return = hid_set_output_report(x->x_hidinterface, x->x_write_elements, x->x_write_element_count, packet, length_arg); +*/ if (x->x_hid_return != HID_RET_SUCCESS) { error("[usbhid] hid_get_input_report failed with return code %d\n", x->x_hid_return); reset_output(x); add_float_to_output(x, x->x_hid_return); - outlet_anything(x->x_status_outlet, gensym("setError"), + outlet_anything(x->x_status_outlet, gensym("set_error"), x->output_count, x->output); } } +/* -------------------------------------------------------------------------- */ +static void usbhid_write(t_usbhid *x, t_symbol *usage_page_symbol, + t_symbol *usage_symbol, t_float value) +{ + if(x->debug_level) post("usbhid_set"); +// const char* path[] = {0x00010004, 0xff000002}; + long path_element; + int path[] = {0xff000002}; + unsigned int const depth = 1; + unsigned char const SEND_PACKET_LEN = 1; + char const PACKET[] = { 0x50 }; + + if ( !hid_is_opened(x->x_hidinterface) ) + { + error("[usbhid] device not open, can't set data"); + return; + } + path_element = (strtol(usage_page_symbol->s_name, NULL, 16) << 16) + + (strtol(usage_symbol->s_name, NULL, 16) & 0x0000ffff); + if (path_element == 0) + switch (errno) + { + case EINVAL: + post("strtol EINVAL error %d", errno); + break; + case ERANGE: + post("strtol ERANGE error %d", errno); + break; + default: + post("strtol error %d", errno); + } + post("path: 0x%08x", path_element); + path[0] = path_element; + x->x_hid_return = hid_set_output_report(x->x_hidinterface, + &path_element, + depth, + PACKET, + SEND_PACKET_LEN); + if (x->x_hid_return != HID_RET_SUCCESS) + { + error("[usbhid] hid_set_output_report failed with return code %d", + x->x_hid_return); + reset_output(x); + add_float_to_output(x, x->x_hid_return); + outlet_anything(x->x_status_outlet, gensym("get_error"), + x->output_count, x->output); + } + post("wrote"); +} + + /* -------------------------------------------------------------------------- */ /* reinit libhid to get update the list of attached devices */ static void usbhid_refresh(t_usbhid *x) @@ -775,10 +829,12 @@ void usbhid_setup(void) A_DEFFLOAT,0); class_addmethod(usbhid_class,(t_method) usbhid_descriptor,gensym("descriptor"), A_GIMME,0); - class_addmethod(usbhid_class,(t_method) usbhid_set,gensym("set"), - A_DEFFLOAT,0); class_addmethod(usbhid_class,(t_method) usbhid_get,gensym("get"), A_DEFFLOAT,0); + class_addmethod(usbhid_class,(t_method) usbhid_set,gensym("set"), + A_DEFFLOAT,0); + class_addmethod(usbhid_class,(t_method) usbhid_write,gensym("write"), + A_DEFSYM, A_DEFSYM, A_DEFFLOAT, 0); class_addmethod(usbhid_class,(t_method) usbhid_open,gensym("open"), A_DEFSYM,A_DEFSYM,0); class_addmethod(usbhid_class,(t_method) usbhid_close,gensym("close"),0); -- cgit v1.2.1