From 66d52779d1ecb627a3fc7dc25101f53f45bd2652 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 30 Jul 2007 18:15:46 +0000 Subject: first probes at write support, switching to Mac OS X for dev platform svn path=/trunk/externals/hcs/; revision=8280 --- usbhid/usbhid.c | 61 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'usbhid/usbhid.c') 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; ix_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; ix_data_outlet, &s_list, x->output_count, x->output); - post("x->x_read_elements %d",x->x_read_elements); } -- cgit v1.2.1