hwmon: add args for value precalculation
authorPhil Sutter <n0-1@freewrt.org>
Sun, 10 May 2009 22:22:02 +0000 (00:22 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 11 May 2009 22:49:40 +0000 (00:49 +0200)
doc/variables.xml
src/conky.c
src/text_object.h

index 1466ac1..c216293 100644 (file)
        <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>
 
index ab5f971..0b603d0 100644 (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) {
index 0037655..fe915a2 100644 (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;