aboutsummaryrefslogtreecommitdiff
path: root/usbhid/usbhid.c
diff options
context:
space:
mode:
Diffstat (limited to 'usbhid/usbhid.c')
-rw-r--r--usbhid/usbhid.c61
1 files changed, 33 insertions, 28 deletions
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);
}