[gnome-color-manager: 4/80] Send 8 bytes of zero data to the HUEY
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager: 4/80] Send 8 bytes of zero data to the HUEY
- Date: Mon, 19 Jul 2010 11:32:47 +0000 (UTC)
commit 2b80915491568aa479bb4cf47b3ae75931785c88
Author: Richard Hughes <richard hughsie com>
Date: Sat Jul 17 22:38:55 2010 +0100
Send 8 bytes of zero data to the HUEY
src/gcm-huey-example.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/src/gcm-huey-example.c b/src/gcm-huey-example.c
index 7637b78..05ab000 100644
--- a/src/gcm-huey-example.c
+++ b/src/gcm-huey-example.c
@@ -32,10 +32,12 @@
#define HUEY_VENDOR_ID 0x0971
#define HUEY_PRODUCT_ID 0x2005
+#define HUEY_CONTROL_MESSAGE_TIMEOUT 5000 /* ms */
typedef struct {
- gboolean connected;
- libusb_device *device;
+ gboolean connected;
+ libusb_device *device;
+ libusb_device_handle *handle;
} GcmPriv;
static gboolean
@@ -83,6 +85,28 @@ gcm_find_device (GcmPriv *priv, GError **error)
g_set_error_literal (error, 1, 0, "no compatible hardware attached");
goto out;
}
+
+ /* open device */
+ retval = libusb_open (priv->device, &priv->handle);
+ if (retval < 0) {
+ ret = FALSE;
+ g_set_error (error, 1, 0, "failed to open device: %s", libusb_strerror (retval));
+ goto out;
+ }
+
+ /* set configuration and interface, the only values we've got in lsusb-vvv */
+ retval = libusb_set_configuration (priv->handle, 1);
+ if (retval < 0) {
+ ret = FALSE;
+ g_set_error (error, 1, 0, "failed to set configuration: %s", libusb_strerror (retval));
+ goto out;
+ }
+ retval = libusb_claim_interface (priv->handle, 0);
+ if (retval < 0) {
+ ret = FALSE;
+ g_set_error (error, 1, 0, "failed to claim interface: %s", libusb_strerror (retval));
+ goto out;
+ }
out:
libusb_free_device_list (devs, 1);
return ret;
@@ -95,6 +119,9 @@ main (void)
gboolean ret;
GcmPriv *priv;
GError *error = NULL;
+ guchar *data;
+ gint bytes_read = 0;
+ guint i;
priv = g_new0 (GcmPriv, 1);
@@ -114,8 +141,36 @@ main (void)
goto out;
}
+ /* according to wMaxPacketSize, all the messages have just 8 bytes */
+ data = g_new0 (guchar, 8);
+ retval = libusb_control_transfer (priv->handle,
+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+ 0x09, 0x0200, 0,
+ data, 8,
+ HUEY_CONTROL_MESSAGE_TIMEOUT);
+ if (retval < 0) {
+ g_warning ("failed to send message interface: %s", libusb_strerror (retval));
+ goto out;
+ }
+
+ /* get response, from bEndpointAddress */
+ retval = libusb_interrupt_transfer (priv->handle, 0x81, data, 8, &bytes_read, HUEY_CONTROL_MESSAGE_TIMEOUT);
+ if (retval < 0) {
+ g_warning ("failed to recieve message interface: %s", libusb_strerror (retval));
+ goto out;
+ }
+
+ for (i=0; i< (guint)bytes_read; i++)
+ g_print ("%02x [%c]\t", data[i], g_ascii_isprint (data[i]) ? data[i] : '?');
+
+ g_print ("\n");
+ g_free (data);
+
/* do something */
g_warning ("fixme");
+
+ /* close device */
+ libusb_close (priv->handle);
out:
if (priv->device != NULL)
libusb_unref_device (priv->device);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]