aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usbhid/Makefile3
-rw-r--r--usbhid/usbhid-help.pd75
-rw-r--r--usbhid/usbhid.c61
3 files changed, 74 insertions, 65 deletions
diff --git a/usbhid/Makefile b/usbhid/Makefile
index 576ff87..4b68f67 100644
--- a/usbhid/Makefile
+++ b/usbhid/Makefile
@@ -14,4 +14,5 @@ test_locations:
make -C $(EXTERNALS_ROOT) test_locations
etags:
- etags *.[ch] ~/cvs/pure-data/pd/src/*.[ch] /usr/include/*.h /usr/include/sys/*.h
+ etags *.[ch] ../../../pd/src/*.[ch] libhid-svn/*/*.? \
+ /usr/include/*.h /usr/include/sys/*.h
diff --git a/usbhid/usbhid-help.pd b/usbhid/usbhid-help.pd
index 6152ced..1f85b95 100644
--- a/usbhid/usbhid-help.pd
+++ b/usbhid/usbhid-help.pd
@@ -1,9 +1,9 @@
-#N canvas 339 22 633 553 10;
-#X obj 132 376 usbhid;
-#X msg 184 91 close;
-#X msg 184 117 reset;
-#X text 240 307 GARBAGE FOR TESTING;
-#X msg 197 155 print;
+#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 0 22 462 312 buttons 0;
#X obj 99 36 inlet;
@@ -47,21 +47,21 @@
#X connect 14 0 7 0;
#X connect 15 0 8 0;
#X connect 16 0 9 0;
-#X restore 65 515 pd buttons test;
-#X obj 127 462 unpack float float float float;
-#X obj 44 83 metro 400;
-#X obj 46 57 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
+#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 floatatom 186 499 5 0 0 0 - - -;
-#X floatatom 256 500 5 0 0 0 - - -;
-#X floatatom 336 495 5 0 0 0 - - -;
+#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 496 5 0 0 0 - - -;
-#X msg 239 273 debug \$1;
-#X obj 239 251 hradio 15 1 0 10 empty empty empty 0 -6 0 8 -262144
--1 -1 9;
-#X obj 27 441 print data;
+#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
+-1 -1 0;
+#X obj 27 471 print data;
#N canvas 458 151 458 489 parsing 0;
#X obj 77 6 inlet;
#X obj 80 101 route float symbol;
@@ -89,30 +89,32 @@
#X connect 9 1 10 0;
#X connect 10 0 2 1;
#X connect 10 1 11 0;
-#X restore 226 418 pd parsing;
-#X text 8 122 how many bytes to read;
-#X msg 194 136 refresh;
-#X text 259 137 reinit and refresh device list;
-#X text 233 117 resets device (don't really know what that does tho)
+#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 obj 171 419 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+#X obj 171 449 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
1;
-#X obj 171 397 route open device;
-#X msg 44 104 get 4;
-#X msg 82 137 get 2;
-#X msg 212 179 descriptor;
-#X text 291 179 get descriptor;
-#X msg 219 213 descriptor 1 30 1 31 1 38;
-#X text 398 212 [descriptor page# usage# ...(;
-#X text 218 197 for writing to the device:;
-#X msg 25 208 set 2;
-#X msg 237 323 close \, open 0x045e 0x0039 \, descriptor;
-#X text 183 382 <- status outlet;
-#X text 21 383 data outlet ->;
+#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;
@@ -140,3 +142,4 @@
#X connect 34 0 0 0;
#X connect 37 0 0 0;
#X connect 39 0 0 0;
+#X connect 41 0 0 0;
diff --git a/usbhid/usbhid.c b/usbhid/usbhid.c
index 5fc069f..14b6ee2 100644
--- a/usbhid/usbhid.c
+++ b/usbhid/usbhid.c
@@ -294,7 +294,8 @@ static t_int get_device_string(HIDInterface *hidif, char *device_string)
{
int length;
t_int ret = 0;
- char buffer[STRING_BUFFER_LENGTH];
+ char buffer[STRING_BUFFER_LENGTH] = "";
+ char return_buffer[STRING_BUFFER_LENGTH] = "";
if ( !hid_is_opened(hidif) )
return(0);
@@ -306,8 +307,8 @@ static t_int get_device_string(HIDInterface *hidif, char *device_string)
STRING_BUFFER_LENGTH);
if (length > 0)
{
- strncat(device_string, buffer, STRING_BUFFER_LENGTH - strlen(device_string));
- strncat(device_string, " ",1);
+ strncat(return_buffer, buffer, STRING_BUFFER_LENGTH - strlen(device_string));
+ strncat(return_buffer, " ",1);
ret = 1;
}
else
@@ -323,8 +324,8 @@ static t_int get_device_string(HIDInterface *hidif, char *device_string)
STRING_BUFFER_LENGTH);
if (length > 0)
{
- strncat(device_string, buffer, STRING_BUFFER_LENGTH - strlen(device_string));
- strncat(device_string, " ",1);
+ strncat(return_buffer, buffer, STRING_BUFFER_LENGTH - strlen(device_string));
+ strncat(return_buffer, " ",1);
ret = 1;
}
else
@@ -339,11 +340,14 @@ static t_int get_device_string(HIDInterface *hidif, char *device_string)
buffer,
STRING_BUFFER_LENGTH);
if (length > 0)
- strncat(device_string, buffer, STRING_BUFFER_LENGTH - strlen(device_string));
+ strncat(return_buffer, buffer, STRING_BUFFER_LENGTH - strlen(device_string));
else
post("(unable to fetch product string)");
}
-
+
+ if (return_buffer)
+ strncpy(device_string, return_buffer, STRING_BUFFER_LENGTH);
+
return ret;
}
@@ -435,20 +439,21 @@ static void usbhid_open(t_usbhid *x, t_symbol *vendor_id_hex, t_symbol *product_
/* -------------------------------------------------------------------------- */
-static void usbhid_set(t_usbhid *x, t_float length_arg)
+static void usbhid_get(t_usbhid *x, t_float length_arg)
{
- if(x->debug_level) post("usbhid_set");
+ if(x->debug_level) post("usbhid_get");
+ int i;
int packet_bytes = (int)length_arg;
char packet[packet_bytes];
if ( !hid_is_opened(x->x_hidinterface) )
{
- error("[usbhid] device not open, can't set data");
+ error("[usbhid] device not open, can't get data");
return;
}
- x->x_hid_return = hid_set_output_report(x->x_hidinterface,
- x->x_write_elements,
- x->x_write_element_count,
+ x->x_hid_return = hid_get_input_report(x->x_hidinterface,
+ NULL,
+ x->x_read_element_count,
packet,
length_arg);
if (x->x_hid_return != HID_RET_SUCCESS)
@@ -457,27 +462,33 @@ static void usbhid_set(t_usbhid *x, t_float length_arg)
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("getError"),
x->output_count, x->output);
}
+
+ reset_output(x);
+ for(i=0; i<packet_bytes; ++i)
+ add_float_to_output(x,packet[i]);
+ outlet_list(x->x_data_outlet, &s_list, x->output_count, x->output);
+ post("x->x_read_elements %d",x->x_read_elements);
}
+
/* -------------------------------------------------------------------------- */
-static void usbhid_get(t_usbhid *x, t_float length_arg)
+static void usbhid_set(t_usbhid *x, t_float length_arg)
{
- if(x->debug_level) post("usbhid_get");
- int i;
+ if(x->debug_level) post("usbhid_set");
int packet_bytes = (int)length_arg;
char packet[packet_bytes];
if ( !hid_is_opened(x->x_hidinterface) )
{
- error("[usbhid] device not open, can't get data");
+ error("[usbhid] device not open, can't set data");
return;
}
- x->x_hid_return = hid_get_input_report(x->x_hidinterface,
- NULL,
- x->x_read_element_count,
+ 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)
@@ -486,15 +497,9 @@ static void usbhid_get(t_usbhid *x, t_float length_arg)
x->x_hid_return);
reset_output(x);
add_float_to_output(x, x->x_hid_return);
- outlet_anything(x->x_status_outlet, gensym("getError"),
+ outlet_anything(x->x_status_outlet, gensym("setError"),
x->output_count, x->output);
}
-
- reset_output(x);
- for(i=0; i<packet_bytes; ++i)
- add_float_to_output(x,packet[i]);
- outlet_list(x->x_data_outlet, &s_list, x->output_count, x->output);
- post("x->x_read_elements %d",x->x_read_elements);
}