aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-05-18 11:56:07 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-05-18 11:56:07 +0000
commit476c214fc8987f2c49e266de57a9b7c4c6fb4426 (patch)
treea3254f8e397ce64b8cf6da73d79c3d759f4ff3ae
parent7cbfcfbcd4cfe315f7604765f53d2d7a747a2bd5 (diff)
first sketch of opening working
svn path=/trunk/externals/hcs/; revision=5081
-rw-r--r--libhid-help.pd17
-rw-r--r--libhid.c157
-rw-r--r--libhid.libs1
3 files changed, 112 insertions, 63 deletions
diff --git a/libhid-help.pd b/libhid-help.pd
index bb516f4..3262754 100644
--- a/libhid-help.pd
+++ b/libhid-help.pd
@@ -1,7 +1,6 @@
-#N canvas 338 93 585 463 10;
+#N canvas 338 93 593 471 10;
#X obj 111 373 libhid;
-#X msg 170 60 bang;
-#X msg 183 79 open;
+#X msg 125 14 bang;
#X msg 185 98 close;
#X msg 185 124 reset;
#X obj 84 408 print left;
@@ -12,12 +11,16 @@
#X text 233 258 GARBAGE FOR TESTING;
#X msg 250 292 set read 1 30 word 1 31 1 38;
#X msg 205 182 set read 1 30 1 31 12 38;
-#X connect 0 0 5 0;
-#X connect 0 1 6 0;
+#X msg 198 142 print;
+#X msg 177 78 open 1149 16392;
+#X text 298 78 Gravis/Destroyer Tiltpad;
+#X connect 0 0 4 0;
+#X connect 0 1 5 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 3 0 0 0;
-#X connect 4 0 0 0;
-#X connect 9 0 0 0;
+#X connect 8 0 0 0;
+#X connect 10 0 0 0;
#X connect 11 0 0 0;
#X connect 12 0 0 0;
+#X connect 13 0 0 0;
diff --git a/libhid.c b/libhid.c
index 327b59a..9bd2498 100644
--- a/libhid.c
+++ b/libhid.c
@@ -31,6 +31,22 @@
/*------------------------------------------------------------------------------
+ * INCLUDE HACK
+ */
+
+/* NOTE: included from libusb/usbi.h. UGLY, i know, but so is libusb! */
+struct usb_dev_handle {
+ int fd;
+ struct usb_bus *bus;
+ struct usb_device *device;
+ int config;
+ int interface;
+ int altsetting;
+ void *impl_info;
+};
+
+
+/*------------------------------------------------------------------------------
* GLOBAL VARIABLES
*/
@@ -41,6 +57,7 @@
t_int libhid_instance_count;
char *hid_id[32]; /* FIXME: 32 devices MAX */
+t_int hid_id_count;
/*------------------------------------------------------------------------------
* CLASS DEF
@@ -65,20 +82,10 @@ typedef struct _libhid
t_int x_started;
/* outlets */
t_outlet *x_data_outlet;
- t_outlet *x_device_name_outlet;
+ t_outlet *x_control_outlet;
} t_libhid;
-/* NOTE: included from libusb/usbi.h. UGLY, i know, but so is libusb! */
-struct usb_dev_handle {
- int fd;
- struct usb_bus *bus;
- struct usb_device *device;
- int config;
- int interface;
- int altsetting;
- void *impl_info;
-};
/*------------------------------------------------------------------------------
@@ -131,6 +138,11 @@ static bool device_iterator (struct usb_dev_handle const* usbdev, void* custom,
{
hid_id[i] = (char *) malloc(strlen(usbdev->device->filename) + strlen(usbdev->bus->dirname) );
sprintf(hid_id[i], "%s/%s", usbdev->bus->dirname, usbdev->device->filename);
+ post("bus %s device %s: %d %d",
+ usbdev->bus->dirname,
+ usbdev->device->filename,
+ usbdev->device->descriptor.idVendor,
+ usbdev->device->descriptor.idProduct);
}
else /* device already seen */
{
@@ -148,9 +160,9 @@ static bool device_iterator (struct usb_dev_handle const* usbdev, void* custom,
return ret;
}
-/*
- This function is used in a HIDInterfaceMatcher in order to match devices by
- serial number.
+/* -------------------------------------------------------------------------- */
+/* This function is used in a HIDInterfaceMatcher in order to match devices by
+ * serial number.
*/
/* static bool match_serial_number(struct usb_dev_handle* usbdev, void* custom, unsigned int len) */
/* { */
@@ -164,6 +176,7 @@ static bool device_iterator (struct usb_dev_handle const* usbdev, void* custom,
/* } */
+/* -------------------------------------------------------------------------- */
/* static HIDInterface* get_device_by_number(t_int device_number) */
/* { */
/* HIDInterface* return_hid; */
@@ -172,24 +185,51 @@ static bool device_iterator (struct usb_dev_handle const* usbdev, void* custom,
/* } */
+/* -------------------------------------------------------------------------- */
+static t_int* make_hid_packet(t_int element_count, t_int argc, t_atom *argv)
+{
+ DEBUG(post("make_hid_packet"););
+ t_int i;
+ t_int *return_array = NULL;
+
+ post("element_count %d",element_count);
+ return_array = (t_int *) getbytes(sizeof(t_int) * element_count);
+ for(i=0; i < element_count; ++i)
+ {
+/*
+ * A libhid path component is 32 bits, the high 16 bits identify the usage page,
+ * and the low 16 bits the item number.
+ */
+ return_array[i] =
+ (atom_getintarg(i*2,argc,argv) << 16) + atom_getintarg(i*2+1,argc,argv);
+/* TODO: print error if a symbol is found in the data list */
+ }
+ return return_array;
+}
+
/*------------------------------------------------------------------------------
* IMPLEMENTATION
*/
/* -------------------------------------------------------------------------- */
-static void libhid_open(t_libhid *x)
+static void libhid_open(t_libhid *x, t_float vendor_id, t_float product_id)
{
DEBUG(post("libhid_open"););
-/* Microsoft 5-Button Mouse with IntelliEye(TM) */
- HIDInterfaceMatcher matcher = { 0x045e, 0x0039, NULL, NULL, 0 };
+ HIDInterfaceMatcher matcher = { (unsigned short)vendor_id,
+ (unsigned short)product_id,
+ NULL,
+ NULL,
+ 0 };
- x->x_hid_return = hid_force_open(x->x_hidinterface, 0, &matcher, 3);
- if (x->x_hid_return != HID_RET_SUCCESS) {
- error("[libhid] hid_force_open failed with return code %d\n", x->x_hid_return);
+ if ( !hid_is_opened(x->x_hidinterface) )
+ {
+ x->x_hid_return = hid_force_open(x->x_hidinterface, 0, &matcher, 3);
+ if (x->x_hid_return != HID_RET_SUCCESS) {
+ error("[libhid] hid_force_open failed with return code %d\n", x->x_hid_return);
+ }
}
-
}
@@ -203,12 +243,12 @@ static void libhid_read(t_libhid *x)
char packet[RECEIVE_PACKET_LENGTH];
- if ( !hid_is_opened(x->x_hidinterface) )
- {
- libhid_open(x);
- }
- else
- {
+/* if ( !hid_is_opened(x->x_hidinterface) ) */
+/* { */
+/* libhid_open(x); */
+/* } */
+/* else */
+/* { */
x->x_hid_return = hid_get_input_report(x->x_hidinterface,
PATH_OUT,
PATH_LENGTH,
@@ -217,31 +257,10 @@ static void libhid_read(t_libhid *x)
if (x->x_hid_return != HID_RET_SUCCESS)
error("[libhid] hid_get_input_report failed with return code %d\n",
x->x_hid_return);
- }
+/* } */
}
-/* -------------------------------------------------------------------------- */
-static t_int* libhid_make_packet(t_int element_count, t_int argc, t_atom *argv)
-{
- DEBUG(post("libhid_make_packet"););
- t_int i;
- t_int *return_array = NULL;
-
- post("element_count %d",element_count);
- return_array = (t_int *) getbytes(sizeof(t_int) * element_count);
- for(i=0; i < element_count; ++i)
- {
-/*
- * A libhid path component is 32 bits, the high 16 bits identify the usage page,
- * and the low 16 bits the item number.
- */
- return_array[i] =
- (atom_getintarg(i*2,argc,argv) << 16) + atom_getintarg(i*2+1,argc,argv);
-/* TODO: print error if a symbol is found in the data list */
- }
- return return_array;
-}
/* -------------------------------------------------------------------------- */
/* set the HID packet for which elements to read */
@@ -251,7 +270,7 @@ static void libhid_set_read(t_libhid *x, int argc, t_atom *argv)
t_int i;
x->x_read_element_count = argc / 2;
- x->x_read_elements = libhid_make_packet(x->x_read_element_count, argc, argv);
+ x->x_read_elements = make_hid_packet(x->x_read_element_count, argc, argv);
post("x_read_element_count %d",x->x_read_element_count);
for(i=0;i<x->x_read_element_count;++i)
post("x_read_elements %d: %d",i,x->x_read_elements[i]);
@@ -266,7 +285,7 @@ static void libhid_set_write(t_libhid *x, int argc, t_atom *argv)
t_int i;
x->x_write_element_count = argc / 2;
- x->x_write_elements = libhid_make_packet(x->x_write_element_count, argc, argv);
+ x->x_write_elements = make_hid_packet(x->x_write_element_count, argc, argv);
post("x_write_element_count %d",x->x_write_element_count);
for(i=0;i<x->x_write_element_count;++i)
post("x_write_elements %d: %d",i,x->x_write_elements[i]);
@@ -275,6 +294,7 @@ static void libhid_set_write(t_libhid *x, int argc, t_atom *argv)
/* -------------------------------------------------------------------------- */
+/* convert a list to a HID packet and set it */
static void libhid_set(t_libhid *x, t_symbol *s, int argc, t_atom *argv)
{
DEBUG(post("libhid_set"););
@@ -288,6 +308,20 @@ static void libhid_set(t_libhid *x, t_symbol *s, int argc, t_atom *argv)
}
+/* -------------------------------------------------------------------------- */
+static void libhid_get(t_libhid *x, t_symbol *s, int argc, t_atom *argv)
+{
+ DEBUG(post("libhid_get"););
+ t_symbol *subselector;
+
+ subselector = atom_getsymbol(&argv[0]);
+/* if(strcmp(subselector->s_name,"read") == 0) */
+
+/* if(strcmp(subselector->s_name,"write") == 0) */
+
+}
+
+
/* -------------------------------------------------------------------------- */
static void libhid_close(t_libhid *x)
@@ -312,8 +346,18 @@ static void libhid_close(t_libhid *x)
static void libhid_print(t_libhid *x)
{
DEBUG(post("libhid_print"););
-
- hid_write_identification(stdout, x->x_hidinterface);
+ t_int i;
+ t_atom event_data[3];
+
+ for ( i = 0 ; ( hid_id[i] != NULL ) ; i++ )
+ {
+ if( hid_id[i] != NULL )
+ post("hid_id[%d]: %s",i,hid_id[i]);
+ }
+/* SETSYMBOL(event_data, gensym(type)); /\* type *\/ */
+/* SETSYMBOL(event_data + 1, gensym(code)); /\* code *\/ */
+/* SETSYMBOL(event_data + 2, value); /\* value *\/ */
+// outlet_list(x->x_control_outlet, &s_list,
}
@@ -365,7 +409,7 @@ static void *libhid_new(t_float f)
/* create anything outlet used for HID data */
x->x_data_outlet = outlet_new(&x->x_obj, 0);
- x->x_device_name_outlet = outlet_new(&x->x_obj, 0);
+ x->x_control_outlet = outlet_new(&x->x_obj, 0);
/* hid_write_library_config(stdout); */
/* hid_set_debug(HID_DEBUG_NOTRACES); */
@@ -392,7 +436,7 @@ static void *libhid_new(t_float f)
/* open recursively all HID devices found */
while ( (x->x_hid_return = hid_force_open(x->x_hidinterface, 0, &matcher, 2)) != HID_RET_DEVICE_NOT_FOUND)
{
- printf("************************************************************************\n");
+/* printf("************************************************************************\n"); */
/* hid_write_identification(stdout, x->x_hidinterface); */
@@ -433,7 +477,8 @@ void libhid_setup(void)
class_addmethod(libhid_class,(t_method) libhid_print,gensym("print"),0);
class_addmethod(libhid_class,(t_method) libhid_reset,gensym("reset"),0);
class_addmethod(libhid_class,(t_method) libhid_set,gensym("set"),A_GIMME,0);
- class_addmethod(libhid_class,(t_method) libhid_open,gensym("open"),0);
+ class_addmethod(libhid_class,(t_method) libhid_get,gensym("get"),A_DEFSYM,0);
+ class_addmethod(libhid_class,(t_method) libhid_open,gensym("open"),A_DEFFLOAT,A_DEFFLOAT,0);
class_addmethod(libhid_class,(t_method) libhid_close,gensym("close"),0);
}
diff --git a/libhid.libs b/libhid.libs
new file mode 100644
index 0000000..f4a4261
--- /dev/null
+++ b/libhid.libs
@@ -0,0 +1 @@
+-lusb -lhid