From bc023e1557973a838b03760db62d262dcbbe1f5c Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 9 Dec 2007 21:55:47 +0000 Subject: added the ability to set the HID path in the [write( message svn path=/trunk/externals/hcs/; revision=9087 --- usbhid/usbhid-help.pd | 73 ++++++++++++++++++++++++++--------------------- usbhid/usbhid.c | 79 ++++++++++++++++++++++++++------------------------- 2 files changed, 81 insertions(+), 71 deletions(-) (limited to 'usbhid') diff --git a/usbhid/usbhid-help.pd b/usbhid/usbhid-help.pd index 951e58e..6681bf0 100644 --- a/usbhid/usbhid-help.pd +++ b/usbhid/usbhid-help.pd @@ -1,8 +1,8 @@ -#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; +#N canvas 677 22 710 687 10; +#X obj 177 545 usbhid; +#X msg 276 167 close; +#X msg 276 193 reset; +#X msg 289 231 print; #X text 367 72 Gravis/Destroyer Tiltpad; #N canvas 0 22 462 312 buttons 0; #X obj 99 36 inlet; @@ -47,7 +47,7 @@ #X connect 15 0 8 0; #X connect 16 0 9 0; #X restore 115 655 pd buttons test; -#X obj 177 602 unpack float float float float; +#X obj 177 613 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 ; @@ -57,10 +57,10 @@ #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 +#X msg 314 347 debug \$1; +#X obj 314 325 hradio 15 1 0 10 empty empty empty 0 -6 0 8 -262144 -1 -1 0; -#X obj 77 581 print data; +#X obj 77 592 print data; #N canvas 458 151 458 489 parsing 0; #X obj 77 6 inlet; #X obj 80 101 route float symbol; @@ -88,24 +88,24 @@ #X connect 9 1 10 0; #X connect 10 0 2 1; #X connect 10 1 11 0; -#X restore 276 558 pd parsing; +#X restore 271 587 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 msg 286 212 refresh; +#X text 351 213 reinit and refresh device list; +#X text 325 193 resets device (don't really know what that does tho) ; -#X obj 221 559 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 +#X obj 216 588 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1; -#X obj 221 537 route open device; +#X obj 216 566 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 294 256 descriptor; +#X text 373 256 get descriptor; +#X msg 301 290 descriptor 1 30 1 31 1 38; +#X text 480 289 [descriptor page# usage# ...(; +#X text 300 274 for writing to the device:; #X msg 75 308 set 2; -#X text 233 522 <- status outlet; -#X text 71 523 data outlet ->; +#X text 228 551 <- status outlet; +#X text 66 552 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; @@ -115,14 +115,18 @@ #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 +#X obj 332 453 int; +#X obj 335 434 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 obj 357 591 print ELSE; +#X msg 421 501 write 0x0001 0x0004 5; +#X msg 419 521 write 0xff00 0x0001 5; +#X msg 419 541 write 0xff00 0x0002 5; +#X obj 320 395 int; +#X obj 323 376 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 10 -262144 +-1 -1 0 1; +#X msg 320 415 write 0x01 0x04 0x0 0x0 0xff00 0x02 \$1; +#X msg 332 473 write 0x01 0x04 0x00 0x00 0xff00 0x01 \$1; #X connect 0 0 6 0; #X connect 0 0 17 0; #X connect 0 1 24 0; @@ -142,7 +146,7 @@ #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 24 2 45 0; #X connect 25 0 0 0; #X connect 26 0 0 0; #X connect 28 0 0 0; @@ -152,9 +156,12 @@ #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 43 0 52 0; #X connect 44 0 43 0; -#X connect 45 0 44 0; +#X connect 46 0 0 0; #X connect 47 0 0 0; #X connect 48 0 0 0; -#X connect 49 0 0 0; +#X connect 49 0 51 0; +#X connect 50 0 49 0; +#X connect 51 0 0 0; +#X connect 52 0 0 0; diff --git a/usbhid/usbhid.c b/usbhid/usbhid.c index da8d6b6..ee22c8f 100644 --- a/usbhid/usbhid.c +++ b/usbhid/usbhid.c @@ -507,42 +507,45 @@ static void usbhid_set(t_usbhid *x, t_float length_arg) /* -------------------------------------------------------------------------- */ -static void usbhid_write(t_usbhid *x, t_symbol *usage_page_symbol, - t_symbol *usage_symbol, t_float value) +static void usbhid_write(t_usbhid *x, t_symbol *s, int argc, t_atom *argv) { - 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(x->debug_level) post("usbhid_write"); + int i; +// const int path[] = {0x000c0001, 0x000c0001}; +// int path[] = {0xff000002}; + int *path; +// unsigned int const depth = 2; // number of 32bit chunks in the path +// unsigned char const SEND_PACKET_LEN = 2; // number of bytes in packet +// char const PACKET[] = { 0x50 }; // the data to write + unsigned int depth; // number of 32bit chunks in the path + unsigned char SEND_PACKET_LEN; // number of bytes in packet + char PACKET[] = { 0x50 }; // the data to write 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; + + path = getbytes(sizeof(int) * (argc - 1)); + depth = (argc - 1) / 2; + for(i = 0; i < argc - 1; ++i) + { + path[(i+1)/2] = (strtol(atom_getsymbol(argv + i)->s_name, NULL, 16) << 16) + + (strtol(atom_getsymbol(argv + i + 1)->s_name, NULL, 16) & 0x0000ffff); + ++i; + } + SEND_PACKET_LEN = 1; + PACKET[0] = (unsigned short) atom_getfloat(argv + argc - 1); + post("depth: %d SEND_PACKET_LEN: %d PACKET[0]: %d", + depth, SEND_PACKET_LEN, PACKET[0]); + for(i = 0; i < (argc - 1) / 2; ++i) + { + post("path %d: 0x%08x", i, path[i]); + } + x->x_hid_return = hid_set_output_report(x->x_hidinterface, - &path_element, - depth, - PACKET, + path, depth, PACKET, SEND_PACKET_LEN); if (x->x_hid_return != HID_RET_SUCCESS) { @@ -611,6 +614,7 @@ static void usbhid_get_descriptor(t_usbhid *x) t_int input_size = 0; t_int output_size = 0; t_int feature_size = 0; + char buf[MAXPDSTRING]; if (!hid_is_opened(x->x_hidinterface)) { error("[usbget] cannot dump tree of unopened HIDinterface."); @@ -639,17 +643,16 @@ static void usbhid_get_descriptor(t_usbhid *x) } add_float_to_output(x, x->x_hidinterface->hid_data->Size); add_float_to_output(x, x->x_hidinterface->hid_data->Offset); + add_symbol_to_output(x, gensym("path")); + post("path"); for (i = 0; i < x->x_hidinterface->hid_data->Path.Size; ++i) { - add_symbol_to_output(x, gensym("usage")); - add_float_to_output(x, x->x_hidinterface->hid_data->Path.Node[i].UPage); - add_float_to_output(x, x->x_hidinterface->hid_data->Path.Node[i].Usage); - post("page: 0x%04x\t%d\t\tusage: 0x%04x\t%d", - x->x_hidinterface->hid_data->Path.Node[i].UPage, - x->x_hidinterface->hid_data->Path.Node[i].UPage, - x->x_hidinterface->hid_data->Path.Node[i].Usage, - x->x_hidinterface->hid_data->Path.Node[i].Usage); + sprintf(buf, "0x%04x", x->x_hidinterface->hid_data->Path.Node[i].UPage); + add_symbol_to_output(x, gensym(buf)); + sprintf(buf, "0x%04x", x->x_hidinterface->hid_data->Path.Node[i].Usage); + add_symbol_to_output(x, gensym(buf)); + post("0x%04x%04x",x->x_hidinterface->hid_data->Path.Node[i].UPage, + x->x_hidinterface->hid_data->Path.Node[i].Usage); } - post("type: 0x%02x\n", x->x_hidinterface->hid_data->Type); add_symbol_to_output(x, gensym("logical")); add_float_to_output(x, x->x_hidinterface->hid_data->LogMin); add_float_to_output(x, x->x_hidinterface->hid_data->LogMax); @@ -834,7 +837,7 @@ void usbhid_setup(void) 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); + A_GIMME, 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