diff --git a/src/conky.c b/src/conky.c index a1bee786..b0cb0d4c 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1114,23 +1114,13 @@ void generate_text_internal(char *p, int p_max_size, #endif #ifdef __OpenBSD__ OBJ(obsd_sensors_temp) { - obsd_sensors.device = sensor_device; - update_obsd_sensors(); - temp_print(p, p_max_size, - obsd_sensors.temp[obsd_sensors.device][obj->data.sensor], - TEMP_CELSIUS); + print_obsd_sensors_temp(obj, p, p_max_size); } OBJ(obsd_sensors_fan) { - obsd_sensors.device = sensor_device; - update_obsd_sensors(); - snprintf(p, p_max_size, "%d", - obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]); + print_obsd_sensors_fan(obj, p, p_max_size); } OBJ(obsd_sensors_volt) { - obsd_sensors.device = sensor_device; - update_obsd_sensors(); - snprintf(p, p_max_size, "%.2f", - obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]); + print_obsd_sensors_volt(obj, p, p_max_size); } OBJ(obsd_vendor) { get_obsd_vendor(p, p_max_size); diff --git a/src/core.c b/src/core.c index 6efab874..697fc067 100644 --- a/src/core.c +++ b/src/core.c @@ -325,26 +325,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif #if defined(__OpenBSD__) END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument") - if (!isdigit(arg[0]) || atoi(&arg[0]) < 0 - || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) { - obj->data.sensor = 0; - NORM_ERR("Invalid temperature sensor number!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); END OBJ_ARG(obsd_sensors_fan, 0, "obsd_sensors_fan: needs 2 arguments (device and sensor number)") - if (!isdigit(arg[0]) || atoi(&arg[0]) < 0 - || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) { - obj->data.sensor = 0; - NORM_ERR("Invalid fan sensor number!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); END OBJ_ARG(obsd_sensors_volt, 0, "obsd_sensors_volt: needs 2 arguments (device and sensor number)") - if (!isdigit(arg[0]) || atoi(&arg[0]) < 0 - || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) { - obj->data.sensor = 0; - NORM_ERR("Invalid voltage sensor number!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); END OBJ(obsd_vendor, 0) END OBJ(obsd_product, 0) #endif /* __OpenBSD__ */ diff --git a/src/openbsd.c b/src/openbsd.c index 4d5f240d..b6fba3d0 100644 --- a/src/openbsd.c +++ b/src/openbsd.c @@ -440,6 +440,14 @@ void update_load_average() info.loadavg[2] = (float) v[2]; } +#define OBSD_MAX_SENSORS 256 +static struct obsd_sensors_struct { + int device; + float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; + unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; + float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; +} obsd_sensors; + /* read sensors from sysctl */ void update_obsd_sensors() { @@ -503,6 +511,41 @@ void update_obsd_sensors() init_sensors = 1; } +void parse_obsd_sensor(struct text_object *obj, const char *arg) +{ + if (!isdigit(arg[0]) || atoi(&arg[0]) < 0 + || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) { + obj->data.l = 0; + NORM_ERR("Invalid sensor number!"); + } else + obj->data.l = atoi(&arg[0]); +} + +void print_obsd_sensors_temp(struct text_object *obj, char *p, int p_max_size) +{ + obsd_sensors.device = sensor_device; + update_obsd_sensors(); + temp_print(p, p_max_size, + obsd_sensors.temp[obsd_sensors.device][obj->data.l], + TEMP_CELSIUS); +} + +void print_obsd_sensors_fan(struct text_object *obj, char *p, int p_max_size) +{ + obsd_sensors.device = sensor_device; + update_obsd_sensors(); + snprintf(p, p_max_size, "%d", + obsd_sensors.fan[obsd_sensors.device][obj->data.l]); +} + +void print_obsd_sensors_volt(struct text_object *obj, char *p, int p_max_size) +{ + obsd_sensors.device = sensor_device; + update_obsd_sensors(); + snprintf(p, p_max_size, "%.2f", + obsd_sensors.volt[obsd_sensors.device][obj->data.l]); +} + /* chipset vendor */ void get_obsd_vendor(char *buf, size_t client_buffer_size) { diff --git a/src/openbsd.h b/src/openbsd.h index 2ee32cb6..0f7a3ac1 100644 --- a/src/openbsd.h +++ b/src/openbsd.h @@ -9,45 +9,13 @@ #include #include -void update_obsd_sensors(void); +void parse_obsd_sensor(struct text_object *, const char *); +void print_obsd_sensors_temp(struct text_object *, char *, int); +void print_obsd_sensors_fan(struct text_object *, char *, int); +void print_obsd_sensors_volt(struct text_object *, char *, int); void get_obsd_vendor(char *buf, size_t client_buffer_size); void get_obsd_product(char *buf, size_t client_buffer_size); -#define OBSD_MAX_SENSORS 256 -struct obsd_sensors_struct { - int device; - float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; - unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; - float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; -}; -struct obsd_sensors_struct obsd_sensors; - -#if defined(i386) || defined(__i386__) -typedef struct apm_power_info *apm_info_t; -#endif - -#endif /*OPENBSD_H_*/ -#ifndef OPENBSD_H_ -#define OPENBSD_H_ - -#include "common.h" -#include -#include -#include - -void update_obsd_sensors(void); -void get_obsd_vendor(char *buf, size_t client_buffer_size); -void get_obsd_product(char *buf, size_t client_buffer_size); - -#define OBSD_MAX_SENSORS 256 -struct obsd_sensors_struct { - int device; - float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; - unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; - float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS]; -}; -struct obsd_sensors_struct obsd_sensors; - #if defined(i386) || defined(__i386__) typedef struct apm_power_info *apm_info_t; #endif