mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-13 11:15:27 +00:00
added option battery_power_draw to get power draw in watts
This commit is contained in:
parent
30cad6afca
commit
817b7acb64
@ -638,6 +638,11 @@ void print_battery_time(struct text_object *obj, char *p,
|
|||||||
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
|
get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void battery_power_draw(struct text_object *obj, char *p,
|
||||||
|
unsigned int p_max_size) {
|
||||||
|
get_battery_power_draw(p, p_max_size, obj->data.s);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t battery_percentage(struct text_object *obj) {
|
uint8_t battery_percentage(struct text_object *obj) {
|
||||||
return get_battery_perct(obj->data.s);
|
return get_battery_perct(obj->data.s);
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
|
|||||||
void get_acpi_fan(char *, size_t);
|
void get_acpi_fan(char *, size_t);
|
||||||
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
|
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item);
|
||||||
int get_battery_perct(const char *bat);
|
int get_battery_perct(const char *bat);
|
||||||
|
void get_battery_power_draw(char *buffer, unsigned int n, const char *bat);
|
||||||
double get_battery_perct_bar(struct text_object *);
|
double get_battery_perct_bar(struct text_object *);
|
||||||
void get_battery_short_status(char *buf, unsigned int n, const char *bat);
|
void get_battery_short_status(char *buf, unsigned int n, const char *bat);
|
||||||
|
|
||||||
@ -162,6 +163,7 @@ void print_acpiacadapter(struct text_object *, char *, unsigned int);
|
|||||||
void print_battery(struct text_object *, char *, unsigned int);
|
void print_battery(struct text_object *, char *, unsigned int);
|
||||||
void print_battery_time(struct text_object *, char *, unsigned int);
|
void print_battery_time(struct text_object *, char *, unsigned int);
|
||||||
uint8_t battery_percentage(struct text_object *);
|
uint8_t battery_percentage(struct text_object *);
|
||||||
|
void battery_power_draw(struct text_object *, char *, unsigned int);
|
||||||
void print_battery_short(struct text_object *, char *, unsigned int);
|
void print_battery_short(struct text_object *, char *, unsigned int);
|
||||||
void print_battery_status(struct text_object *, char *, unsigned int);
|
void print_battery_status(struct text_object *, char *, unsigned int);
|
||||||
#endif /* !__OpenBSD__ */
|
#endif /* !__OpenBSD__ */
|
||||||
|
12
src/core.cc
12
src/core.cc
@ -586,6 +586,18 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
|
|||||||
obj->data.s = strndup(bat, text_buffer_size.get(*state));
|
obj->data.s = strndup(bat, text_buffer_size.get(*state));
|
||||||
obj->callbacks.percentage = &battery_percentage;
|
obj->callbacks.percentage = &battery_percentage;
|
||||||
obj->callbacks.free = &gen_free_opaque;
|
obj->callbacks.free = &gen_free_opaque;
|
||||||
|
END OBJ(battery_power_draw, nullptr) char bat[64];
|
||||||
|
|
||||||
|
if (arg != nullptr) {
|
||||||
|
sscanf(arg, "%63s", bat);
|
||||||
|
} else {
|
||||||
|
strncpy(bat, "BAT0", 5);
|
||||||
|
}
|
||||||
|
obj->data.s = strndup(bat, text_buffer_size.get(*state));
|
||||||
|
obj->callbacks.print = &battery_power_draw;
|
||||||
|
obj->callbacks.free = &gen_free_opaque;
|
||||||
|
|
||||||
|
|
||||||
END OBJ(battery_bar, nullptr) char bat[64];
|
END OBJ(battery_bar, nullptr) char bat[64];
|
||||||
|
|
||||||
arg = scan_bar(obj, arg, 100);
|
arg = scan_bar(obj, arg, 100);
|
||||||
|
27
src/linux.cc
27
src/linux.cc
@ -2351,6 +2351,33 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat) {
|
|||||||
// Otherwise, don't shorten.
|
// Otherwise, don't shorten.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_battery_power_draw(char *buffer, unsigned int n, const char *bat) {
|
||||||
|
static int reported = 0;
|
||||||
|
char current_now_path[256], voltage_now_path[256], current_now_val[256], voltage_now_val[256];
|
||||||
|
char *ptr;
|
||||||
|
long current_now, voltage_now;
|
||||||
|
FILE *current_now_file;
|
||||||
|
FILE *voltage_now_file;
|
||||||
|
double result;
|
||||||
|
|
||||||
|
snprintf(current_now_path, 255, SYSFS_BATTERY_BASE_PATH "/%s/current_now", bat);
|
||||||
|
snprintf(voltage_now_path, 255, SYSFS_BATTERY_BASE_PATH "/%s/voltage_now", bat);
|
||||||
|
|
||||||
|
current_now_file = open_file(current_now_path, &reported);
|
||||||
|
voltage_now_file = open_file(voltage_now_path, &reported);
|
||||||
|
|
||||||
|
if (current_now_file != nullptr && voltage_now_file != nullptr) {
|
||||||
|
fgets(current_now_val, 256, current_now_file);
|
||||||
|
fgets(voltage_now_val, 256, voltage_now_file);
|
||||||
|
|
||||||
|
current_now = strtol(current_now_val, &ptr, 10);
|
||||||
|
voltage_now = strtol(voltage_now_val, &ptr, 10);
|
||||||
|
|
||||||
|
result = (double)(current_now*voltage_now)/(double)1000000000000;
|
||||||
|
snprintf(buffer, n, "%.1f", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int _get_battery_perct(const char *bat) {
|
int _get_battery_perct(const char *bat) {
|
||||||
static int reported = 0;
|
static int reported = 0;
|
||||||
int idx;
|
int idx;
|
||||||
|
Loading…
Reference in New Issue
Block a user