From 0b83ebec500f6fd6ce8d402b50b51de5964a8252 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 30 Oct 2012 15:12:16 +0100 Subject: [PATCH 1/2] Add luminosity property This adds the luminosity property for devices able to recharge using light. Signed-off-by: Julien Danjou --- libupower-glib/up-device.c | 27 +++++++++++++++++++++++++++ src/org.freedesktop.UPower.Device.xml | 10 ++++++++++ src/up-device.c | 16 ++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/libupower-glib/up-device.c b/libupower-glib/up-device.c index ce826c6..bf9f758 100644 --- a/libupower-glib/up-device.c +++ b/libupower-glib/up-device.c @@ -81,6 +81,7 @@ struct _UpDevicePrivate gdouble energy_full_design; /* Watt Hours */ gdouble energy_rate; /* Watts */ gdouble voltage; /* Volts */ + gdouble luminosity; /* Lux */ gint64 time_to_empty; /* seconds */ gint64 time_to_full; /* seconds */ gdouble percentage; /* percent */ @@ -112,6 +113,7 @@ enum { PROP_ENERGY_FULL_DESIGN, PROP_ENERGY_RATE, PROP_VOLTAGE, + PROP_LUMINOSITY, PROP_TIME_TO_EMPTY, PROP_TIME_TO_FULL, PROP_PERCENTAGE, @@ -195,6 +197,8 @@ up_device_collect_props_cb (const char *key, const GValue *value, UpDevice *devi device->priv->energy_rate = g_value_get_double (value); } else if (g_strcmp0 (key, "Voltage") == 0) { device->priv->voltage = g_value_get_double (value); + } else if (g_strcmp0 (key, "Luminosity") == 0) { + device->priv->luminosity = g_value_get_double (value); } else if (g_strcmp0 (key, "TimeToFull") == 0) { device->priv->time_to_full = g_value_get_int64 (value); } else if (g_strcmp0 (key, "TimeToEmpty") == 0) { @@ -481,6 +485,10 @@ up_device_to_text (UpDevice *device) if (device->priv->voltage > 0) g_string_append_printf (string, " voltage: %g V\n", device->priv->voltage); } + if (device->priv->kind == UP_DEVICE_KIND_KEYBOARD) { + if (device->priv->luminosity > 0) + g_string_append_printf (string, " luminosity: %g lx\n", device->priv->luminosity); + } if (device->priv->kind == UP_DEVICE_KIND_BATTERY || device->priv->kind == UP_DEVICE_KIND_UPS) { if (device->priv->time_to_full > 0) { @@ -807,6 +815,9 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa case PROP_VOLTAGE: device->priv->voltage = g_value_get_double (value); break; + case PROP_LUMINOSITY: + device->priv->luminosity = g_value_get_double (value); + break; case PROP_TIME_TO_EMPTY: device->priv->time_to_empty = g_value_get_int64 (value); break; @@ -908,6 +919,9 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe case PROP_VOLTAGE: g_value_set_double (value, device->priv->voltage); break; + case PROP_LUMINOSITY: + g_value_set_double (value, device->priv->luminosity); + break; case PROP_TIME_TO_EMPTY: g_value_set_int64 (value, device->priv->time_to_empty); break; @@ -1234,6 +1248,19 @@ up_device_class_init (UpDeviceClass *klass) g_param_spec_double ("voltage", NULL, NULL, 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); + + /** + * UpDevice:luminosity: + * + * The current luminosity of the device. + * + * Since: 0.9.19 + **/ + g_object_class_install_property (object_class, + PROP_LUMINOSITY, + g_param_spec_double ("luminosity", NULL, NULL, + 0.0, G_MAXDOUBLE, 0.0, + G_PARAM_READWRITE)); /** * UpDevice:time-to-empty: * diff --git a/src/org.freedesktop.UPower.Device.xml b/src/org.freedesktop.UPower.Device.xml index 7c9a65b..04ea4da 100644 --- a/src/org.freedesktop.UPower.Device.xml +++ b/src/org.freedesktop.UPower.Device.xml @@ -482,6 +482,16 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2 + + + + + Luminosity being recorded by the meter. + + + + + diff --git a/src/up-device.c b/src/up-device.c index 3591125..efb8d72 100644 --- a/src/up-device.c +++ b/src/up-device.c @@ -73,6 +73,7 @@ struct UpDevicePrivate gdouble energy_full_design; /* Watt Hours */ gdouble energy_rate; /* Watts */ gdouble voltage; /* Volts */ + gdouble luminosity; /* Lux */ gint64 time_to_empty; /* seconds */ gint64 time_to_full; /* seconds */ gdouble percentage; /* percent */ @@ -105,6 +106,7 @@ enum { PROP_ENERGY_FULL_DESIGN, PROP_ENERGY_RATE, PROP_VOLTAGE, + PROP_LUMINOSITY, PROP_TIME_TO_EMPTY, PROP_TIME_TO_FULL, PROP_PERCENTAGE, @@ -235,6 +237,9 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe case PROP_VOLTAGE: g_value_set_double (value, device->priv->voltage); break; + case PROP_LUMINOSITY: + g_value_set_double (value, device->priv->luminosity); + break; case PROP_TIME_TO_EMPTY: g_value_set_int64 (value, device->priv->time_to_empty); break; @@ -335,6 +340,9 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa case PROP_VOLTAGE: device->priv->voltage = g_value_get_double (value); break; + case PROP_LUMINOSITY: + device->priv->luminosity = g_value_get_double (value); + break; case PROP_TIME_TO_EMPTY: device->priv->time_to_empty = g_value_get_int64 (value); break; @@ -1130,6 +1138,14 @@ up_device_class_init (UpDeviceClass *klass) 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE)); /** + * UpDevice:luminosity: + */ + g_object_class_install_property (object_class, + PROP_LUMINOSITY, + g_param_spec_double ("luminosity", NULL, NULL, + 0.0, G_MAXDOUBLE, 0.0, + G_PARAM_READWRITE)); + /** * UpDevice:time-to-empty: */ g_object_class_install_property (object_class, -- 1.7.10.4