[gnome-color-manager: 55/80] huey: it appears the ambient command changes when selecting CRT mode



commit e1855f3ec322d4ae6d798aab97ab5b6ebcd87c49
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jul 17 23:37:18 2010 +0100

    huey: it appears the ambient command changes when selecting CRT mode

 docs/huey/usb-profile-complete-crt.txt.gz |  Bin 0 -> 51034 bytes
 libcolor-glib/gcm-sensor-huey.c           |   21 +++++++++++++++------
 libcolor-glib/gcm-sensor.c                |   19 +++++++++++++++++++
 libcolor-glib/gcm-sensor.h                |   13 +++++++++++--
 src/gcm-huey-example.c                    |    3 +++
 5 files changed, 48 insertions(+), 8 deletions(-)
---
diff --git a/docs/huey/usb-profile-complete-crt.txt.gz b/docs/huey/usb-profile-complete-crt.txt.gz
new file mode 100644
index 0000000..839954c
Binary files /dev/null and b/docs/huey/usb-profile-complete-crt.txt.gz differ
diff --git a/libcolor-glib/gcm-sensor-huey.c b/libcolor-glib/gcm-sensor-huey.c
index 9b768f2..befa0f5 100644
--- a/libcolor-glib/gcm-sensor-huey.c
+++ b/libcolor-glib/gcm-sensor-huey.c
@@ -273,14 +273,14 @@ G_DEFINE_TYPE (GcmSensorHuey, gcm_sensor_huey, GCM_TYPE_SENSOR)
 /*
  * 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?
- *                    \-- only ever 0 or 2 (only ever saw 2 once...)
+ * 	no idea	--^^       ^---^ = 16bits data?
  */
-#define HUEY_COMMAND_AMBIENT		0x17
+#define HUEY_COMMAND_GET_AMBIENT	0x17
 
 /*
  * Set the LEDs on the sensor
@@ -297,7 +297,7 @@ G_DEFINE_TYPE (GcmSensorHuey, gcm_sensor_huey, GCM_TYPE_SENSOR)
  * 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_AMBIENT to Lux */
+/* fudge factor to convert the value of HUEY_COMMAND_GET_AMBIENT to Lux */
 #define HUEY_AMBIENT_UNITS_TO_LUX	125.0f
 
 /* this is a random number chosen to find the best accuracy whilst
@@ -535,12 +535,21 @@ static gboolean
 gcm_sensor_huey_get_ambient (GcmSensor *sensor, gdouble *value, GError **error)
 {
 	guchar reply[8];
-	gboolean ret;
+	gboolean ret = FALSE;
 	gsize reply_read;
-	const guchar request[] = { HUEY_COMMAND_AMBIENT, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+	GcmSensorOutputType output_type;
+	guchar request[] = { HUEY_COMMAND_GET_AMBIENT, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 	GcmSensorHuey *sensor_huey = GCM_SENSOR_HUEY (sensor);
 
+	/* ensure the user set this */
+	output_type = gcm_sensor_get_output_type (sensor);
+	if (output_type == GCM_SENSOR_OUTPUT_TYPE_UNKNOWN) {
+		g_set_error_literal (error, 1, 0, "output sensor type was not set");
+		goto out;
+	}
+
 	/* hit hardware */
+	request[2] = (output_type == GCM_SENSOR_OUTPUT_TYPE_LCD) ? 0x00 : 0x02;
 	ret = gcm_sensor_huey_send_data (sensor_huey, request, 8, reply, 8, &reply_read, error);
 	if (!ret)
 		goto out;
diff --git a/libcolor-glib/gcm-sensor.c b/libcolor-glib/gcm-sensor.c
index 155b620..4db1e62 100644
--- a/libcolor-glib/gcm-sensor.c
+++ b/libcolor-glib/gcm-sensor.c
@@ -44,6 +44,7 @@ static void     gcm_sensor_finalize	(GObject     *object);
 struct _GcmSensorPrivate
 {
 	gchar				*device;
+	GcmSensorOutputType		 output_type;
 };
 
 enum {
@@ -55,6 +56,24 @@ enum {
 G_DEFINE_TYPE (GcmSensor, gcm_sensor, G_TYPE_OBJECT)
 
 /**
+ * gcm_sensor_set_output_type:
+ **/
+void
+gcm_sensor_set_output_type (GcmSensor *sensor, GcmSensorOutputType output_type)
+{
+	sensor->priv->output_type = output_type;
+}
+
+/**
+ * gcm_sensor_get_output_type:
+ **/
+GcmSensorOutputType
+gcm_sensor_get_output_type (GcmSensor *sensor)
+{
+	return sensor->priv->output_type;
+}
+
+/**
  * gcm_sensor_startup:
  **/
 gboolean
diff --git a/libcolor-glib/gcm-sensor.h b/libcolor-glib/gcm-sensor.h
index 156710d..0a90f5a 100644
--- a/libcolor-glib/gcm-sensor.h
+++ b/libcolor-glib/gcm-sensor.h
@@ -68,14 +68,20 @@ struct _GcmSensorClass
 	void (*_gcm_reserved5) (void);
 };
 
-typedef enum
-{
+typedef enum {
 	GCM_SENSOR_ERROR_USER_ABORT,
 	GCM_SENSOR_ERROR_NO_SUPPORT,
 	GCM_SENSOR_ERROR_NO_DATA,
 	GCM_SENSOR_ERROR_INTERNAL
 } GcmSensorError;
 
+typedef enum {
+	GCM_SENSOR_OUTPUT_TYPE_UNKNOWN,
+	GCM_SENSOR_OUTPUT_TYPE_LCD,
+	GCM_SENSOR_OUTPUT_TYPE_CRT,
+	GCM_SENSOR_OUTPUT_TYPE_PROJECTOR
+} GcmSensorOutputType;
+
 /* dummy */
 #define GCM_SENSOR_ERROR	1
 
@@ -93,6 +99,9 @@ gboolean	 gcm_sensor_sample			(GcmSensor	*sensor,
 							 GError		**error);
 gboolean	 gcm_sensor_startup			(GcmSensor	*sensor,
 							 GError		**error);
+void		 gcm_sensor_set_output_type		(GcmSensor	*sensor,
+							 GcmSensorOutputType output_type);
+GcmSensorOutputType  gcm_sensor_get_output_type		(GcmSensor	*sensor);
 
 G_END_DECLS
 
diff --git a/src/gcm-huey-example.c b/src/gcm-huey-example.c
index 82a68bc..c0a820f 100644
--- a/src/gcm-huey-example.c
+++ b/src/gcm-huey-example.c
@@ -59,6 +59,9 @@ main (void)
 		goto out;
 	}
 
+	/* set mode */
+	gcm_sensor_set_output_type (sensor, GCM_SENSOR_OUTPUT_TYPE_LCD);
+
 	/* get ambient */
 	ret = gcm_sensor_get_ambient (sensor, &value, &error);
 	if (!ret) {



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