summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdevkit-power/dkp-client-device.c34
-rw-r--r--libdevkit-power/dkp-object.c3
2 files changed, 32 insertions, 5 deletions
diff --git a/libdevkit-power/dkp-client-device.c b/libdevkit-power/dkp-client-device.c
index 4402bc6..56d879a 100644
--- a/libdevkit-power/dkp-client-device.c
+++ b/libdevkit-power/dkp-client-device.c
@@ -192,6 +192,35 @@ dkp_client_device_get_object (const DkpClientDevice *device)
}
/**
+ * dkp_client_device_print_stats:
+ **/
+static gboolean
+dkp_client_device_print_stats (const DkpClientDevice *device, const gchar *type)
+{
+ guint i;
+ GPtrArray *array;
+ DkpHistoryObj *obj;
+ gboolean ret = FALSE;
+
+ /* get a fair chunk of data */
+ array = dkp_client_device_get_statistics (device, type, 120);
+ if (array == NULL)
+ goto out;
+
+ /* pretty print */
+ g_print (" Statistics (%s):\n", type);
+ for (i=0; i<array->len; i++) {
+ obj = (DkpHistoryObj *) g_ptr_array_index (array, i);
+ g_print (" %i\t%.3f\t%s\n", obj->time, obj->value, dkp_device_state_to_text (obj->state));
+ }
+ g_ptr_array_foreach (array, (GFunc) dkp_history_obj_free, NULL);
+ g_ptr_array_free (array, TRUE);
+ ret = TRUE;
+out:
+ return ret;
+}
+
+/**
* dkp_client_device_print:
**/
gboolean
@@ -203,8 +232,9 @@ dkp_client_device_print (const DkpClientDevice *device)
dkp_object_print (device->priv->obj);
/* if we can, get stats */
- dkp_client_device_get_statistics (device, "charge", 120);
- dkp_client_device_get_statistics (device, "rate", 120);
+ dkp_client_device_print_stats (device, "charge");
+ dkp_client_device_print_stats (device, "rate");
+
return TRUE;
}
diff --git a/libdevkit-power/dkp-object.c b/libdevkit-power/dkp-object.c
index 4f34293..10751ba 100644
--- a/libdevkit-power/dkp-object.c
+++ b/libdevkit-power/dkp-object.c
@@ -285,9 +285,7 @@ dkp_object_print (const DkpObject *obj)
g_print (" power supply: %s\n", dkp_object_bool_to_text (obj->power_supply));
g_print (" updated: %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - obj->update_time));
g_print (" %s\n", dkp_device_type_to_text (obj->type));
-
if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
- g_print (" battery\n");
g_print (" present: %s\n", dkp_object_bool_to_text (obj->battery_is_present));
g_print (" rechargeable: %s\n", dkp_object_bool_to_text (obj->battery_is_rechargeable));
g_print (" state: %s\n", dkp_device_state_to_text (obj->battery_state));
@@ -310,7 +308,6 @@ dkp_object_print (const DkpObject *obj)
g_print (" capacity: %g%%\n", obj->battery_capacity);
g_print (" technology: %s\n", dkp_device_technology_to_text (obj->battery_technology));
} else if (obj->type == DKP_DEVICE_TYPE_LINE_POWER) {
- g_print (" line-power\n");
g_print (" online: %s\n", dkp_object_bool_to_text (obj->line_power_online));
} else if (obj->type == DKP_DEVICE_TYPE_MOUSE || obj->type == DKP_DEVICE_TYPE_KEYBOARD) {
g_print (" present: %s\n", dkp_object_bool_to_text (obj->battery_is_present));