summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-11-07 10:40:11 +0000
committerRichard Hughes <richard@hughsie.com>2008-11-07 10:40:11 +0000
commitf5ea862a06a43c804fa23f289727132602c851b3 (patch)
tree6b2bb315f5e1946f61a4069da68272fca620a10a
parent75e202c0977068d7c34565d64232760a42c1a0ce (diff)
feature: add voltage property of a power device
-rw-r--r--libdevkit-power/dkp-object.c15
-rw-r--r--libdevkit-power/dkp-object.h1
-rw-r--r--src/dkp-device.c8
-rw-r--r--src/dkp-supply.c2
-rw-r--r--src/dkp-wup.c2
-rw-r--r--src/dkp-wup.h.unused69
-rw-r--r--src/org.freedesktop.DeviceKit.Power.Device.xml6
7 files changed, 33 insertions, 70 deletions
diff --git a/libdevkit-power/dkp-object.c b/libdevkit-power/dkp-object.c
index 6b09a56..afbb6b5 100644
--- a/libdevkit-power/dkp-object.c
+++ b/libdevkit-power/dkp-object.c
@@ -40,6 +40,7 @@ dkp_object_clear_internal (DkpObject *obj)
obj->energy_full = -1;
obj->energy_full_design = -1;
obj->energy_rate = -1;
+ obj->voltage = -1;
obj->percentage = -1;
obj->capacity = -1;
obj->time_to_empty = -1;
@@ -94,6 +95,8 @@ dkp_object_collect_props (const char *key, const GValue *value, DkpObject *obj)
obj->energy_full_design = g_value_get_double (value);
else if (egg_strequal (key, "energy-rate"))
obj->energy_rate = g_value_get_double (value);
+ else if (egg_strequal (key, "voltage"))
+ obj->voltage = g_value_get_double (value);
else if (egg_strequal (key, "time-to-full"))
obj->time_to_full = g_value_get_int64 (value);
else if (egg_strequal (key, "time-to-empty"))
@@ -144,6 +147,7 @@ dkp_object_copy (const DkpObject *cobj)
obj->energy_full = cobj->energy_full;
obj->energy_full_design = cobj->energy_full_design;
obj->energy_rate = cobj->energy_rate;
+ obj->voltage = cobj->voltage;
obj->percentage = cobj->percentage;
obj->capacity = cobj->capacity;
obj->time_to_empty = cobj->time_to_empty;
@@ -175,6 +179,7 @@ dkp_object_equal (const DkpObject *obj1, const DkpObject *obj2)
obj1->energy == obj2->energy &&
obj1->energy_full == obj2->energy_full &&
obj1->energy_full_design == obj2->energy_full_design &&
+ obj1->voltage == obj2->voltage &&
obj1->energy_rate == obj2->energy_rate &&
obj1->percentage == obj2->percentage &&
obj1->has_history == obj2->has_history &&
@@ -279,6 +284,10 @@ dkp_object_print (const DkpObject *obj)
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_MONITOR)
g_print (" energy-rate: %g W\n", obj->energy_rate);
+ if (obj->type == DKP_DEVICE_TYPE_UPS ||
+ obj->type == DKP_DEVICE_TYPE_BATTERY ||
+ obj->type == DKP_DEVICE_TYPE_MONITOR)
+ g_print (" voltage: %g V\n", obj->voltage);
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_UPS) {
if (obj->time_to_full >= 0) {
@@ -376,6 +385,12 @@ dkp_object_diff (const DkpObject *old, const DkpObject *obj)
if (old->energy_rate != obj->energy_rate)
g_print (" energy-rate: %g -> %g W\n",
old->energy_rate, obj->energy_rate);
+ if (obj->type == DKP_DEVICE_TYPE_UPS ||
+ obj->type == DKP_DEVICE_TYPE_BATTERY ||
+ obj->type == DKP_DEVICE_TYPE_MONITOR)
+ if (old->voltage != obj->voltage)
+ g_print (" voltage: %g -> %g V\n",
+ old->voltage, obj->voltage);
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_UPS) {
if (old->time_to_full != obj->time_to_full) {
diff --git a/libdevkit-power/dkp-object.h b/libdevkit-power/dkp-object.h
index 1261e57..c836360 100644
--- a/libdevkit-power/dkp-object.h
+++ b/libdevkit-power/dkp-object.h
@@ -47,6 +47,7 @@ typedef struct {
gdouble energy_full; /* Watt Hours */
gdouble energy_full_design; /* Watt Hours */
gdouble energy_rate; /* Watts */
+ gdouble voltage; /* Volts */
gint64 time_to_empty; /* seconds */
gint64 time_to_full; /* seconds */
gdouble percentage; /* percent */
diff --git a/src/dkp-device.c b/src/dkp-device.c
index 6a352e1..903fbfe 100644
--- a/src/dkp-device.c
+++ b/src/dkp-device.c
@@ -84,6 +84,7 @@ enum
PROP_BATTERY_ENERGY_FULL,
PROP_BATTERY_ENERGY_FULL_DESIGN,
PROP_BATTERY_ENERGY_RATE,
+ PROP_BATTERY_VOLTAGE,
PROP_BATTERY_TIME_TO_EMPTY,
PROP_BATTERY_TIME_TO_FULL,
PROP_BATTERY_PERCENTAGE,
@@ -210,6 +211,9 @@ dkp_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
case PROP_BATTERY_ENERGY_RATE:
g_value_set_double (value, obj->energy_rate);
break;
+ case PROP_BATTERY_VOLTAGE:
+ g_value_set_double (value, obj->voltage);
+ break;
case PROP_BATTERY_TIME_TO_EMPTY:
g_value_set_int64 (value, obj->time_to_empty);
break;
@@ -740,6 +744,10 @@ dkp_device_class_init (DkpDeviceClass *klass)
g_param_spec_double ("energy-rate", NULL, NULL, -G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READABLE));
g_object_class_install_property (
object_class,
+ PROP_BATTERY_VOLTAGE,
+ g_param_spec_double ("voltage", NULL, NULL, -G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
PROP_BATTERY_TIME_TO_EMPTY,
g_param_spec_int64 ("time-to-empty", NULL, NULL, -1, G_MAXINT64, -1, G_PARAM_READABLE));
g_object_class_install_property (
diff --git a/src/dkp-supply.c b/src/dkp-supply.c
index d271915..7fb4984 100644
--- a/src/dkp-supply.c
+++ b/src/dkp-supply.c
@@ -315,6 +315,8 @@ dkp_supply_refresh_battery (DkpSupply *supply)
obj->energy_rate =
fabs (sysfs_get_double (obj->native_path, "current_now") / 1000000.0);
+ obj->voltage =
+ sysfs_get_double (obj->native_path, "voltage_now") / 1000000.0;
/* ACPI gives out the special 'Ones' value for rate when it's unable
* to calculate the true rate. We should set the rate zero, and wait
diff --git a/src/dkp-wup.c b/src/dkp-wup.c
index 6e958ce..a1ccace 100644
--- a/src/dkp-wup.c
+++ b/src/dkp-wup.c
@@ -325,7 +325,7 @@ dkp_wup_parse_command (DkpWup *wup, const gchar *data)
/* update the command fields */
if (command == 'd' && subcommand == '-') {
obj->energy_rate = strtod (tokens[offset+DKP_WUP_RESPONSE_HEADER_WATTS], NULL) / 10.0f;
-// obj->volts = strtod (tokens[offset+DKP_WUP_RESPONSE_HEADER_VOLTS], NULL) / 10.0f;
+ obj->voltage = strtod (tokens[offset+DKP_WUP_RESPONSE_HEADER_VOLTS], NULL) / 10.0f;
ret = TRUE;
} else {
egg_debug ("ignoring command '%c'", command);
diff --git a/src/dkp-wup.h.unused b/src/dkp-wup.h.unused
deleted file mode 100644
index 0f12eb5..0000000
--- a/src/dkp-wup.h.unused
+++ /dev/null
@@ -1,69 +0,0 @@
-Unused constants:
-
-#define DKP_WUP_COMMAND_READ_CAL "#F,R,0"
-/* Response:
- * 0x0 flags
- * 0x1 sample count
- * 0x2 volts gain
- * 0x3 volts bias
- * 0x4 amps gain
- * 0x5 amps bias
- * 0x6 amps offset
- * 0x7 low amps gain
- * 0x8 low amps bias
- * 0x9 low amps offset
- * 0xa watts gain
- * 0xb watts offset
- * 0xc low watts gain
- * 0xd low watts offset
- */
-#define DKP_WUP_COMMAND_START_LOG "#L,W,3,E,1,1"
-#define DKP_WUP_COMMAND_STOP_LOG "#L,R,0"
-/* Response:
- * 0x0 time stamp
- * 0x1 interval
- */
-#define DKP_WUP_COMMAND_READ_INTERVAL "#S,R,0"
-/* Response:
- * 0x0 reserved
- * 0x1 interval
- */
-#define DKP_WUP_COMMAND_WRITE_INTERVAL "#S,W,2," /* {seconds},{interval} */
-#define DKP_WUP_COMMAND_READ_MODE "#M,R,0"
-/* Response:
- * 0x0 display mode
- */
-#define DKP_WUP_COMMAND_WRITE_MODE "#M,W,1," /* {mode} */
-#define DKP_WUP_COMMAND_READ_USER "#U,R,0"
-/* Response:
- * 0x0 cost per kWh
- * 0x1 2nd tier cost
- * 0x2 2nd tier threshold
- * 0x3 duty cycle threshold
- */
-#define DKP_WUP_COMMAND_WRITE_USER "#U,W,0"
-/* Response:
- * 0x0 kwh_cost
- * 0x1 2nd_tier_cost
- * 0x2 2nd_tier_threshold
- * 0x3 duty_cycle_threshold
- */
-#define DKP_WUP_COMMAND_READ_HEADER "#H,R,0"
-/* Response:
- * 0x? One of the DKP_WUP_RESPONSE_HEADER_x constants */
-
-#define DKP_WUP_RESPONSE_HEADER_AMPS 0x2
-#define DKP_WUP_RESPONSE_HEADER_KWH 0x3
-#define DKP_WUP_RESPONSE_HEADER_COST 0x4
-#define DKP_WUP_RESPONSE_HEADER_MONTHLY_KWH 0x5
-#define DKP_WUP_RESPONSE_HEADER_MONTHLY_COST 0x6
-#define DKP_WUP_RESPONSE_HEADER_MAX_WATTS 0x7
-#define DKP_WUP_RESPONSE_HEADER_MAX_VOLTS 0x8
-#define DKP_WUP_RESPONSE_HEADER_MAX_AMPS 0x9
-#define DKP_WUP_RESPONSE_HEADER_MIN_WATTS 0xa
-#define DKP_WUP_RESPONSE_HEADER_MIN_VOLTS 0xb
-#define DKP_WUP_RESPONSE_HEADER_MIN_AMPS 0xc
-#define DKP_WUP_RESPONSE_HEADER_POWER_FACTOR 0xd
-#define DKP_WUP_RESPONSE_HEADER_DUTY_CYCLE 0xe
-#define DKP_WUP_RESPONSE_HEADER_POWER_CYCLE 0xf
-
diff --git a/src/org.freedesktop.DeviceKit.Power.Device.xml b/src/org.freedesktop.DeviceKit.Power.Device.xml
index 00069c9..51721c0 100644
--- a/src/org.freedesktop.DeviceKit.Power.Device.xml
+++ b/src/org.freedesktop.DeviceKit.Power.Device.xml
@@ -259,6 +259,12 @@
</doc:para></doc:description></doc:doc>
</property>
+ <property name="voltage" type="d" access="read">
+ <doc:doc><doc:description><doc:para>
+ Voltage in the Cell or being recorded by the meter.
+ </doc:para></doc:description></doc:doc>
+ </property>
+
<property name="time-to-empty" type="x" access="read">
<doc:doc><doc:description><doc:para>
Number of seconds until the power source is considered empty.