[gnome-color-manager] Add a simple parser that can parse the output of the Beagle USB capture device



commit 673cd45890b561254394192b417567370f77f780
Author: Richard Hughes <richard hughsie com>
Date:   Wed Sep 29 12:56:25 2010 +0100

    Add a simple parser that can parse the output of the Beagle USB capture device

 docs/.gitignore                         |    6 +
 docs/Makefile.am                        |   24 +++
 docs/gcm-parse-beagle.c                 |  256 +++++++++++++++++++++++++
 docs/huey/.gitignore                    |    2 +
 docs/huey/Makefile.am                   |    2 +
 docs/huey/gcm-parse-huey.c              |   73 +-------
 help/.gitignore                         |    2 +-
 libcolor-glib/Makefile.am               |    2 +
 libcolor-glib/gcm-sensor-huey-private.c |   94 +++++++++
 libcolor-glib/gcm-sensor-huey-private.h |  307 ++++++++++++++++++++++++++++++
 libcolor-glib/gcm-sensor-huey.c         |  317 +++---------------------------
 11 files changed, 729 insertions(+), 356 deletions(-)
---
diff --git a/docs/.gitignore b/docs/.gitignore
index a136337..b212b13 100644
--- a/docs/.gitignore
+++ b/docs/.gitignore
@@ -1 +1,7 @@
+.deps
+.libs
+gcm-parse-beagle
+*.parsed
 *.pdf
+*.csv
+*.o
diff --git a/docs/Makefile.am b/docs/Makefile.am
index f917aa7..c895955 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -1,3 +1,27 @@
 SUBDIRS = 						\
 	huey						\
 	api
+
+INCLUDES =							\
+	-I$(top_srcdir)/libcolor-glib				\
+	-DI_KNOW_THE_LIBCOLOR_GLIB_API_IS_SUBJECT_TO_CHANGE	\
+	-DGCM_I_KNOW_THIS_IS_PRIVATE				\
+	$(GUDEV_CFLAGS)						\
+	$(GTK_CFLAGS)						\
+	$(GLIB_CFLAGS)
+
+COLOR_GLIB_LIBS =						\
+	$(top_builddir)/libcolor-glib/libcolor-glib.la
+
+noinst_PROGRAMS =					\
+	gcm-parse-beagle
+
+gcm_parse_beagle_SOURCES =				\
+	gcm-parse-beagle.c
+
+gcm_parse_beagle_LDADD =				\
+	$(COLOR_GLIB_LIBS)					\
+	$(GLIB_LIBS)
+
+gcm_parse_beagle_CFLAGS =				\
+	$(WARNINGFLAGS_C)
diff --git a/docs/gcm-parse-beagle.c b/docs/gcm-parse-beagle.c
new file mode 100644
index 0000000..1ae18cc
--- /dev/null
+++ b/docs/gcm-parse-beagle.c
@@ -0,0 +1,256 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 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
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <libcolor-glib.h>
+
+#include "gcm-sensor-huey-private.h"
+
+typedef enum {
+	GCM_PARSE_SECTION_LEVEL,
+	GCM_PARSE_SECTION_SP,
+	GCM_PARSE_SECTION_MS_US,
+	GCM_PARSE_SECTION_DUR,
+	GCM_PARSE_SECTION_LEN,
+	GCM_PARSE_SECTION_ERR,
+	GCM_PARSE_SECTION_DEV,
+	GCM_PARSE_SECTION_EP,
+	GCM_PARSE_SECTION_RECORD,
+	GCM_PARSE_SECTION_SUMMARY
+} GcmParseSection;
+
+typedef enum {
+	GCM_PARSE_ENTRY_DIRECTION_UNKNOWN,
+	GCM_PARSE_ENTRY_DIRECTION_REQUEST,
+	GCM_PARSE_ENTRY_DIRECTION_REPLY
+} GcmParseEntryDirection;
+
+typedef struct {
+	const gchar		*record;
+	const gchar		*summary;
+	const gchar		*summary_pretty;
+	gint			 dev;
+	gint			 ep;
+	GcmParseEntryDirection	 direction;
+} GcmParseEntry;
+
+/**
+ * gcm_parse_beagle_process_entry_huey:
+ **/
+static void
+gcm_parse_beagle_process_entry_huey (GcmParseEntry *entry)
+{
+	gchar **tok;
+	guint j;
+	guchar cmd;
+	guchar instruction = 0;
+	const gchar *command_as_text;
+	GString *output;
+
+	/* only know how to parse 8 bytes */
+	tok = g_strsplit (entry->summary, " ", -1);
+	if (g_strv_length (tok) != 8) {
+		g_print ("not 8 tokens: %s\n", entry->summary);
+		goto out;
+	}
+
+	output = g_string_new ("");
+	for (j=0; j<8; j++) {
+		command_as_text = NULL;
+		cmd = g_ascii_strtoll (tok[j], NULL, 16);
+		if (j == 0 && entry->direction == GCM_PARSE_ENTRY_DIRECTION_REPLY) {
+			command_as_text = gcm_sensor_huey_return_code_to_string (cmd);
+			if (command_as_text == NULL)
+				g_warning ("return code 0x%02x not known in %s", cmd, entry->summary);
+		}
+		if ((j == 0 && entry->direction == GCM_PARSE_ENTRY_DIRECTION_REQUEST) ||
+		    (j == 1 && entry->direction == GCM_PARSE_ENTRY_DIRECTION_REPLY)) {
+			instruction = cmd;
+			command_as_text = gcm_sensor_huey_command_code_to_string (instruction);
+			if (command_as_text == NULL)
+				g_warning ("command code 0x%02x not known", cmd);
+		}
+
+		/* some requests are filled with junk data */
+		if (entry->direction == GCM_PARSE_ENTRY_DIRECTION_REQUEST &&
+		    instruction == GCM_SENSOR_HUEY_COMMAND_REGISTER_READ && j > 1)
+			g_string_append_printf (output, "xx ");
+		else if (entry->direction == GCM_PARSE_ENTRY_DIRECTION_REQUEST &&
+			 instruction == GCM_SENSOR_HUEY_COMMAND_SET_LEDS && j > 4)
+			g_string_append_printf (output, "xx ");
+		else if (entry->direction == GCM_PARSE_ENTRY_DIRECTION_REQUEST &&
+			 instruction == GCM_SENSOR_HUEY_COMMAND_GET_AMBIENT && j > 3)
+			g_string_append_printf (output, "xx ");
+		else if (command_as_text != NULL)
+			g_string_append_printf (output, "%02x(%s) ", cmd, command_as_text);
+		else
+			g_string_append_printf (output, "%02x ", cmd);
+	}
+
+	/* remove trailing space */
+	if (output->len > 1)
+		g_string_set_size (output, output->len - 1);
+out:
+	if (output != NULL)
+		entry->summary_pretty = g_string_free (output, FALSE);
+	g_strfreev (tok);
+}
+
+/**
+ * gcm_parse_beagle_process_entry:
+ **/
+static gchar *
+gcm_parse_beagle_process_entry (GcmSensorKind kind, GcmParseEntry *entry)
+{
+	gchar *retval = NULL;
+	const gchar *direction = "??";
+
+	/* timeout */
+	if (g_strcmp0 (entry->record, "[250 IN-NAK]") == 0)
+		goto out;
+
+	/* device closed */
+	if (g_strcmp0 (entry->record, "[1 ORPHANED]") == 0)
+		goto out;
+
+	/* usb error */
+	if (g_strcmp0 (entry->record, "[53 SYNC ERRORS]") == 0)
+		goto out;
+	if (g_strcmp0 (entry->record, "[240 IN-NAK]") == 0)
+		goto out;
+	if (g_strcmp0 (entry->record, "Bus event") == 0)
+		goto out;
+
+	/* start or end of file */
+	if (g_str_has_prefix (entry->record, "Capture started"))
+		goto out;
+	if (g_strcmp0 (entry->record, "Capture stopped") == 0)
+		goto out;
+
+	/* get direction */
+	if (g_str_has_prefix (entry->record, "IN txn"))
+		entry->direction = GCM_PARSE_ENTRY_DIRECTION_REPLY;
+	else if (g_strcmp0 (entry->record, "Control Transfer") == 0)
+		entry->direction = GCM_PARSE_ENTRY_DIRECTION_REQUEST;
+
+	/* get correct string */
+	if (entry->direction == GCM_PARSE_ENTRY_DIRECTION_REQUEST)
+		direction = ">>";
+	else if (entry->direction == GCM_PARSE_ENTRY_DIRECTION_REPLY)
+		direction = "<<";
+
+	/* sexify the output */
+	if (kind == GCM_SENSOR_KIND_HUEY)
+		gcm_parse_beagle_process_entry_huey (entry);
+	retval = g_strdup_printf ("dev%02i ep%02i\t%s\t%s\n",
+				  entry->dev, entry->ep, direction,
+				  entry->summary_pretty != NULL ? entry->summary_pretty : entry->summary);
+out:
+	return retval;
+}
+
+/**
+ * main:
+ **/
+gint
+main (gint argc, gchar *argv[])
+{
+	gboolean ret;
+	gchar *data = NULL;
+	gchar **split = NULL;
+	gchar **sections = NULL;
+	GString *output = NULL;
+	GError *error = NULL;
+	guint i;
+	GcmParseEntry entry;
+	gchar *part;
+	gint retval = 1;
+	GcmSensorKind kind;
+
+	if (argc != 4) {
+		g_print ("need to specify [huey|colormunki] input output\n");
+		goto out;
+	}
+	kind = gcm_sensor_kind_from_string (argv[1]);
+	if (kind != GCM_SENSOR_KIND_HUEY &&
+	    kind != GCM_SENSOR_KIND_COLOR_MUNKI) {
+		g_print ("only huey and colormunki device kinds supported\n");
+		goto out;
+	}
+
+	/* read file */
+	ret = g_file_get_contents (argv[2], &data, NULL, &error);
+	if (!ret) {
+		g_print ("failed to read: %s\n", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* parse string */
+	output = g_string_new ("// automatically generated, do not edit\n");
+
+	/* parse string */
+	split = g_strsplit (data, "\n", -1);
+	for (i=0; split[i] != NULL; i++) {
+
+		/* comment or blank line */
+		if (split[i][0] == '#' ||
+		    split[i][0] == '\0')
+			continue;
+
+		/* populate a GcmParseEntry */
+		sections = g_strsplit (split[i], ",", -1);
+		entry.record = sections[GCM_PARSE_SECTION_RECORD];
+		entry.summary = sections[GCM_PARSE_SECTION_SUMMARY];
+		entry.dev = atoi (sections[GCM_PARSE_SECTION_DEV]);
+		entry.ep = atoi (sections[GCM_PARSE_SECTION_EP]);
+		entry.direction = GCM_PARSE_ENTRY_DIRECTION_UNKNOWN;
+		entry.summary_pretty = NULL;
+		part = gcm_parse_beagle_process_entry (kind, &entry);
+		if (part != NULL) {
+			g_string_append (output, part);
+//			g_print ("%s\n", part);
+		}
+		g_free (part);
+		g_strfreev (sections);
+	}
+
+	/* write file */
+	ret = g_file_set_contents (argv[3], output->str, -1, &error);
+	if (!ret) {
+		g_print ("failed to read: %s\n", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	g_print ("done!\n");
+	retval = 0;
+out:
+	if (output != NULL)
+		g_string_free (output, TRUE);
+	g_free (data);
+	g_strfreev (split);
+	return retval;
+}
+
diff --git a/docs/huey/.gitignore b/docs/huey/.gitignore
index 91487bd..cb504dd 100644
--- a/docs/huey/.gitignore
+++ b/docs/huey/.gitignore
@@ -5,3 +5,5 @@ gcm-parse-huey
 gcm-calculate-fudge
 *.o
 *.parsed
+*.txt
+*.gnumeric
diff --git a/docs/huey/Makefile.am b/docs/huey/Makefile.am
index f3d3c81..c7b43e9 100644
--- a/docs/huey/Makefile.am
+++ b/docs/huey/Makefile.am
@@ -1,6 +1,7 @@
 INCLUDES =							\
 	-I$(top_srcdir)/libcolor-glib				\
 	-DI_KNOW_THE_LIBCOLOR_GLIB_API_IS_SUBJECT_TO_CHANGE	\
+	-DGCM_I_KNOW_THIS_IS_PRIVATE				\
 	$(GUDEV_CFLAGS)						\
 	$(GTK_CFLAGS)						\
 	$(GLIB_CFLAGS)
@@ -27,6 +28,7 @@ gcm_parse_huey_SOURCES =					\
 	gcm-parse-huey.c
 
 gcm_parse_huey_LDADD =						\
+	$(COLOR_GLIB_LIBS)					\
 	$(GLIB_LIBS)
 
 gcm_parse_huey_CFLAGS =						\
diff --git a/docs/huey/gcm-parse-huey.c b/docs/huey/gcm-parse-huey.c
index 444361c..5ff1e22 100644
--- a/docs/huey/gcm-parse-huey.c
+++ b/docs/huey/gcm-parse-huey.c
@@ -25,74 +25,7 @@
 
 #include <glib.h>
 
-#define HUEY_RETVAL_SUCCESS		0x00
-#define HUEY_RETVAL_LOCKED		0xc0
-#define HUEY_RETVAL_UNKNOWN_5A		0x5a /* seen in profiling */
-#define HUEY_RETVAL_ERROR		0x80
-#define HUEY_RETVAL_UNKNOWN_81		0x81 /* seen once in init */
-#define HUEY_RETVAL_RETRY		0x90
-
-static const gchar *
-get_return_string (guchar value)
-{
-	if (value == HUEY_RETVAL_SUCCESS)
-		return "success";
-	if (value == HUEY_RETVAL_LOCKED)
-		return "locked";
-	if (value == HUEY_RETVAL_ERROR)
-		return "error";
-	if (value == HUEY_RETVAL_RETRY)
-		return "retry";
-	if (value == HUEY_RETVAL_UNKNOWN_5A)
-		return "unknown5a";
-	if (value == HUEY_RETVAL_UNKNOWN_81)
-		return "unknown81";
-	return NULL;
-}
-
-static const gchar *
-get_command_string (guchar value)
-{
-	if (value == 0x00)
-		return "get-status";
-	if (value == 0x02)
-		return "read-green";
-	if (value == 0x03)
-		return "read-blue";
-	if (value == 0x05)
-		return "set-value";
-	if (value == 0x06)
-		return "get-value";
-	if (value == 0x07)
-		return "unknown07";
-	if (value == 0x08)
-		return "reg-read";
-	if (value == 0x0e)
-		return "unlock";
-	if (value == 0x0f)
-		return "unknown0f";
-	if (value == 0x10)
-		return "unknown10";
-	if (value == 0x11)
-		return "unknown11";
-	if (value == 0x12)
-		return "unknown12";
-	if (value == 0x13)
-		return "measure-rgb-crt";
-	if (value == 0x15)
-		return "unknown15(status?)";
-	if (value == 0x16)
-		return "measure-rgb";
-	if (value == 0x21)
-		return "unknown21";
-	if (value == 0x17)
-		return "ambient";
-	if (value == 0x18)
-		return "set-leds";
-	if (value == 0x19)
-		return "unknown19";
-	return NULL;
-}
+#include "gcm-sensor-huey-private.h"
 
 static void
 parse_command_sequence (GString *output, const gchar *line, gboolean reply)
@@ -111,14 +44,14 @@ parse_command_sequence (GString *output, const gchar *line, gboolean reply)
 		command_as_text = NULL;
 		cmd = g_ascii_strtoll (tok[j], NULL, 16);
 		if (j == 0 && reply) {
-			command_as_text = get_return_string (cmd);
+			command_as_text = gcm_sensor_huey_return_code_to_string (cmd);
 			if (command_as_text == NULL)
 				g_warning ("return code 0x%02x not known in %s", cmd, line);
 		}
 		if ((j == 0 && !reply) ||
 		    (j == 1 && reply)) {
 			instruction = cmd;
-			command_as_text = get_command_string (instruction);
+			command_as_text = gcm_sensor_huey_command_code_to_string (instruction);
 			if (command_as_text == NULL)
 				g_warning ("command code 0x%02x not known", cmd);
 		}
diff --git a/help/.gitignore b/help/.gitignore
index b2752aa..45a4931 100644
--- a/help/.gitignore
+++ b/help/.gitignore
@@ -1,2 +1,2 @@
 gnome-color-manager-*.omf
-
+gnome-color-manager.xml
diff --git a/libcolor-glib/Makefile.am b/libcolor-glib/Makefile.am
index 1c01add..f2cc0ea 100644
--- a/libcolor-glib/Makefile.am
+++ b/libcolor-glib/Makefile.am
@@ -67,6 +67,8 @@ libcolor_glib_la_SOURCES =					\
 	gcm-sensor-client.h					\
 	gcm-sensor-huey.c					\
 	gcm-sensor-huey.h					\
+	gcm-sensor-huey-private.c				\
+	gcm-sensor-huey-private.h				\
 	gcm-sensor-dummy.c					\
 	gcm-sensor-dummy.h					\
 	gcm-tables.c						\
diff --git a/libcolor-glib/gcm-sensor-huey-private.c b/libcolor-glib/gcm-sensor-huey-private.c
new file mode 100644
index 0000000..663f3ca
--- /dev/null
+++ b/libcolor-glib/gcm-sensor-huey-private.c
@@ -0,0 +1,94 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 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
+ */
+
+/**
+ * SECTION:gcm-sensor-huey-private
+ */
+
+#include "gcm-sensor-huey-private.h"
+
+/**
+ * gcm_sensor_huey_return_code_to_string:
+ **/
+const gchar *
+gcm_sensor_huey_return_code_to_string (guchar value)
+{
+	if (value == GCM_SENSOR_HUEY_RETURN_SUCCESS)
+		return "success";
+	if (value == GCM_SENSOR_HUEY_RETURN_LOCKED)
+		return "locked";
+	if (value == GCM_SENSOR_HUEY_RETURN_ERROR)
+		return "error";
+	if (value == GCM_SENSOR_HUEY_RETURN_RETRY)
+		return "retry";
+	if (value == GCM_SENSOR_HUEY_RETURN_UNKNOWN_5A)
+		return "unknown5a";
+	if (value == GCM_SENSOR_HUEY_RETURN_UNKNOWN_81)
+		return "unknown81";
+	return NULL;
+}
+
+/**
+ * gcm_sensor_huey_command_code_to_string:
+ **/
+const gchar *
+gcm_sensor_huey_command_code_to_string (guchar value)
+{
+	if (value == GCM_SENSOR_HUEY_COMMAND_GET_STATUS)
+		return "get-status";
+	if (value == GCM_SENSOR_HUEY_COMMAND_READ_GREEN)
+		return "read-green";
+	if (value == GCM_SENSOR_HUEY_COMMAND_READ_BLUE)
+		return "read-blue";
+	if (value == GCM_SENSOR_HUEY_COMMAND_SET_VALUE)
+		return "set-value";
+	if (value == GCM_SENSOR_HUEY_COMMAND_GET_VALUE)
+		return "get-value";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_07)
+		return "unknown07";
+	if (value == GCM_SENSOR_HUEY_COMMAND_REGISTER_READ)
+		return "reg-read";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNLOCK)
+		return "unlock";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_0F)
+		return "unknown0f";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_10)
+		return "unknown10";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_11)
+		return "unknown11";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_12)
+		return "unknown12";
+	if (value == GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB_CRT)
+		return "measure-rgb-crt";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_15)
+		return "unknown15(status?)";
+	if (value == GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB)
+		return "measure-rgb";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_21)
+		return "unknown21";
+	if (value == GCM_SENSOR_HUEY_COMMAND_GET_AMBIENT)
+		return "ambient";
+	if (value == GCM_SENSOR_HUEY_COMMAND_SET_LEDS)
+		return "set-leds";
+	if (value == GCM_SENSOR_HUEY_COMMAND_UNKNOWN_19)
+		return "unknown19";
+	return NULL;
+}
diff --git a/libcolor-glib/gcm-sensor-huey-private.h b/libcolor-glib/gcm-sensor-huey-private.h
new file mode 100644
index 0000000..f9755a7
--- /dev/null
+++ b/libcolor-glib/gcm-sensor-huey-private.h
@@ -0,0 +1,307 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 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
+ */
+
+#if !defined (LIBCOLOR_GLIB_COMPILATION) && !defined (GCM_I_KNOW_THIS_IS_PRIVATE)
+#error "This header file is for internal use only."
+#endif
+
+#ifndef __GCM_SENSOR_HUEY_PRIVATE_H
+#define __GCM_SENSOR_HUEY_PRIVATE_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define GCM_SENSOR_HUEY_VENDOR_ID				0x0971
+#define GCM_SENSOR_HUEY_PRODUCT_ID				0x2005
+
+/* Return values from the commands */
+#define GCM_SENSOR_HUEY_RETURN_SUCCESS				0x00
+#define GCM_SENSOR_HUEY_RETURN_LOCKED				0xc0
+#define GCM_SENSOR_HUEY_RETURN_UNKNOWN_5A			0x5a /* seen in profiling */
+#define GCM_SENSOR_HUEY_RETURN_ERROR				0x80
+#define GCM_SENSOR_HUEY_RETURN_UNKNOWN_81			0x81 /* seen once in init */
+#define GCM_SENSOR_HUEY_RETURN_RETRY				0x90
+
+/*
+ * Get the currect status of the device
+ *
+ *  input:   00 00 00 00 3f 00 00 00
+ * returns: 00 00 43 69 72 30 30 31  (or)
+ *     "Cir001" --^^^^^^^^^^^^^^^^^ -- Circuit1?...
+ *          c0 00 4c 6f 63 6b 65 64
+ *     "locked" --^^^^^^^^^^^^^^^^^
+ */
+#define GCM_SENSOR_HUEY_COMMAND_GET_STATUS			0x00
+
+/*
+ * Read the green sample data
+ *
+ * input:   02 xx xx xx xx xx xx xx
+ * returns: 00 02 00 00 0a 00 00 00 (or)
+ *          00 02 00 0e c6 80 00 00
+ *            data --^^^^^ ^-- only ever 00 or 80
+ *                    |
+ *                    \-- for RGB(00,00,00) is 09 f2
+ *                            RGB(ff,ff,ff) is 00 00
+ *                            RGB(ff,00,00) is 02 a5
+ *                            RGB(00,ff,00) is 00 f1
+ *                            RGB(00,00,ff) is 08 56
+ *
+ * This doesn't do a sensor read, it seems to be a simple accessor.
+ * GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB has to be used before this one.
+ */
+#define GCM_SENSOR_HUEY_COMMAND_READ_GREEN			0x02
+
+/*
+ * Read the blue sample data
+ *
+ * input:   03 xx xx xx xx xx xx xx
+ * returns: 00 03 00 0f 18 00 00 00
+ *            data --^^^^^ ^-- only ever 00 or 80
+ *                    |
+ *                    \-- for RGB(00,00,00) is 09 64
+ *                            RGB(ff,ff,ff) is 08 80
+ *                            RGB(ff,00,00) is 03 22
+ *                            RGB(00,ff,00) is 00 58
+ *                            RGB(00,00,ff) is 00 59
+ *
+ * This doesn't do a sensor read, it seems to be a simple accessor.
+ * GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB has to be used before this one.
+ */
+#define GCM_SENSOR_HUEY_COMMAND_READ_BLUE			0x03
+
+/*
+ * Set value of some 32 bit register.
+ *
+ * input:   05 ?? 11 12 13 14 xx xx
+ * returns: 00 05 00 00 00 00 00 00
+ *              ^--- always the same no matter the input
+ *
+ * This is never used in profiling
+ */
+#define GCM_SENSOR_HUEY_COMMAND_SET_VALUE			0x05
+
+/*
+ * Get the value of some 32 bit register.
+ *
+ * input:   06 xx xx xx xx xx xx xx
+ * returns: 00 06 11 12 13 14 00 00
+ *    4 bytes ----^^^^^^^^^^^ (from GCM_SENSOR_HUEY_COMMAND_SET_VALUE)
+ *
+ * This is some sort of 32bit register on the device.
+ * The default value at plug-in is 00 0f 42 40, although during
+ * profiling it is set to 00 00 6f 00 and then 00 00 61 00.
+ */
+#define GCM_SENSOR_HUEY_COMMAND_GET_VALUE			0x06
+
+/* NEVER USED */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_07			0x07
+
+/*
+ * Reads a register value.
+ *
+ * (sent at startup  after the unlock)
+ * input:   08 0b xx xx xx xx xx xx
+ *             ^^-- register address
+ * returns: 00 08 0b b8 00 00 00 00
+ *      address --^^ ^^-- value
+ *
+ * It appears you can only ask for one byte at a time.
+ */
+#define GCM_SENSOR_HUEY_COMMAND_REGISTER_READ			0x08
+
+/*
+ * Unlock a locked sensor.
+ *
+ * input:   0e 47 72 4d 62 6b 65 64
+ *  "GrMbked"--^^^^^^^^^^^^^^^^^^^^
+ * returns: 00 0e 00 00 00 00 00 00
+ *
+ * It might be only GrMbk that is needed to unlock.
+ * We still don't know how to 'lock' a device, it just kinda happens.
+ */
+#define GCM_SENSOR_HUEY_COMMAND_UNLOCK				0x0e
+
+/*
+ * Unknown command
+ *
+ * returns: all NULL all of the time */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_0F			0x0f
+
+/*
+ * Unknown command
+ *
+ * Something to do with sampling */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_10			0x10
+
+/*
+ * Unknown command
+ *
+ * Something to do with sampling (that needs a retry with code 5a)
+ */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_11			0x11
+
+/*
+ * Unknown command
+ *
+ * something to do with sampling
+ */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_12			0x12
+
+/*
+ * Measures RGB value, and return the red value (only used in CRT mode).
+ *
+ * Seems to have to retry, every single time.
+ *
+ *                   Gain?
+ *              _______|_______
+ *             /---\ /---\ /---\
+ * input:   13 02 41 00 54 00 49 00
+ * returns: 00 13 00 00 01 99 02 00
+ *                   ^^^^^ - would match GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB
+ *
+ * The gain seems not to change for different measurements with different
+ * colors. This seems to be a less precise profile too.
+ */
+#define GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB_CRT		0x13
+
+/*
+ * Unknown command
+ *
+ * returns: seems to be sent, but not requested
+ */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_15			0x15
+
+/*
+ * Sample a color and return the red component
+ *
+ * input:   16 00 01 00 01 00 01 00
+ * returns: 00 16 00 00 00 00 00 00
+ *
+ * or:
+ *             ,,-,,-,,-,,-,,-,,-- 'gain control'
+ *             || || || || || ||
+ * input:   16 00 35 00 48 00 1d 03
+ * returns: 00 16 00 0b d0 00 00 00
+ *            data --^^^^^ ^^-- only ever 00 or 80
+ *
+ * This is used when profiling, and all commands are followed by
+ * GCM_SENSOR_HUEY_COMMAND_READ_GREEN and HUEY_COMMAND_READ_BLUE.
+ * 
+ * The returned values are some kind of 16 bit register count that
+ * indicate how much light fell on a sensor. If the sensors are
+ * converting light to pulses, then the 'gain' control tells the sensor
+ * how long to read. It's therefore quicker to read white than black.
+ *
+ * Given there exists only GREEN and BLUE accessors, and that RED comes
+ * first in a RGB sequence, I think it's safe to assume that this command
+ * does the measurement, and the others just return cached data.
+ *
+ * argyll does (for #ff0000)
+ *
+ * -> 16 00 01 00 01 00 01 00
+ * <-       00 00 0b 00 00 00
+ * -> 02 xx xx xx xx xx xx xx
+ * <-       00 00 12 00 00 00
+ * -> 03 xx xx xx xx xx xx xx
+ * <-       00 03 41 00 00 00
+ *
+ * then does:
+ *
+ * -> 16 01 63 00 d9 00 04 00
+ * <-       00 0f ce 80 00 00
+ * -> 02 xx xx xx xx xx xx xx
+ * <-       00 0e d0 80 00 00
+ * -> 03 xx xx xx xx xx xx xx
+ * <-       00 0d 3c 00 00 00
+ *
+ * then returns XYZ=87.239169 45.548708 1.952249
+ */
+#define GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB		0x16
+
+/*
+ * Unknown command (some sort of poll?)
+ *
+ * input:   21 09 00 02 00 00 08 00 (or)
+ * returns: [never seems to return a value]
+ *
+ * Only when profiling, and over and over.
+ */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_21			0x21
+
+/*
+ * Get the level of ambient light from the sensor
+ *
+ *                 ,,--- The output-type, where 00 is LCD and 02 is CRT
+ *  input:   17 03 00 xx xx xx xx xx
+ * returns: 90 17 03 00 00 00 00 00  then on second read:
+ * 	    00 17 03 00 00 62 57 00 in light (or)
+ * 	    00 17 03 00 00 00 08 00 in dark
+ * 	no idea	--^^       ^---^ = 16bits data
+ */
+#define GCM_SENSOR_HUEY_COMMAND_GET_AMBIENT			0x17
+
+/*
+ * Set the LEDs on the sensor
+ *
+ * input:   18 00 f0 xx xx xx xx xx
+ * returns: 00 18 f0 00 00 00 00 00
+ *   led mask ----^^
+ */
+#define GCM_SENSOR_HUEY_COMMAND_SET_LEDS			0x18
+
+/*
+ * Unknown command
+ *
+ * returns: all NULL for NULL input: times out for f1 f2 f3 f4 f5 f6 f7 f8 */
+#define GCM_SENSOR_HUEY_COMMAND_UNKNOWN_19			0x19
+
+/*
+ * Register map:
+ *     x0  x1  x2  x3  x4  x5  x6  x7  x8  x9  xA  xB  xC  xD  xE  xF
+ * 0x [serial-number.][matrix-lcd....................................|
+ * 1x ...............................................................|
+ * 2x .......]                                                       |
+ * 3x         [calib-lcd-time][matrix-crt............................|
+ * 4x ...............................................................|
+ * 5x .......................................][calib-crt-time]       |
+ * 6x                             [calib_vector......................|
+ * 7x ...........]                            [unlock-string.....]   |
+ * 8x                                                                |
+ * 9x                             [calib_value...]                   |
+ */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_SERIAL			0x00 /* 4 bytes */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_CALIBRATION_DATA_LCD	0x04 /* 36 bytes */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_CALIBRATION_TIME_LCD	0x32 /* 4 bytes */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_CALIBRATION_DATA_CRT	0x36 /* 36 bytes */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_CALIBRATION_TIME_CRT	0x5a /* 4 bytes */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_DARK_OFFSET			0x67 /* 12 bytes */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_UNLOCK			0x7a /* 5 bytes */
+#define GCM_SENSOR_HUEY_EEPROM_ADDR_CALIB_VALUE			0x94 /* 4 bytes */
+
+const gchar	*gcm_sensor_huey_return_code_to_string		(guchar	 value);
+const gchar	*gcm_sensor_huey_command_code_to_string		(guchar	 value);
+
+G_END_DECLS
+
+#endif /* __GCM_SENSOR_HUEY_PRIVATE_H */
+
diff --git a/libcolor-glib/gcm-sensor-huey.c b/libcolor-glib/gcm-sensor-huey.c
index 9e767a6..3267c36 100644
--- a/libcolor-glib/gcm-sensor-huey.c
+++ b/libcolor-glib/gcm-sensor-huey.c
@@ -38,6 +38,7 @@
 #include "gcm-math.h"
 #include "gcm-compat.h"
 #include "gcm-sensor-huey.h"
+#include "gcm-sensor-huey-private.h"
 
 static void     gcm_sensor_huey_finalize	(GObject     *object);
 
@@ -73,253 +74,10 @@ static gboolean gcm_sensor_huey_startup (GcmSensor *sensor, GError **error);
 
 G_DEFINE_TYPE (GcmSensorHuey, gcm_sensor_huey, GCM_TYPE_SENSOR)
 
-#define HUEY_VENDOR_ID			0x0971
-#define HUEY_PRODUCT_ID			0x2005
 #define HUEY_CONTROL_MESSAGE_TIMEOUT	50000 /* ms */
 #define HUEY_MAX_READ_RETRIES		5
 
-#define HUEY_RETVAL_SUCCESS		0x00
-#define HUEY_RETVAL_LOCKED		0xc0
-#define HUEY_RETVAL_UNKNOWN_5A		0x5a /* seen in profiling */
-#define HUEY_RETVAL_ERROR		0x80
-#define HUEY_RETVAL_UNKNOWN_81		0x81 /* seen once in init */
-#define HUEY_RETVAL_RETRY		0x90
-
-/*
- * Get the currect status of the device
- *
- *  input:   00 00 00 00 3f 00 00 00
- * returns: 00 00 43 69 72 30 30 31  (or)
- *     "Cir001" --^^^^^^^^^^^^^^^^^ -- Circuit1?...
- *          c0 00 4c 6f 63 6b 65 64
- *     "locked" --^^^^^^^^^^^^^^^^^
- */
-#define HUEY_COMMAND_GET_STATUS		0x00
-
-/*
- * Read the green sample data
- *
- * input:   02 xx xx xx xx xx xx xx
- * returns: 00 02 00 00 0a 00 00 00 (or)
- *          00 02 00 0e c6 80 00 00
- *            data --^^^^^ ^-- only ever 00 or 80
- *                    |
- *                    \-- for RGB(00,00,00) is 09 f2
- *                            RGB(ff,ff,ff) is 00 00
- *                            RGB(ff,00,00) is 02 a5
- *                            RGB(00,ff,00) is 00 f1
- *                            RGB(00,00,ff) is 08 56
- *
- * This doesn't do a sensor read, it seems to be a simple accessor.
- * HUEY_COMMAND_SENSOR_MEASURE_RGB has to be used before this one.
- */
-#define HUEY_COMMAND_READ_GREEN		0x02
-
-/*
- * Read the blue sample data
- *
- * input:   03 xx xx xx xx xx xx xx
- * returns: 00 03 00 0f 18 00 00 00
- *            data --^^^^^ ^-- only ever 00 or 80
- *                    |
- *                    \-- for RGB(00,00,00) is 09 64
- *                            RGB(ff,ff,ff) is 08 80
- *                            RGB(ff,00,00) is 03 22
- *                            RGB(00,ff,00) is 00 58
- *                            RGB(00,00,ff) is 00 59
- *
- * This doesn't do a sensor read, it seems to be a simple accessor.
- * HUEY_COMMAND_SENSOR_MEASURE_RGB has to be used before this one.
- */
-#define HUEY_COMMAND_READ_BLUE	0x03
-
-/*
- * Set value of some 32 bit register.
- *
- * input:   05 ?? 11 12 13 14 xx xx
- * returns: 00 05 00 00 00 00 00 00
- *              ^--- always the same no matter the input
- *
- * This is never used in profiling
- */
-#define HUEY_COMMAND_SET_VALUE		0x05
-
-/*
- * Get the value of some 32 bit register.
- *
- * input:   06 xx xx xx xx xx xx xx
- * returns: 00 06 11 12 13 14 00 00
- *    4 bytes ----^^^^^^^^^^^ (from HUEY_COMMAND_SET_VALUE)
- *
- * This is some sort of 32bit register on the device.
- * The default value at plug-in is 00 0f 42 40, although during
- * profiling it is set to 00 00 6f 00 and then 00 00 61 00.
- */
-#define HUEY_COMMAND_GET_VALUE		0x06
-
-/* NEVER USED */
-#define HUEY_COMMAND_UNKNOWN_07		0x07
-
-/*
- * Reads a register value.
- *
- * (sent at startup  after the unlock)
- * input:   08 0b xx xx xx xx xx xx
- *             ^^-- register address
- * returns: 00 08 0b b8 00 00 00 00
- *      address --^^ ^^-- value
- *
- * It appears you can only ask for one byte at a time.
- */
-#define HUEY_COMMAND_REGISTER_READ	0x08
-
-/*
- * Unlock a locked sensor.
- *
- * input:   0e 47 72 4d 62 6b 65 64
- *  "GrMbked"--^^^^^^^^^^^^^^^^^^^^
- * returns: 00 0e 00 00 00 00 00 00
- *
- * It might be only GrMbk that is needed to unlock.
- * We still don't know how to 'lock' a device, it just kinda happens.
- */
-#define HUEY_COMMAND_UNLOCK		0x0e
-
-/*
- * Unknown command
- *
- * returns: all NULL all of the time */
-#define HUEY_COMMAND_UNKNOWN_0F		0x0f
-
-/*
- * Unknown command
- *
- * Something to do with sampling */
-#define HUEY_COMMAND_UNKNOWN_10		0x10
-
-/*
- * Unknown command
- *
- * Something to do with sampling (that needs a retry with code 5a)
- */
-#define HUEY_COMMAND_UNKNOWN_11		0x11
-
-/*
- * Unknown command
- *
- * something to do with sampling
- */
-#define HUEY_COMMAND_UNKNOWN_12		0x12
-
-/*
- * Measures RGB value, and return the red value (only used in CRT mode).
- *
- * Seems to have to retry, every single time.
- *
- *                   Gain?
- *              _______|_______
- *             /---\ /---\ /---\
- * input:   13 02 41 00 54 00 49 00
- * returns: 00 13 00 00 01 99 02 00
- *                   ^^^^^ - would match HUEY_COMMAND_SENSOR_MEASURE_RGB
- *
- * The gain seems not to change for different measurements with different
- * colors. This seems to be a less precise profile too.
- */
-#define HUEY_COMMAND_SENSOR_MEASURE_RGB_CRT	0x13
-
-/*
- * Unknown command
- *
- * returns: seems to be sent, but not requested
- */
-#define HUEY_COMMAND_UNKNOWN_15		0x15
-
-/*
- * Sample a color and return the red component
- *
- * input:   16 00 01 00 01 00 01 00
- * returns: 00 16 00 00 00 00 00 00
- *
- * or:
- *             ,,-,,-,,-,,-,,-,,-- 'gain control'
- *             || || || || || ||
- * input:   16 00 35 00 48 00 1d 03
- * returns: 00 16 00 0b d0 00 00 00
- *            data --^^^^^ ^^-- only ever 00 or 80
- *
- * This is used when profiling, and all commands are followed by
- * HUEY_COMMAND_READ_GREEN and HUEY_COMMAND_READ_BLUE.
- * 
- * The returned values are some kind of 16 bit register count that
- * indicate how much light fell on a sensor. If the sensors are
- * converting light to pulses, then the 'gain' control tells the sensor
- * how long to read. It's therefore quicker to read white than black.
- *
- * Given there exists only GREEN and BLUE accessors, and that RED comes
- * first in a RGB sequence, I think it's safe to assume that this command
- * does the measurement, and the others just return cached data.
- *
- * argyll does (for #ff0000)
- *
- * -> 16 00 01 00 01 00 01 00
- * <-       00 00 0b 00 00 00
- * -> 02 xx xx xx xx xx xx xx
- * <-       00 00 12 00 00 00
- * -> 03 xx xx xx xx xx xx xx
- * <-       00 03 41 00 00 00
- *
- * then does:
- *
- * -> 16 01 63 00 d9 00 04 00
- * <-       00 0f ce 80 00 00
- * -> 02 xx xx xx xx xx xx xx
- * <-       00 0e d0 80 00 00
- * -> 03 xx xx xx xx xx xx xx
- * <-       00 0d 3c 00 00 00
- *
- * then returns XYZ=87.239169 45.548708 1.952249
- */
-#define HUEY_COMMAND_SENSOR_MEASURE_RGB		0x16
-
-/*
- * Unknown command (some sort of poll?)
- *
- * input:   21 09 00 02 00 00 08 00 (or)
- * returns: [never seems to return a value]
- *
- * Only when profiling, and over and over.
- */
-#define HUEY_COMMAND_UNKNOWN_21		0x21
-
-/*
- * Get the level of ambient light from the sensor
- *
- *                 ,,--- The output-type, where 00 is LCD and 02 is CRT
- *  input:   17 03 00 xx xx xx xx xx
- * returns: 90 17 03 00 00 00 00 00  then on second read:
- * 	    00 17 03 00 00 62 57 00 in light (or)
- * 	    00 17 03 00 00 00 08 00 in dark
- * 	no idea	--^^       ^---^ = 16bits data
- */
-#define HUEY_COMMAND_GET_AMBIENT	0x17
-
-/*
- * Set the LEDs on the sensor
- *
- * input:   18 00 f0 xx xx xx xx xx
- * returns: 00 18 f0 00 00 00 00 00
- *   led mask ----^^
- */
-#define HUEY_COMMAND_SET_LEDS		0x18
-
-/*
- * Unknown command
- *
- * returns: all NULL for NULL input: times out for f1 f2 f3 f4 f5 f6 f7 f8 */
-#define HUEY_COMMAND_UNKNOWN_19		0x19
-
-/* fudge factor to convert the value of HUEY_COMMAND_GET_AMBIENT to Lux */
+/* fudge factor to convert the value of GCM_SENSOR_HUEY_COMMAND_GET_AMBIENT to Lux */
 #define HUEY_AMBIENT_UNITS_TO_LUX	125.0f
 
 /* this is the same approx ratio as argyll uses to find the best accuracy
@@ -331,29 +89,6 @@ G_DEFINE_TYPE (GcmSensorHuey, gcm_sensor_huey, GCM_TYPE_SENSOR)
  * indicates we doing something wrong. */
 #define HUEY_XYZ_POST_MULTIPLY_SCALE_FACTOR	3.347250f
 
-/*
- * Register map:
- *     x0  x1  x2  x3  x4  x5  x6  x7  x8  x9  xA  xB  xC  xD  xE  xF
- * 0x [serial-number.][matrix-lcd....................................|
- * 1x ...............................................................|
- * 2x .......]                                                       |
- * 3x         [calib-lcd-time][matrix-crt............................|
- * 4x ...............................................................|
- * 5x .......................................][calib-crt-time]       |
- * 6x                             [calib_vector......................|
- * 7x ...........]                            [unlock-string.....]   |
- * 8x                                                                |
- * 9x                             [calib_value...]                   |
- */
-#define HUEY_EEPROM_ADDR_SERIAL			0x00 /* 4 bytes */
-#define HUEY_EEPROM_ADDR_CALIBRATION_DATA_LCD	0x04 /* 36 bytes */
-#define HUEY_EEPROM_ADDR_CALIBRATION_TIME_LCD	0x32 /* 4 bytes */
-#define HUEY_EEPROM_ADDR_CALIBRATION_DATA_CRT	0x36 /* 36 bytes */
-#define HUEY_EEPROM_ADDR_CALIBRATION_TIME_CRT	0x5a /* 4 bytes */
-#define HUEY_EEPROM_ADDR_DARK_OFFSET		0x67 /* 12 bytes */
-#define HUEY_EEPROM_ADDR_UNLOCK			0x7a /* 5 bytes */
-#define HUEY_EEPROM_ADDR_CALIB_VALUE		0x94 /* 4 bytes */
-
 /**
  * gcm_sensor_huey_print_data:
  **/
@@ -440,13 +175,13 @@ gcm_sensor_huey_send_data (GcmSensorHuey *sensor_huey,
 		}
 
 		/* the first byte is status */
-		if (reply[0] == HUEY_RETVAL_SUCCESS) {
+		if (reply[0] == GCM_SENSOR_HUEY_RETURN_SUCCESS) {
 			ret = TRUE;
 			break;
 		}
 
 		/* failure, the return buffer is set to "Locked" */
-		if (reply[0] == HUEY_RETVAL_LOCKED) {
+		if (reply[0] == GCM_SENSOR_HUEY_RETURN_LOCKED) {
 			g_set_error_literal (error, GCM_SENSOR_ERROR,
 					     GCM_SENSOR_ERROR_INTERNAL,
 					     "the device is locked");
@@ -454,7 +189,7 @@ gcm_sensor_huey_send_data (GcmSensorHuey *sensor_huey,
 		}
 
 		/* failure, the return buffer is set to "NoCmd" */
-		if (reply[0] == HUEY_RETVAL_ERROR) {
+		if (reply[0] == GCM_SENSOR_HUEY_RETURN_ERROR) {
 			g_set_error (error, GCM_SENSOR_ERROR,
 				     GCM_SENSOR_ERROR_INTERNAL,
 				     "failed to issue command: %s", &reply[2]);
@@ -462,7 +197,7 @@ gcm_sensor_huey_send_data (GcmSensorHuey *sensor_huey,
 		}
 
 		/* we ignore retry */
-		if (reply[0] != HUEY_RETVAL_RETRY) {
+		if (reply[0] != GCM_SENSOR_HUEY_RETURN_RETRY) {
 			g_set_error (error, GCM_SENSOR_ERROR,
 				     GCM_SENSOR_ERROR_INTERNAL,
 				     "return value unknown: 0x%02x", reply[0]);
@@ -487,7 +222,7 @@ out:
 static gboolean
 gcm_sensor_huey_read_register_byte (GcmSensorHuey *sensor_huey, guint8 addr, guint8 *value, GError **error)
 {
-	guchar request[] = { HUEY_COMMAND_REGISTER_READ, 0xff, 0x00, 0x10, 0x3c, 0x06, 0x00, 0x00 };
+	guchar request[] = { GCM_SENSOR_HUEY_COMMAND_REGISTER_READ, 0xff, 0x00, 0x10, 0x3c, 0x06, 0x00, 0x00 };
 	guchar reply[8];
 	gboolean ret;
 	gsize reply_read;
@@ -669,7 +404,7 @@ gcm_sensor_huey_get_ambient_thread_cb (GSimpleAsyncResult *res, GObject *object,
 	gboolean ret = FALSE;
 	gsize reply_read;
 	GcmSensorOutputType output_type;
-	guchar request[] = { HUEY_COMMAND_GET_AMBIENT, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+	guchar request[] = { GCM_SENSOR_HUEY_COMMAND_GET_AMBIENT, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 	GcmSensorHuey *sensor_huey = GCM_SENSOR_HUEY (sensor);
 
 	/* ensure sensor is started */
@@ -784,7 +519,7 @@ gcm_sensor_huey_set_leds (GcmSensor *sensor, guint8 value, GError **error)
 	guchar reply[8];
 	gsize reply_read;
 	GcmSensorHuey *sensor_huey = GCM_SENSOR_HUEY (sensor);
-	guchar payload[] = { HUEY_COMMAND_SET_LEDS, 0x00, ~value, 0x00, 0x00, 0x00, 0x00, 0x00 };
+	guchar payload[] = { GCM_SENSOR_HUEY_COMMAND_SET_LEDS, 0x00, ~value, 0x00, 0x00, 0x00, 0x00, 0x00 };
 	return gcm_sensor_huey_send_data (sensor_huey, payload, 8, reply, 8, &reply_read, error);
 }
 
@@ -800,7 +535,7 @@ typedef struct {
 static gboolean
 gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmSensorHueyMultiplier *threshold, GcmColorRGB *values, GError **error)
 {
-	guchar request[] = { HUEY_COMMAND_SENSOR_MEASURE_RGB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+	guchar request[] = { GCM_SENSOR_HUEY_COMMAND_SENSOR_MEASURE_RGB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 	guchar reply[8];
 	gboolean ret;
 	gsize reply_read;
@@ -819,7 +554,7 @@ gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmSensorHueyM
 	values->R = (gdouble) threshold->R / (gdouble)gcm_buffer_read_uint16_be (reply+3);
 
 	/* get green */
-	request[0] = HUEY_COMMAND_READ_GREEN;
+	request[0] = GCM_SENSOR_HUEY_COMMAND_READ_GREEN;
 	ret = gcm_sensor_huey_send_data (sensor_huey, request, 8, reply, 8, &reply_read, error);
 	if (!ret)
 		goto out;
@@ -828,7 +563,7 @@ gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmSensorHueyM
 	values->G = (gdouble) threshold->G / (gdouble)gcm_buffer_read_uint16_be (reply+3);
 
 	/* get blue */
-	request[0] = HUEY_COMMAND_READ_BLUE;
+	request[0] = GCM_SENSOR_HUEY_COMMAND_READ_BLUE;
 	ret = gcm_sensor_huey_send_data (sensor_huey, request, 8, reply, 8, &reply_read, error);
 	if (!ret)
 		goto out;
@@ -1037,7 +772,7 @@ gcm_sensor_huey_send_unlock (GcmSensorHuey *sensor_huey, GError **error)
 	gboolean ret;
 	gsize reply_read;
 
-	request[0] = HUEY_COMMAND_UNLOCK;
+	request[0] = GCM_SENSOR_HUEY_COMMAND_UNLOCK;
 	request[1] = 'G';
 	request[2] = 'r';
 	request[3] = 'M';
@@ -1070,7 +805,7 @@ gcm_sensor_huey_startup (GcmSensor *sensor, GError **error)
 
 	/* connect */
 	ret = gcm_usb_connect (priv->usb,
-			       HUEY_VENDOR_ID, HUEY_PRODUCT_ID,
+			       GCM_SENSOR_HUEY_VENDOR_ID, GCM_SENSOR_HUEY_PRODUCT_ID,
 			       0x01, 0x00, error);
 	if (!ret)
 		goto out;
@@ -1084,7 +819,9 @@ gcm_sensor_huey_startup (GcmSensor *sensor, GError **error)
 		goto out;
 
 	/* get serial number */
-	ret = gcm_sensor_huey_read_register_word (sensor_huey, HUEY_EEPROM_ADDR_SERIAL, &serial_number, error);
+	ret = gcm_sensor_huey_read_register_word (sensor_huey,
+						  GCM_SENSOR_HUEY_EEPROM_ADDR_SERIAL,
+						  &serial_number, error);
 	if (!ret)
 		goto out;
 	serial_number_tmp = g_strdup_printf ("%i", serial_number);
@@ -1092,32 +829,42 @@ gcm_sensor_huey_startup (GcmSensor *sensor, GError **error)
 	egg_debug ("Serial number: %s", serial_number_tmp);
 
 	/* get unlock string */
-	ret = gcm_sensor_huey_read_register_string (sensor_huey, HUEY_EEPROM_ADDR_UNLOCK, priv->unlock_string, 5, error);
+	ret = gcm_sensor_huey_read_register_string (sensor_huey,
+						    GCM_SENSOR_HUEY_EEPROM_ADDR_UNLOCK,
+						    priv->unlock_string, 5, error);
 	if (!ret)
 		goto out;
 	egg_debug ("Unlock string: %s", priv->unlock_string);
 
 	/* get matrix */
 	gcm_mat33_clear (&priv->calibration_lcd);
-	ret = gcm_sensor_huey_read_register_matrix (sensor_huey, HUEY_EEPROM_ADDR_CALIBRATION_DATA_LCD, &priv->calibration_lcd, error);
+	ret = gcm_sensor_huey_read_register_matrix (sensor_huey,
+						    GCM_SENSOR_HUEY_EEPROM_ADDR_CALIBRATION_DATA_LCD,
+						    &priv->calibration_lcd, error);
 	if (!ret)
 		goto out;
 	egg_debug ("device matrix1: %s", gcm_mat33_to_string (&priv->calibration_lcd));
 
 	/* get another matrix, although this one is different... */
 	gcm_mat33_clear (&priv->calibration_crt);
-	ret = gcm_sensor_huey_read_register_matrix (sensor_huey, HUEY_EEPROM_ADDR_CALIBRATION_DATA_CRT, &priv->calibration_crt, error);
+	ret = gcm_sensor_huey_read_register_matrix (sensor_huey,
+						    GCM_SENSOR_HUEY_EEPROM_ADDR_CALIBRATION_DATA_CRT,
+						    &priv->calibration_crt, error);
 	if (!ret)
 		goto out;
 	egg_debug ("device matrix2: %s", gcm_mat33_to_string (&priv->calibration_crt));
 
 	/* this number is different on all three hueys */
-	ret = gcm_sensor_huey_read_register_float (sensor_huey, HUEY_EEPROM_ADDR_CALIB_VALUE, &priv->calibration_value, error);
+	ret = gcm_sensor_huey_read_register_float (sensor_huey,
+						   GCM_SENSOR_HUEY_EEPROM_ADDR_CALIB_VALUE,
+						   &priv->calibration_value, error);
 	if (!ret)
 		goto out;
 
 	/* this vector changes between sensor 1 and 3 */
-	ret = gcm_sensor_huey_read_register_vector (sensor_huey, HUEY_EEPROM_ADDR_DARK_OFFSET, &priv->dark_offset, error);
+	ret = gcm_sensor_huey_read_register_vector (sensor_huey,
+						    GCM_SENSOR_HUEY_EEPROM_ADDR_DARK_OFFSET,
+						    &priv->dark_offset, error);
 	if (!ret)
 		goto out;
 



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