1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

obsd_sensors: cleanup code (untested)

This commit is contained in:
Phil Sutter 2009-10-09 03:55:46 +02:00
parent f2188a67a1
commit 0de0047bdc
4 changed files with 53 additions and 67 deletions

View File

@ -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);

View File

@ -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__ */

View File

@ -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)
{

View File

@ -9,45 +9,13 @@
#include <sys/sensors.h>
#include <machine/apmvar.h>
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 <sys/sysctl.h>
#include <sys/sensors.h>
#include <machine/apmvar.h>
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