From c8bed3a28db51cb850c9c2fd0dbb196fefb83feb Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 13 Nov 2009 00:24:54 +0100 Subject: [PATCH] voltage: outsource printing code --- src/common.h | 3 ++- src/conky.c | 12 ++---------- src/linux.c | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/common.h b/src/common.h index a0f006ab..4dadab21 100644 --- a/src/common.h +++ b/src/common.h @@ -29,7 +29,8 @@ void update_threads(void); void update_running_processes(void); void update_stuff(void); char get_freq(char *, size_t, const char *, int, unsigned int); -char get_voltage(char *, size_t, const char *, int, unsigned int); /* ptarjan */ +void print_voltage_mv(struct text_object *, char *, int); +void print_voltage_v(struct text_object *, char *, int); void update_load_average(void); void update_top(void); void free_all_processes(void); diff --git a/src/conky.c b/src/conky.c index 9b6b14c6..bd549602 100644 --- a/src/conky.c +++ b/src/conky.c @@ -818,18 +818,10 @@ void generate_text_internal(char *p, int p_max_size, } #if defined(__linux__) OBJ(voltage_mv) { - static int ok = 1; - if (ok) { - ok = get_voltage(p, p_max_size, "%.0f", 1, - obj->data.i); - } + print_voltage_mv(obj, p, p_max_size); } OBJ(voltage_v) { - static int ok = 1; - if (ok) { - ok = get_voltage(p, p_max_size, "%'.3f", 1000, - obj->data.i); - } + print_voltage_v(obj, p, p_max_size); } #ifdef HAVE_IWLIB diff --git a/src/linux.c b/src/linux.c index f70117f9..b4fc672a 100644 --- a/src/linux.c +++ b/src/linux.c @@ -1201,7 +1201,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, * Peter Tarjan (ptarjan@citromail.hu) */ /* return cpu voltage in mV (use divisor=1) or V (use divisor=1000) */ -char get_voltage(char *p_client_buffer, size_t client_buffer_size, +static char get_voltage(char *p_client_buffer, size_t client_buffer_size, const char *p_format, int divisor, unsigned int cpu) { FILE *f; @@ -1270,6 +1270,22 @@ char get_voltage(char *p_client_buffer, size_t client_buffer_size, return 1; } +void print_voltage_mv(struct text_object *obj, char *p, int p_max_size) +{ + static int ok = 1; + if (ok) { + ok = get_voltage(p, p_max_size, "%.0f", 1, obj->data.i); + } +} + +void print_voltage_v(struct text_object *obj, char *p, int p_max_size) +{ + static int ok = 1; + if (ok) { + ok = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.i); + } +} + #define ACPI_FAN_DIR "/proc/acpi/fan/" void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)