[gnome-color-manager] Add a ::button-pressed signal to GcmSensor
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add a ::button-pressed signal to GcmSensor
- Date: Tue, 20 Jul 2010 09:02:38 +0000 (UTC)
commit 1efa6340a33ba4eebfd35ee8df6704da559dbdc6
Author: Richard Hughes <richard hughsie com>
Date: Mon Jul 19 17:55:13 2010 +0100
Add a ::button-pressed signal to GcmSensor
libcolor-glib/gcm-self-test.c | 11 +++++++++++
libcolor-glib/gcm-sensor-client.h | 2 ++
libcolor-glib/gcm-sensor-dummy.c | 3 +++
libcolor-glib/gcm-sensor.c | 29 +++++++++++++++++++++++++++++
libcolor-glib/gcm-sensor.h | 3 +++
src/gcm-sensor-example.c | 19 +++++++++++--------
6 files changed, 59 insertions(+), 8 deletions(-)
---
diff --git a/libcolor-glib/gcm-self-test.c b/libcolor-glib/gcm-self-test.c
index 3d4eea9..c051b6b 100644
--- a/libcolor-glib/gcm-self-test.c
+++ b/libcolor-glib/gcm-self-test.c
@@ -145,6 +145,12 @@ gcm_test_ddc_client_func (void)
}
static void
+gcm_test_sensor_button_pressed_cb (GcmSensor *sensor, gint *signal_count)
+{
+ (*signal_count)++;
+}
+
+static void
gcm_test_sensor_func (void)
{
gboolean ret;
@@ -152,9 +158,12 @@ gcm_test_sensor_func (void)
GcmSensor *sensor;
gdouble value;
GcmColorXYZ values;
+ gboolean signal_count = 0;
/* start sensor */
sensor = gcm_sensor_dummy_new ();
+ g_signal_connect (sensor, "button-pressed", G_CALLBACK (gcm_test_sensor_button_pressed_cb), &signal_count);
+
ret = gcm_sensor_startup (sensor, &error);
g_assert_no_error (error);
g_assert (ret);
@@ -170,12 +179,14 @@ gcm_test_sensor_func (void)
/* get ambient */
ret = gcm_sensor_get_ambient (sensor, &value, &error);
+ g_assert_cmpint (signal_count, ==, 0);
g_assert_no_error (error);
g_assert (ret);
g_debug ("ambient = %.1lf Lux", value);
/* sample color */
ret = gcm_sensor_sample (sensor, &values, &error);
+ g_assert_cmpint (signal_count, ==, 1);
g_assert_no_error (error);
g_assert (ret);
g_debug ("X=%0.4lf, Y=%0.4lf, Z=%0.4lf", values.X, values.Y, values.Z);
diff --git a/libcolor-glib/gcm-sensor-client.h b/libcolor-glib/gcm-sensor-client.h
index 8730c80..337ecb1 100644
--- a/libcolor-glib/gcm-sensor-client.h
+++ b/libcolor-glib/gcm-sensor-client.h
@@ -48,6 +48,8 @@ struct _GcmSensorClient
struct _GcmSensorClientClass
{
GObjectClass parent_class;
+
+ /* signals */
void (* changed) (void);
/* padding for future expansion */
void (*_gcm_reserved1) (void);
diff --git a/libcolor-glib/gcm-sensor-dummy.c b/libcolor-glib/gcm-sensor-dummy.c
index 5b93f2c..0f3f0f8 100644
--- a/libcolor-glib/gcm-sensor-dummy.c
+++ b/libcolor-glib/gcm-sensor-dummy.c
@@ -62,6 +62,9 @@ gcm_sensor_dummy_sample (GcmSensor *sensor, GcmColorXYZ *value, GError **error)
value->X = 17.0f;
value->Y = 18.0f;
value->Z = 19.0f;
+
+ /* emulate */
+ gcm_sensor_button_pressed (sensor);
return TRUE;
}
diff --git a/libcolor-glib/gcm-sensor.c b/libcolor-glib/gcm-sensor.c
index 860a868..bff64b4 100644
--- a/libcolor-glib/gcm-sensor.c
+++ b/libcolor-glib/gcm-sensor.c
@@ -71,9 +71,28 @@ enum {
PROP_LAST
};
+enum {
+ SIGNAL_BUTTON_PRESSED,
+ SIGNAL_LAST
+};
+
+static guint signals[SIGNAL_LAST] = { 0 };
+
G_DEFINE_TYPE (GcmSensor, gcm_sensor, G_TYPE_OBJECT)
/**
+ * gcm_sensor_button_pressed:
+ *
+ * Causes the ::button-pressed signal to be fired.
+ **/
+void
+gcm_sensor_button_pressed (GcmSensor *sensor)
+{
+ egg_debug ("emit: button-pressed");
+ g_signal_emit (sensor, signals[SIGNAL_BUTTON_PRESSED], 0);
+}
+
+/**
* gcm_sensor_get_model:
* @sensor: a valid #GcmSensor instance
*
@@ -649,6 +668,16 @@ gcm_sensor_class_init (GcmSensorClass *klass)
G_PARAM_READABLE);
g_object_class_install_property (object_class, PROP_DEVICE, pspec);
+ /**
+ * GcmSensor::button-pressed:
+ **/
+ signals[SIGNAL_BUTTON_PRESSED] =
+ g_signal_new ("button-pressed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GcmSensorClass, button_pressed),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
g_type_class_add_private (klass, sizeof (GcmSensorPrivate));
}
diff --git a/libcolor-glib/gcm-sensor.h b/libcolor-glib/gcm-sensor.h
index 6ef1ede..c169937 100644
--- a/libcolor-glib/gcm-sensor.h
+++ b/libcolor-glib/gcm-sensor.h
@@ -65,6 +65,8 @@ struct _GcmSensorClass
GError **error);
gboolean (*startup) (GcmSensor *sensor,
GError **error);
+ /* signals */
+ void (* button_pressed) (void);
/* padding for future expansion */
void (*_gcm_reserved1) (void);
void (*_gcm_reserved2) (void);
@@ -122,6 +124,7 @@ typedef enum {
GType gcm_sensor_get_type (void);
GcmSensor *gcm_sensor_new (void);
+void gcm_sensor_button_pressed (GcmSensor *sensor);
gboolean gcm_sensor_get_ambient (GcmSensor *sensor,
gdouble *value,
GError **error);
diff --git a/src/gcm-sensor-example.c b/src/gcm-sensor-example.c
index 838b98f..5f773e3 100644
--- a/src/gcm-sensor-example.c
+++ b/src/gcm-sensor-example.c
@@ -111,6 +111,7 @@ out:
gsize reply_read;
guchar reply[8];
guint i;
+ guint32 event;
libusb_device_handle *handle;
/* connect */
@@ -165,19 +166,21 @@ out:
#define COLORMUNKI_COMMAND_BUTTON_PRESSED 0x01
#define COLORMUNKI_COMMAND_BUTTON_RELEASED 0x02
+ event = (reply[7] << 24) + (reply[6] << 16) + (reply[5] << 8) + (reply[4] << 0);
+
print_data ("reply", reply, reply_read);
if (reply[0] == COLORMUNKI_COMMAND_DIAL_ROTATE)
- egg_warning ("dial rotate");
- if (reply[0] == COLORMUNKI_COMMAND_BUTTON_PRESSED)
- egg_warning ("button pressed");
- if (reply[0] == COLORMUNKI_COMMAND_BUTTON_RELEASED)
- egg_warning ("button released");
+ egg_warning ("dial rotate at %ims", event);
+ else if (reply[0] == COLORMUNKI_COMMAND_BUTTON_PRESSED)
+ egg_warning ("button pressed at %ims", event);
+ else if (reply[0] == COLORMUNKI_COMMAND_BUTTON_RELEASED)
+ egg_warning ("button released at %ims", event);
/*
- * subcmd ----\ /---- some kind of time counter, seconds?
- * cmd ----|\ || ||
+ * subcmd ----\ /------------ 32 bit event time
+ * cmd ----|\ || || || || ||
* Returns: 02 00 00 00 ac 62 07 00
- * \|-||----------||-----always zero
+ * always zero ---||-||
*
* cmd is:
* 00 dial rotate
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]