void print_battery_info(int number, const char *format, bool last_full_capacity) {
char buf[1024];
char statusbuf[16];
+ char percentagebuf[16];
char remainingbuf[256];
const char *walk, *last;
int full_design = -1,
charging_status_t status = CS_DISCHARGING;
memset(statusbuf, '\0', sizeof(statusbuf));
+ memset(percentagebuf, '\0', sizeof(percentagebuf));
memset(remainingbuf, '\0', sizeof(remainingbuf));
#if defined(LINUX)
(status == CS_CHARGING ? "CHR" :
(status == CS_DISCHARGING ? "BAT" : "FULL")));
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%",
+ (((float)remaining / (float)full_design) * 100));
+
if (present_rate > 0) {
float remaining_time;
int seconds, hours, minutes;
minutes = seconds / 60;
seconds -= (minutes * 60);
- (void)snprintf(remainingbuf, sizeof(remainingbuf), "%.02f%% %02d:%02d:%02d",
- (((float)remaining / (float)full_design) * 100),
+ (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
max(hours, 0), max(minutes, 0), max(seconds, 0));
- } else {
- (void)snprintf(remainingbuf, sizeof(remainingbuf), "%.02f%%", (((float)remaining / (float)full_design) * 100));
}
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
int state;
(status == CS_CHARGING ? "CHR" :
(status == CS_DISCHARGING ? "BAT" : "FULL")));
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%",
+ present_rate);
+
if (state == 1) {
int hours, minutes;
minutes = remaining;
hours = minutes / 60;
minutes -= (hours * 60);
- (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d%% %02dh%02d",
- present_rate,
+ (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02dh%02d",
max(hours, 0), max(minutes, 0));
- } else {
- (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d%%",
- present_rate);
}
#endif
if (strncmp(walk+1, "status", strlen("status")) == 0) {
printf("%s", statusbuf);
walk += strlen("status");
+ } else if (strncmp(walk+1, "percentage", strlen("percentage")) == 0) {
+ printf("%s", percentagebuf);
+ walk += strlen("percentage");
} else if (strncmp(walk+1, "remaining", strlen("remaining")) == 0) {
printf("%s", remainingbuf);
walk += strlen("remaining");