[gnome-color-manager] trivial: move the ColorMunki driver into libcolor-glib and create the private files needed for debug



commit 7a4deeb534795a43b5cdeafa214bd362f1b3196d
Author: Richard Hughes <richard hughsie com>
Date:   Wed Sep 29 14:03:43 2010 +0100

    trivial: move the ColorMunki driver into libcolor-glib and create the private files needed for debugging

 libcolor-glib/Makefile.am                        |    4 +
 libcolor-glib/gcm-sensor-colormunki-private.c    |   71 ++++++++++++++++++++++
 libcolor-glib/gcm-sensor-colormunki-private.h    |   58 ++++++++++++++++++
 {tools => libcolor-glib}/gcm-sensor-colormunki.c |   62 ++++++-------------
 {tools => libcolor-glib}/gcm-sensor-colormunki.h |    0
 tools/Makefile.am                                |    2 -
 6 files changed, 153 insertions(+), 44 deletions(-)
---
diff --git a/libcolor-glib/Makefile.am b/libcolor-glib/Makefile.am
index f2cc0ea..09da129 100644
--- a/libcolor-glib/Makefile.am
+++ b/libcolor-glib/Makefile.am
@@ -69,6 +69,10 @@ libcolor_glib_la_SOURCES =					\
 	gcm-sensor-huey.h					\
 	gcm-sensor-huey-private.c				\
 	gcm-sensor-huey-private.h				\
+	gcm-sensor-colormunki.c					\
+	gcm-sensor-colormunki.h					\
+	gcm-sensor-colormunki-private.c				\
+	gcm-sensor-colormunki-private.h				\
 	gcm-sensor-dummy.c					\
 	gcm-sensor-dummy.h					\
 	gcm-tables.c						\
diff --git a/libcolor-glib/gcm-sensor-colormunki-private.c b/libcolor-glib/gcm-sensor-colormunki-private.c
new file mode 100644
index 0000000..89ff978
--- /dev/null
+++ b/libcolor-glib/gcm-sensor-colormunki-private.c
@@ -0,0 +1,71 @@
+/* -*- 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-colormunki-private
+ */
+
+#include "gcm-sensor-colormunki-private.h"
+
+/**
+ * gcm_sensor_colormunki_command_value_to_string:
+ **/
+const gchar *
+gcm_sensor_colormunki_command_value_to_string (guchar value)
+{
+	if (value == GCM_SENSOR_COLORMUNKI_COMMAND_DIAL_ROTATE)
+		return "dial-rotate";
+	if (value == GCM_SENSOR_COLORMUNKI_COMMAND_BUTTON_PRESSED)
+		return "button-released";
+	if (value == GCM_SENSOR_COLORMUNKI_COMMAND_BUTTON_RELEASED)
+		return "button-released";
+	return NULL;
+}
+
+/**
+ * gcm_sensor_colormunki_button_state_to_string:
+ **/
+const gchar *
+gcm_sensor_colormunki_button_state_to_string (guchar value)
+{
+	if (value == GCM_SENSOR_COLORMUNKI_BUTTON_STATE_RELEASED)
+		return "released";
+	if (value == GCM_SENSOR_COLORMUNKI_BUTTON_STATE_PRESSED)
+		return "pressed";
+	return NULL;
+}
+
+/**
+ * gcm_sensor_colormunki_dial_position_to_string:
+ **/
+const gchar *
+gcm_sensor_colormunki_dial_position_to_string (guchar value)
+{
+	if (value == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_PROJECTOR)
+		return "projector";
+	if (value == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_SURFACE)
+		return "surface";
+	if (value == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_CALIBRATION)
+		return "calibration";
+	if (value == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_AMBIENT)
+		return "ambient";
+	return NULL;
+}
diff --git a/libcolor-glib/gcm-sensor-colormunki-private.h b/libcolor-glib/gcm-sensor-colormunki-private.h
new file mode 100644
index 0000000..7e091b8
--- /dev/null
+++ b/libcolor-glib/gcm-sensor-colormunki-private.h
@@ -0,0 +1,58 @@
+/* -*- 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_COLORMUNKI_PRIVATE_H
+#define __GCM_SENSOR_COLORMUNKI_PRIVATE_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#define GCM_SENSOR_COLORMUNKI_VENDOR_ID				0x0971
+#define GCM_SENSOR_COLORMUNKI_PRODUCT_ID			0x2007
+
+#define GCM_SENSOR_COLORMUNKI_COMMAND_DIAL_ROTATE		0x00
+#define GCM_SENSOR_COLORMUNKI_COMMAND_BUTTON_PRESSED		0x01
+#define GCM_SENSOR_COLORMUNKI_COMMAND_BUTTON_RELEASED		0x02
+
+#define	GCM_SENSOR_COLORMUNKI_BUTTON_STATE_RELEASED		0x00
+#define	GCM_SENSOR_COLORMUNKI_BUTTON_STATE_PRESSED		0x01
+
+#define	GCM_SENSOR_COLORMUNKI_DIAL_POSITION_PROJECTOR		0x00
+#define	GCM_SENSOR_COLORMUNKI_DIAL_POSITION_SURFACE		0x01
+#define	GCM_SENSOR_COLORMUNKI_DIAL_POSITION_CALIBRATION		0x02
+#define	GCM_SENSOR_COLORMUNKI_DIAL_POSITION_AMBIENT		0x03
+#define	GCM_SENSOR_COLORMUNKI_DIAL_POSITION_UNKNOWN		0xff
+
+#define	COLORMUNKI_EEPROM_OFFSET_SERIAL_NUMBER			0x0018
+
+const gchar	*gcm_sensor_colormunki_button_state_to_string	(guchar	 value);
+const gchar	*gcm_sensor_colormunki_dial_position_to_string	(guchar	 value);
+const gchar	*gcm_sensor_colormunki_command_value_to_string	(guchar	 value);
+
+G_END_DECLS
+
+#endif /* __GCM_SENSOR_COLORMUNKI_PRIVATE_H */
+
diff --git a/tools/gcm-sensor-colormunki.c b/libcolor-glib/gcm-sensor-colormunki.c
similarity index 91%
rename from tools/gcm-sensor-colormunki.c
rename to libcolor-glib/gcm-sensor-colormunki.c
index 23d0116..dc443db 100644
--- a/tools/gcm-sensor-colormunki.c
+++ b/libcolor-glib/gcm-sensor-colormunki.c
@@ -35,19 +35,13 @@
 #include "egg-debug.h"
 
 #include "gcm-sensor-colormunki.h"
+#include "gcm-sensor-colormunki-private.h"
 
 static void     gcm_sensor_colormunki_finalize	(GObject     *object);
 
 #define GCM_SENSOR_COLORMUNKI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_SENSOR_COLORMUNKI, GcmSensorColormunkiPrivate))
 
-typedef enum {
-	GCM_COLORMUNKI_DIAL_POSITION_UNKNOWN,
-	GCM_COLORMUNKI_DIAL_POSITION_PROJECTOR,
-	GCM_COLORMUNKI_DIAL_POSITION_SURFACE,
-	GCM_COLORMUNKI_DIAL_POSITION_CALIBRATION,
-	GCM_COLORMUNKI_DIAL_POSITION_AMBIENT,
-	GCM_COLORMUNKI_DIAL_POSITION_LAST
-} GcmSensorColormunkiDialPosition;
+typedef gint GcmSensorColormunkiDialPosition;
 
 /**
  * GcmSensorColormunkiPrivate:
@@ -71,23 +65,6 @@ struct _GcmSensorColormunkiPrivate
 
 G_DEFINE_TYPE (GcmSensorColormunki, gcm_sensor_colormunki, GCM_TYPE_SENSOR)
 
-#define COLORMUNKI_VENDOR_ID			0x0971
-#define COLORMUNKI_PRODUCT_ID			0x2007
-
-#define COLORMUNKI_COMMAND_DIAL_ROTATE		0x00
-#define COLORMUNKI_COMMAND_BUTTON_PRESSED	0x01
-#define COLORMUNKI_COMMAND_BUTTON_RELEASED	0x02
-
-#define	COLORMUNKI_BUTTON_STATE_RELEASED	0x00
-#define	COLORMUNKI_BUTTON_STATE_PRESSED		0x01
-
-#define	COLORMUNKI_DIAL_POSITION_PROJECTOR	0x00
-#define	COLORMUNKI_DIAL_POSITION_SURFACE	0x01
-#define	COLORMUNKI_DIAL_POSITION_CALIBRATION	0x02
-#define	COLORMUNKI_DIAL_POSITION_AMBIENT	0x03
-
-#define	COLORMUNKI_EEPROM_OFFSET_SERIAL_NUMBER	0x0018
-
 /**
  * gcm_sensor_colormunki_print_data:
  **/
@@ -139,27 +116,27 @@ gcm_sensor_colormunki_refresh_state_transfer_cb (struct libusb_transfer *transfe
 	 * - 02 = calibration
 	 * - 03 = ambient
 	 */
-	if (reply[0] == COLORMUNKI_DIAL_POSITION_PROJECTOR) {
+	if (reply[0] == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_PROJECTOR) {
 		egg_debug ("now projector");
-		priv->dial_position = GCM_COLORMUNKI_DIAL_POSITION_PROJECTOR;
-	} else if (reply[0] == COLORMUNKI_DIAL_POSITION_SURFACE) {
+		priv->dial_position = GCM_SENSOR_COLORMUNKI_DIAL_POSITION_PROJECTOR;
+	} else if (reply[0] == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_SURFACE) {
 		egg_debug ("now surface");
-		priv->dial_position = GCM_COLORMUNKI_DIAL_POSITION_SURFACE;
-	} else if (reply[0] == COLORMUNKI_DIAL_POSITION_CALIBRATION) {
+		priv->dial_position = GCM_SENSOR_COLORMUNKI_DIAL_POSITION_SURFACE;
+	} else if (reply[0] == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_CALIBRATION) {
 		egg_debug ("now calibration");
-		priv->dial_position = GCM_COLORMUNKI_DIAL_POSITION_CALIBRATION;
-	} else if (reply[0] == COLORMUNKI_DIAL_POSITION_AMBIENT) {
+		priv->dial_position = GCM_SENSOR_COLORMUNKI_DIAL_POSITION_CALIBRATION;
+	} else if (reply[0] == GCM_SENSOR_COLORMUNKI_DIAL_POSITION_AMBIENT) {
 		egg_debug ("now ambient");
-		priv->dial_position = GCM_COLORMUNKI_DIAL_POSITION_AMBIENT;
+		priv->dial_position = GCM_SENSOR_COLORMUNKI_DIAL_POSITION_AMBIENT;
 	} else {
 		egg_warning ("dial position unknown: 0x%02x", reply[0]);
-		priv->dial_position = GCM_COLORMUNKI_DIAL_POSITION_UNKNOWN;
+		priv->dial_position = GCM_SENSOR_COLORMUNKI_DIAL_POSITION_UNKNOWN;
 	}
 
 	/* button state */
-	if (reply[1] == COLORMUNKI_BUTTON_STATE_RELEASED) {
+	if (reply[1] == GCM_SENSOR_COLORMUNKI_BUTTON_STATE_RELEASED) {
 		egg_debug ("button released");
-	} else if (reply[1] == COLORMUNKI_BUTTON_STATE_PRESSED) {
+	} else if (reply[1] == GCM_SENSOR_COLORMUNKI_BUTTON_STATE_PRESSED) {
 		egg_debug ("button pressed");
 	} else {
 		egg_warning ("switch state unknown: 0x%02x", reply[1]);
@@ -236,14 +213,14 @@ gcm_sensor_colormunki_transfer_cb (struct libusb_transfer *transfer)
 	gcm_sensor_colormunki_print_data ("reply", transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, transfer->actual_length);
 	timestamp = (reply[7] << 24) + (reply[6] << 16) + (reply[5] << 8) + (reply[4] << 0);
 	/* we only care when the button is pressed */
-	if (reply[0] == COLORMUNKI_COMMAND_BUTTON_RELEASED) {
+	if (reply[0] == GCM_SENSOR_COLORMUNKI_COMMAND_BUTTON_RELEASED) {
 		egg_debug ("ignoring button released");
 		goto out;
 	}
 
-	if (reply[0] == COLORMUNKI_COMMAND_DIAL_ROTATE) {
+	if (reply[0] == GCM_SENSOR_COLORMUNKI_COMMAND_DIAL_ROTATE) {
 		egg_warning ("dial rotate at %ims", timestamp);
-	} else if (reply[0] == COLORMUNKI_COMMAND_BUTTON_PRESSED) {
+	} else if (reply[0] == GCM_SENSOR_COLORMUNKI_COMMAND_BUTTON_PRESSED) {
 		egg_debug ("button pressed at %ims", timestamp);
 		gcm_sensor_button_pressed (GCM_SENSOR (sensor_colormunki));
 	}
@@ -384,7 +361,8 @@ gcm_sensor_colormunki_startup (GcmSensor *sensor, GError **error)
 
 	/* connect */
 	ret = gcm_usb_connect (priv->usb,
-			       COLORMUNKI_VENDOR_ID, COLORMUNKI_PRODUCT_ID,
+			       GCM_SENSOR_COLORMUNKI_VENDOR_ID,
+			       GCM_SENSOR_COLORMUNKI_PRODUCT_ID,
 			       0x01, 0x00, error);
 	if (!ret)
 		goto out;
@@ -474,7 +452,7 @@ gcm_sensor_colormunki_get_ambient (GcmSensor *sensor, gdouble *value, GError **e
 	GcmSensorColormunki *sensor_colormunki = GCM_SENSOR_COLORMUNKI (sensor);
 
 	/* no hardware support */
-	if (sensor_colormunki->priv->dial_position != GCM_COLORMUNKI_DIAL_POSITION_AMBIENT) {
+	if (sensor_colormunki->priv->dial_position != GCM_SENSOR_COLORMUNKI_DIAL_POSITION_AMBIENT) {
 		g_set_error_literal (error, GCM_SENSOR_ERROR,
 				     GCM_SENSOR_ERROR_NO_SUPPORT,
 				     "Cannot measure ambient light in this mode (turn dial!)");
@@ -612,7 +590,7 @@ gcm_sensor_colormunki_new (void)
 {
 	GcmSensorColormunki *sensor;
 	sensor = g_object_new (GCM_TYPE_SENSOR_COLORMUNKI,
-			       "native", TRUE,
+			       "native", FALSE,
 			       "kind", GCM_SENSOR_KIND_COLOR_MUNKI,
 			       "image-display", "munki-attach.svg",
 			       "image-calibrate", "munki-calibrate.svg",
diff --git a/tools/gcm-sensor-colormunki.h b/libcolor-glib/gcm-sensor-colormunki.h
similarity index 100%
rename from tools/gcm-sensor-colormunki.h
rename to libcolor-glib/gcm-sensor-colormunki.h
diff --git a/tools/Makefile.am b/tools/Makefile.am
index bf961f1..f7dd7d4 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -86,8 +86,6 @@ gcm_ddc_util_CFLAGS =					\
 gcm_sensor_example_SOURCES =				\
 	egg-debug.c					\
 	egg-debug.h					\
-	gcm-sensor-colormunki.c				\
-	gcm-sensor-colormunki.h				\
 	gcm-sensor-example.c
 
 gcm_sensor_example_LDADD =				\



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