summaryrefslogtreecommitdiff
path: root/src/print_battery_info.c
diff options
context:
space:
mode:
authorMarcel Hellwig <keks@cookiesoft.de>2012-07-05 18:19:26 +0200
committerMichael Stapelberg <michael@stapelberg.de>2012-07-09 15:13:05 +0200
commitc01e87b2692bac03dffb07f3cf8e263758385910 (patch)
treefb9a8fa5962afa571fb99145b57323506d5aedbc /src/print_battery_info.c
parentccc31f0b803a924b69f23880ea9693e17f57f833 (diff)
Added consumption to battery info
Diffstat (limited to 'src/print_battery_info.c')
-rw-r--r--src/print_battery_info.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c
index 3e0c302..74d4460 100644
--- a/src/print_battery_info.c
+++ b/src/print_battery_info.c
@@ -37,6 +37,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
char percentagebuf[16];
char remainingbuf[256];
char emptytimebuf[256];
+ char consumptionbuf[256];
const char *walk, *last;
char *outwalk = buffer;
int full_design = -1,
@@ -48,6 +49,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
memset(percentagebuf, '\0', sizeof(percentagebuf));
memset(remainingbuf, '\0', sizeof(remainingbuf));
memset(emptytimebuf, '\0', sizeof(emptytimebuf));
+ memset(consumptionbuf, '\0', sizeof(consumptionbuf));
INSTANCE(path);
@@ -134,6 +136,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
(void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d",
max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0));
+ (void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW",
+ ((float)present_rate / 1000.0 / 1000.0));
+
END_COLOR;
}
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
@@ -249,6 +254,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
} else if (strncmp(walk+1, "emptytime", strlen("emptytime")) == 0) {
outwalk += sprintf(outwalk, "%s", emptytimebuf);
walk += strlen("emptytime");
+ } else if (strncmp(walk+1, "consumption", strlen("consumption")) == 0) {
+ outwalk += sprintf(outwalk, "%s", consumptionbuf);
+ walk += strlen("consumptionbuf");
}
}