[gnome-color-manager: 3/80] Add some initial framework code to talk to the HUEY colorimeter



commit 0566e5f02e0ab218689d4067e9229cb72a89086d
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jul 17 22:38:05 2010 +0100

    Add some initial framework code to talk to the HUEY colorimeter

 configure.ac                     |    1 +
 docs/huey/lsusb-vvv              |   97 +++++++++++++++++++++++++++++
 docs/huey/usb-init-cancel.txt.gz |  Bin 0 -> 663 bytes
 docs/huey/usb-init.txt.gz        |  Bin 0 -> 1896 bytes
 docs/huey/usb-startup.txt.gz     |  Bin 0 -> 9249 bytes
 src/.gitignore                   |    1 +
 src/Makefile.am                  |   13 ++++-
 src/gcm-huey-example.c           |  127 ++++++++++++++++++++++++++++++++++++++
 8 files changed, 238 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 52d8be3..56ab10b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -142,6 +142,7 @@ PKG_CHECK_MODULES(GNOMEDESKTOP, gnome-desktop-3.0 >= 2.90.0)
 PKG_CHECK_MODULES(GUDEV, gudev-1.0)
 PKG_CHECK_MODULES(LCMS, lcms2)
 PKG_CHECK_MODULES(X11, x11)
+PKG_CHECK_MODULES(USB, [libusb-1.0 >= 1.0.0])
 
 dnl Required for the properties window
 PKG_CHECK_MODULES(CONTROL_CENTER, [
diff --git a/docs/huey/lsusb-vvv b/docs/huey/lsusb-vvv
new file mode 100644
index 0000000..ddc8f97
--- /dev/null
+++ b/docs/huey/lsusb-vvv
@@ -0,0 +1,97 @@
+Bus 005 Device 002: ID 0971:2005 Gretag-Macbeth AG Huey
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.10
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0         8
+  idVendor           0x0971 Gretag-Macbeth AG
+  idProduct          0x2005 Huey
+  bcdDevice            0.01
+  iManufacturer           0 
+  iProduct                0 
+  iSerial                 0 
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           34
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass         3 Human Interface Device
+      bInterfaceSubClass      0 No Subclass
+      bInterfaceProtocol      0 None
+      iInterface              0 
+        HID Device Descriptor:
+          bLength                 9
+          bDescriptorType        33
+          bcdHID               1.00
+          bCountryCode            0 Not supported
+          bNumDescriptors         1
+          bDescriptorType        34 Report
+          wDescriptorLength      52
+          Report Descriptor: (length is 52)
+            Item(Global): Usage Page, data= [ 0xa0 0xff ] 65440
+                            (null)
+            Item(Local ): Usage, data= [ 0x01 ] 1
+                            (null)
+            Item(Main  ): Collection, data= [ 0x01 ] 1
+                            Application
+            Item(Local ): Usage, data= [ 0x02 ] 2
+                            (null)
+            Item(Main  ): Collection, data= [ 0x00 ] 0
+                            Physical
+            Item(Global): Usage Page, data= [ 0xa1 0xff ] 65441
+                            (null)
+            Item(Local ): Usage, data= [ 0x03 ] 3
+                            (null)
+            Item(Local ): Usage, data= [ 0x04 ] 4
+                            (null)
+            Item(Global): Logical Minimum, data= [ 0x80 ] 128
+            Item(Global): Logical Maximum, data= [ 0x7f ] 127
+            Item(Global): Physical Minimum, data= [ 0x00 ] 0
+            Item(Global): Physical Maximum, data= [ 0xff ] 255
+            Item(Global): Report Size, data= [ 0x08 ] 8
+            Item(Global): Report Count, data= [ 0x08 ] 8
+            Item(Main  ): Input, data= [ 0x02 ] 2
+                            Data Variable Absolute No_Wrap Linear
+                            Preferred_State No_Null_Position Non_Volatile Bitfield
+            Item(Local ): Usage, data= [ 0x05 ] 5
+                            (null)
+            Item(Local ): Usage, data= [ 0x06 ] 6
+                            (null)
+            Item(Global): Logical Minimum, data= [ 0x80 ] 128
+            Item(Global): Logical Maximum, data= [ 0x7f ] 127
+            Item(Global): Physical Minimum, data= [ 0x00 ] 0
+            Item(Global): Physical Maximum, data= [ 0xff ] 255
+            Item(Global): Report Size, data= [ 0x08 ] 8
+            Item(Global): Report Count, data= [ 0x08 ] 8
+            Item(Main  ): Output, data= [ 0x02 ] 2
+                            Data Variable Absolute No_Wrap Linear
+                            Preferred_State No_Null_Position Non_Volatile Bitfield
+            Item(Main  ): End Collection, data=none
+            Item(Main  ): End Collection, data=none
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0008  1x 8 bytes
+        bInterval              10
+Device Status:     0x0000
+  (Bus Powered)
diff --git a/docs/huey/usb-init-cancel.txt.gz b/docs/huey/usb-init-cancel.txt.gz
new file mode 100644
index 0000000..57a0d1e
Binary files /dev/null and b/docs/huey/usb-init-cancel.txt.gz differ
diff --git a/docs/huey/usb-init.txt.gz b/docs/huey/usb-init.txt.gz
new file mode 100644
index 0000000..4f15765
Binary files /dev/null and b/docs/huey/usb-init.txt.gz differ
diff --git a/docs/huey/usb-startup.txt.gz b/docs/huey/usb-startup.txt.gz
new file mode 100644
index 0000000..50df93d
Binary files /dev/null and b/docs/huey/usb-startup.txt.gz differ
diff --git a/src/.gitignore b/src/.gitignore
index 389a65d..87580a1 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -19,3 +19,4 @@ gcm-install-system-wide
 gcm-helper-exiv
 gcm-glsl-demo
 gcm-ddc-util
+gcm-huey-example
diff --git a/src/Makefile.am b/src/Makefile.am
index d027be1..0900d3a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -119,7 +119,8 @@ bin_PROGRAMS =						\
 	gcm-session					\
 	gcm-picker					\
 	gcm-ddc-util					\
-	gcm-import
+	gcm-import					\
+	gcm-huey-example
 
 if HAVE_EXIV
 libexec_PROGRAMS = gcm-helper-exiv
@@ -391,6 +392,16 @@ install-data-hook:
 		mkdir -p $(DESTDIR)$(GCM_SYSTEM_PROFILES_DIR); \
 	fi
 
+gcm_huey_example_SOURCES =				\
+	gcm-huey-example.c
+
+gcm_huey_example_LDADD =				\
+	$(GLIB_LIBS)					\
+	$(COLOR_GLIB_LIBS)
+
+#gcm_huey_example_CFLAGS =				\
+#	$(WARNINGFLAGS_C)
+
 clean-local:
 	rm -f *~
 
diff --git a/src/gcm-huey-example.c b/src/gcm-huey-example.c
new file mode 100644
index 0000000..7637b78
--- /dev/null
+++ b/src/gcm-huey-example.c
@@ -0,0 +1,127 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+/*
+ * I've reversed engineered this myself using USB Snoop on Windows XP,
+ * in a KVM virtual machine. Please see ../docs/huey for data.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#include <libusb-1.0/libusb.h>
+#include <glib.h>
+
+#define HUEY_VENDOR_ID			0x0971
+#define HUEY_PRODUCT_ID			0x2005
+
+typedef struct {
+	gboolean	 connected;
+	libusb_device	*device;
+} GcmPriv;
+
+static gboolean
+gcm_find_device (GcmPriv *priv, GError **error)
+{
+	struct libusb_device_descriptor desc;
+	libusb_device **devs = NULL;
+	libusb_device *dev;
+	gint retval;
+	gsize cnt;
+	guint i = 0;
+	gboolean ret = FALSE;
+
+	/* get device */
+	cnt = libusb_get_device_list (NULL, &devs);
+	if (cnt < 0) {
+		g_set_error (error, 1, 0, "failed to get device list: %s", libusb_strerror (cnt));
+		goto out;
+	}
+
+	/* find device */
+	for (i=0; i<cnt; i++) {
+		dev = devs[i];
+
+		/* get descriptor */
+		retval = libusb_get_device_descriptor (dev, &desc);
+		if (retval < 0) {
+			g_warning ("failed to get device descriptor for %02x:%02x, possibly faulty hardware",
+				   libusb_get_bus_number (dev), libusb_get_device_address (dev));
+			continue;
+		}
+
+		/* does match HUEY? */
+		if (desc.idVendor == HUEY_VENDOR_ID &&
+		    desc.idProduct == HUEY_PRODUCT_ID) {
+			g_debug ("got huey!");
+			ret = TRUE;
+			priv->device = libusb_ref_device (dev);
+			break;
+		}
+	}
+
+	/* not found */
+	if (!ret) {
+		g_set_error_literal (error, 1, 0, "no compatible hardware attached");
+		goto out;
+	}
+out:
+	libusb_free_device_list (devs, 1);
+	return ret;
+}
+
+int
+main (void)
+{
+	gint retval;
+	gboolean ret;
+	GcmPriv *priv;
+	GError *error = NULL;
+
+	priv = g_new0 (GcmPriv, 1);
+
+	/* connect */
+	retval = libusb_init (NULL);
+	if (retval < 0) {
+		g_warning ("failed to init libusb: %s", libusb_strerror (retval));
+		goto out;
+	}
+	priv->connected = TRUE;
+
+	/* find device */
+	ret = gcm_find_device (priv, &error);
+	if (!ret) {
+		g_warning ("failed to find sensor: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* do something */
+	g_warning ("fixme");
+out:
+	if (priv->device != NULL)
+		libusb_unref_device (priv->device);
+	if (priv->connected)
+		libusb_exit (NULL);
+	g_free (priv);
+	return 0;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]