From 7cb58215e1e9fbe5bbe2c5829bcde42116699b6a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 30 Oct 2012 15:12:16 +0100 Subject: [PATCH 1/2] Add lux property This adds the tux 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..814318a 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 lux; /* 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_LUX, 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, "Lux") == 0) { + device->priv->lux = 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->lux > 0) + g_string_append_printf (string, " lux: %g lx\n", device->priv->lux); + } 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_LUX: + device->priv->lux = 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_LUX: + g_value_set_double (value, device->priv->lux); + 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:lux: + * + * The current lux of the device. + * + * Since: 0.9.19 + **/ + g_object_class_install_property (object_class, + PROP_LUX, + g_param_spec_double ("lux", 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..d2c12d3 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 + + + + + Lux (light) being recorded by the meter. + + + + + diff --git a/src/up-device.c b/src/up-device.c index 3591125..77e3ad9 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 lux; /* 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_LUX, 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_LUX: + g_value_set_double (value, device->priv->lux); + 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_LUX: + device->priv->lux = 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:lux: + */ + g_object_class_install_property (object_class, + PROP_LUX, + g_param_spec_double ("lux", 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