1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-03 20:48:31 +00:00

hwmon: add args for value precalculation

This commit is contained in:
Phil Sutter 2009-05-11 00:22:02 +02:00 committed by Phil Sutter
parent ae7996bdd1
commit 322d77942a
3 changed files with 32 additions and 15 deletions

View File

@ -1015,10 +1015,10 @@
<varlistentry>
<term>
<command><option>hwmon</option></command>
<option>(dev) type n</option>
<option>(dev) type n (factor offset)</option>
</term>
<listitem>
Hwmon sensor from sysfs (Linux 2.6). Parameter dev may be omitted if you have only one hwmon device. Parameter type is either 'in' or 'vol' meaning voltage; 'fan' meaning fan; 'temp' meaning temperature. Parameter n is number of the sensor. See /sys/class/hwmon/ on your local computer.
Hwmon sensor from sysfs (Linux 2.6). Parameter dev may be omitted if you have only one hwmon device. Parameter type is either 'in' or 'vol' meaning voltage; 'fan' meaning fan; 'temp' meaning temperature. Parameter n is number of the sensor. See /sys/class/hwmon/ on your local computer. The optional arguments 'factor' and 'offset' allow precalculation of the raw input, which is being modified as follows: 'input = input * factor + offset'. Note that they have to be given as decimal values (i.e. contain at least one decimal place).
<para></para></listitem>
</varlistentry>

View File

@ -1716,7 +1716,8 @@ static struct text_object *construct_text_object(const char *s,
END OBJ(hwmon, INFO_SYSFS)
char buf1[64], buf2[64];
int n;
float factor, offset;
int n, found = 0;
if (!arg) {
ERR("hwmon needs argumanets");
@ -1724,18 +1725,31 @@ static struct text_object *construct_text_object(const char *s,
return NULL;
}
if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
/* if scanf couldn't read three values, read type and num and use
* default device */
sscanf(arg, "%63s %d", buf2, &n);
obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
strncpy(obj->data.sysfs.type, buf2, 63);
} else {
obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
strncpy(obj->data.sysfs.type, buf2, 63);
buf1[0] = 0;
factor = 1.0;
offset = 0.0;
if (sscanf(arg, "%63s %63s %d %f %f", buf1, buf2, &n, &factor, &offset) == 5)
found = 1;
if (!found && (sscanf(arg, "%63s %d %f %f", buf2, &n, &factor, &offset) == 3))
found = 1;
if (!found && (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) == 3))
found = 1;
if (!found && (sscanf(arg, "%63s %d", buf2, &n) == 2))
found = 1;
if (!found) {
ERR("hwmon failed to parse arguments");
obj->type = OBJ_text;
return NULL;
}
DBGP("parsed hwmon args: %s %s %d %f %f\n", buf1, buf2, n, factor, offset);
obj->data.sysfs.fd = open_hwmon_sensor((*buf1) ? buf1 : 0, buf2, n,
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
strncpy(obj->data.sysfs.type, buf2, 63);
obj->data.sysfs.factor = factor;
obj->data.sysfs.offset = offset;
#endif /* !__OpenBSD__ */
END
@ -4136,6 +4150,8 @@ static void generate_text_internal(char *p, int p_max_size,
r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
obj->data.sysfs.devtype, obj->data.sysfs.type);
r = r * obj->data.sysfs.factor + obj->data.sysfs.offset;
if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
temp_print(p, p_max_size, r, TEMP_CELSIUS);
} else if (r >= 100.0 || r == 0) {

View File

@ -460,7 +460,8 @@ struct text_object {
int arg;
char devtype[256];
char type[64];
} sysfs; /* 2 */
float factor, offset;
} sysfs;
struct {
struct text_object *next;