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/usbhid.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'usbhid/usbhid.c') 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