Implement option to use the last full capacity instead of the design capacity

This commit is contained in:
Michael Stapelberg 2009-10-16 20:37:41 +02:00
parent 8a66289702
commit da8cb9ebfc
4 changed files with 11 additions and 8 deletions

View File

@ -71,6 +71,7 @@ int main(int argc, char *argv[]) {
cfg_opt_t battery_opts[] = { cfg_opt_t battery_opts[] = {
CFG_STR("format", "%status %remaining", CFGF_NONE), CFG_STR("format", "%status %remaining", CFGF_NONE),
CFG_BOOL("last_full_capacity", false, CFGF_NONE),
CFG_END() CFG_END()
}; };
@ -157,7 +158,7 @@ int main(int argc, char *argv[]) {
print_eth_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down")); print_eth_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"));
CASE_SEC_TITLE("battery") CASE_SEC_TITLE("battery")
print_battery_info(atoi(title), cfg_getstr(sec, "format")); print_battery_info(atoi(title), cfg_getstr(sec, "format"), cfg_getbool(sec, "last_full_capacity"));
CASE_SEC_TITLE("run_watch") CASE_SEC_TITLE("run_watch")
print_run_watch(title, cfg_getstr(sec, "pidfile"), cfg_getstr(sec, "format")); print_run_watch(title, cfg_getstr(sec, "pidfile"), cfg_getstr(sec, "format"));

View File

@ -63,7 +63,7 @@ char *endcolor() __attribute__ ((pure));
void print_ipv6_info(const char *format); void print_ipv6_info(const char *format);
void print_disk_info(const char *path, const char *format); void print_disk_info(const char *path, const char *format);
void print_battery_info(int number, const char *format); void print_battery_info(int number, const char *format, bool last_full_capacity);
void print_time(const char *format); void print_time(const char *format);
const char *get_ip_addr(); const char *get_ip_addr();
void print_wireless_info(const char *interface, const char *format_up, const char *format_down); void print_wireless_info(const char *interface, const char *format_up, const char *format_down);

View File

@ -145,7 +145,11 @@ interface. Getting the link speed requires root privileges.
=== Battery === Battery
Gets the status (charging, discharging, running), percentage and remaining Gets the status (charging, discharging, running), percentage and remaining
time of the given battery. time of the given battery. If you want to use the last full capacity instead
of the design capacity (when using the design capacity, it may happen that
your battery is at 23% when fully charged because its old. In general, I
want to see it this way, because it tells me how worn off my battery is.),
just specify +last_full_capacity = true+.
*Example order*: +battery 0+ *Example order*: +battery 0+

View File

@ -16,7 +16,7 @@
* worn off your battery is. * worn off your battery is.
* *
*/ */
void print_battery_info(int number, const char *format) { void print_battery_info(int number, const char *format, bool last_full_capacity) {
char buf[1024]; char buf[1024];
char *walk, *last; char *walk, *last;
int full_design = -1, int full_design = -1,
@ -52,17 +52,15 @@ void print_battery_info(int number, const char *format) {
status = CS_FULL; status = CS_FULL;
else { else {
/* The only thing left is the full capacity */ /* The only thing left is the full capacity */
#if 0 if (last_full_capacity) {
if (bat->use_last_full) {
if (!BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL") && if (!BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL") &&
!BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL")) !BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL"))
continue; continue;
} else { } else {
#endif
if (!BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN") && if (!BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN") &&
!BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL_DESIGN")) !BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL_DESIGN"))
continue; continue;
//} }
full_design = atoi(walk+1); full_design = atoi(walk+1);
} }