1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-28 01:28:30 +00:00

really apply the hwmon patch (tracker item 1650894)

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@919 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Toni Spets 2007-08-13 17:33:41 +00:00
parent 1b509f9357
commit f296609096
3 changed files with 70 additions and 0 deletions

View File

@ -1003,6 +1003,7 @@ enum text_object_type {
OBJ_alignc,
OBJ_i2c,
#if defined(__linux__)
OBJ_hwmon,
OBJ_i8k_version,
OBJ_i8k_bios,
OBJ_i8k_serial,
@ -1210,6 +1211,12 @@ struct text_object {
char *tz; /* timezone variable */
char *fmt; /* time display formatting */
} tztime;
#if defined(__linux__)
struct {
enum hwmon_sensor_type type;
char *fname; /* filename in /sys/class/hwmon/hwmonX/device/ */
} hwmon;
#endif
struct {
struct fs_stat *fs;
@ -1810,6 +1817,11 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
case OBJ_acpitempf:
close(objs[i].data.i);
break;
#if defined(__linux__)
case OBJ_hwmon:
free(objs[i].data.hwmon.fname);
break;
#endif
case OBJ_i2c:
close(objs[i].data.i2c.fd);
break;
@ -2289,6 +2301,28 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
obj->data.s = strdup(bat);
#endif /* !__OpenBSD__ */
#if defined(__linux__)
END OBJ(hwmon, 0)
if (!arg) {
CRIT_ERR("hwmon: needs arguments (hwmon-number, sensor type, sensor number, sensor subtype)");
} else {
unsigned int monidx, sensidx;
char sensor[10], senssub[32];
if (sscanf(arg, "%u %9s %u %31s", &monidx, sensor, &sensidx, senssub) != 4) {
CRIT_ERR("hwmon: invalid (number of) arguments");
} else {
unsigned int maxlen = strlen(arg)+29+1+1; /* 29=strlen("/sys/class/hwmon/hwmon/device") */
char fname[maxlen];
snprintf(fname, maxlen, "/sys/class/hwmon/hwmon%u/device/%s%u_%s", monidx, sensor, sensidx, senssub);
obj->data.hwmon.fname = strdup(fname);
if (strncmp(sensor, "temp", 5) == 0) {
obj->data.hwmon.type = HWMON_temp;
} else if (strncmp(sensor, "fan", 4) == 0) {
obj->data.hwmon.type = HWMON_fan;
} else {
obj->data.hwmon.type = HWMON_other;
}
}
}
END OBJ(i8k_version, INFO_I8K)
END OBJ(i8k_bios, INFO_I8K)
END OBJ(i8k_serial, INFO_I8K)
@ -3738,6 +3772,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
new_fg(p, color9);
}
#if defined(__linux__)
OBJ(hwmon) {
get_hwmon_value(p, p_max_size, obj->data.hwmon.fname, obj->data.hwmon.type);
}
OBJ(i8k_version) {
snprintf(p, p_max_size, "%s", i8k.version);
}

View File

@ -280,6 +280,12 @@ enum {
INFO_PLATFORM = 25
};
enum hwmon_sensor_type {
HWMON_temp,
HWMON_fan,
HWMON_other
};
void get_hwmon_value( char * p_client_buffer, size_t client_buffer_size, char * fname, enum hwmon_sensor_type type );
/* get_battery_stuff() item selector */
enum {

View File

@ -777,6 +777,33 @@ double get_sysbus_info(int *fd, int div, char *devtype, char *type)
}
}
void get_hwmon_value( char * p_client_buffer, size_t client_buffer_size, char * fname, enum hwmon_sensor_type type )
{
static int rep;
int sensor_value;
FILE *fp;
if ( !p_client_buffer || client_buffer_size <= 0 || !fname )
return;
if ((fp = open_file(fname, &rep)) == NULL) {
snprintf( p_client_buffer, client_buffer_size, "hwmon: file '%s' not found", fname );
} else {
fscanf(fp, "%d", &sensor_value);
fclose(fp);
switch (type) {
case HWMON_temp:
sensor_value /= 1000; /* temperatures are given in milli-degree (at least for my abit uguru) */
break;
case HWMON_fan: /* already in RPM on my abit uguru */
case HWMON_other: /* do nothing */
default:
break;
}
snprintf( p_client_buffer, client_buffer_size, "%d", sensor_value );
}
}
/* Prior to kernel version 2.6.12, the CPU fan speed was available
* in ADT746X_FAN_OLD, whereas later kernel versions provide this
* information in ADT746X_FAN.