cfg_opt_t battery_opts[] = {
CFG_STR("format", "%status %percentage %remaining", CFGF_NONE),
CFG_STR("path", "/sys/class/power_supply/BAT%d/uevent", CFGF_NONE),
- CFG_INT("low_threshold", 10, CFGF_NONE),
+ CFG_INT("low_threshold", 30, CFGF_NONE),
+ CFG_STR("threshold_type", "time", CFGF_NONE),
CFG_BOOL("last_full_capacity", false, CFGF_NONE),
CFG_END()
};
CASE_SEC_TITLE("battery") {
SEC_OPEN_MAP("battery");
- print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getint(sec, "low_threshold"), cfg_getbool(sec, "last_full_capacity"));
+ print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity"));
SEC_CLOSE_MAP;
}
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format);
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int threshold, bool last_full_capacity);
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity);
void print_time(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm);
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm);
const char *get_ip_addr();
modify the "path" property accordingly. The first occurence of %d gets replaced
with the battery number, but you can just hard-code a path as well.
-If the remaining time sinks below low_threshold minutes, the battery text will
-be colored red. So, if you configure low_threshold to 10, and your battery
-lasts another 9 minutes, it will be colored red.
+It is possible to define a low_threshold that causes the battery text to be
+colored red. The low_threshold type can be of threshold_type "time" or
+"percentage". So, if you configure low_threshold to 10 and threshold_type to
+"time", and your battery lasts another 9 minutes, it will be colored red.
*Example order*: +battery 0+
*Example format*: +%status %remaining (%emptytime %consumption)+
-*Example low_threshold*: +low_threshold 10+
+*Example low_threshold*: +30+
+
+*Example threshold_type*: +time+
=== CPU-Temperature
* worn off your battery is.
*
*/
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int threshold, bool last_full_capacity) {
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity) {
time_t empty_time;
struct tm *empty_tm;
char buf[1024];
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%",
- (((float)remaining / (float)full_design) * 100));
+ float percentage_remaining = (((float)remaining / (float)full_design) * 100);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining);
if (present_rate > 0) {
float remaining_time;
minutes = seconds / 60;
seconds -= (minutes * 60);
- if (status == CS_DISCHARGING && threshold > 0 && seconds_remaining < 60 * threshold)
- START_COLOR("color_bad");
+ if (status == CS_DISCHARGING && low_threshold > 0) {
+ if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0
+ && percentage_remaining < low_threshold) {
+ START_COLOR("color_bad");
+ } else if (strncmp(threshold_type, "time", strlen(threshold_type)) == 0
+ && seconds_remaining < 60 * low_threshold) {
+ START_COLOR("color_bad");
+ }
+ }
(void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
max(hours, 0), max(minutes, 0), max(seconds, 0));