diff -ruN torsmo-0.18/freebsd.c torsmo-0.18.new/freebsd.c --- torsmo-0.18/freebsd.c 2004-08-25 18:24:24.000000000 +0200 +++ torsmo-0.18.new/freebsd.c 2005-04-19 11:17:18.000000000 +0200 @@ -278,7 +278,7 @@ oldtotal = total; } -double get_i2c_info(int fd, int div) { +double get_i2c_info(int *fd, int div, char *devtype) { return 0; } @@ -314,7 +314,7 @@ snprintf(buf, n, "Battery is charging"); } -int open_i2c_sensor(const char *dev, const char *type, int n, int *div) +int open_i2c_sensor(const char *dev, const char *type, int n, int *div, char *devtype) { return 0; } diff -ruN torsmo-0.18/linux.c torsmo-0.18.new/linux.c --- torsmo-0.18/linux.c 2004-12-21 22:20:07.000000000 +0100 +++ torsmo-0.18.new/linux.c 2005-04-19 11:16:26.000000000 +0200 @@ -300,7 +300,7 @@ #define I2C_DIR "/sys/bus/i2c/devices/" -int open_i2c_sensor(const char *dev, const char *type, int n, int *div) { +int open_i2c_sensor(const char *dev, const char *type, int n, int *div, char *devtype) { char path[256]; char buf[64]; int fd; @@ -319,6 +319,7 @@ type = "in"; snprintf(path, 255, I2C_DIR "%s/%s%d_input", dev, type, n); + strcpy (devtype, path); /* open file */ fd = open(path, O_RDONLY); @@ -329,6 +330,10 @@ else *div = 0; + /* fan does not use *_div as a read divisor */ + if (strcmp ("fan", type) == 0) + return fd; + /* test if *_div file exist, open it and use it as divisor */ snprintf(path, 255, I2C_DIR "%s/%s%d_div", dev, type, n); @@ -349,24 +354,29 @@ return fd; } -double get_i2c_info(int fd, int div) { +double get_i2c_info(int *fd, int div, char *devtype) { int val = 0; - if (fd <= 0) return 0; + if (*fd <= 0) return 0; - lseek(fd, 0, SEEK_SET); + lseek(*fd, 0, SEEK_SET); /* read integer */ { char buf[64]; unsigned int n; - n = read(fd, buf, 63); + n = read(*fd, buf, 63); /* should read until n == 0 but I doubt that kernel will give these * in multiple pieces. :) */ buf[n] = '\0'; val = atoi(buf); } + close (*fd); + /* open file */ + *fd = open(devtype, O_RDONLY); + if (*fd < 0) ERR("can't open '%s': %s", devtype, strerror(errno)); + /* divide voltage and temperature by 1000 */ /* or if any other divisor is given, use that */ if (div > 1) diff -ruN torsmo-0.18/netbsd.c torsmo-0.18.new/netbsd.c --- torsmo-0.18/netbsd.c 2004-08-25 19:55:57.000000000 +0200 +++ torsmo-0.18.new/netbsd.c 2005-04-19 11:17:42.000000000 +0200 @@ -301,7 +301,7 @@ } -double get_i2c_info(int fd, int div) { +double get_i2c_info(int *fd, int div, char *devtype) { return -1; } @@ -321,7 +321,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat) { } -int open_i2c_sensor(const char *dev, const char *type, int n, int *div) +int open_i2c_sensor(const char *dev, const char *type, int n, int *div, char *devtype) { return -1; } diff -ruN torsmo-0.18/torsmo.c torsmo-0.18.new/torsmo.c --- torsmo-0.18/torsmo.c 2004-12-21 23:14:46.000000000 +0100 +++ torsmo-0.18.new/torsmo.c 2005-04-19 11:29:50.000000000 +0200 @@ -377,6 +377,7 @@ struct { int fd; int arg; + char devtype[256]; } i2c; /* 2 */ struct { @@ -606,10 +607,10 @@ /* if scanf couldn't read three values, read type and num and use * default device */ sscanf(arg, "%63s %d", buf2, &n); - obj->data.i2c.fd = open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg); + obj->data.i2c.fd = open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg, obj->data.i2c.devtype); } else { - obj->data.i2c.fd = open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg); + obj->data.i2c.fd = open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg, obj->data.i2c.devtype); } END OBJ(loadavg, INFO_LOADAVG) @@ -705,11 +706,11 @@ END OBJ(temp1, INFO_I2C) obj->type = OBJ_i2c; - obj->data.i2c.fd = open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg); + obj->data.i2c.fd = open_i2c_sensor(0, "temp", 1, &obj->data.i2c.arg, obj->data.i2c.devtype); END OBJ(temp2, INFO_I2C) obj->type = OBJ_i2c; - obj->data.i2c.fd = open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg); + obj->data.i2c.fd = open_i2c_sensor(0, "temp", 2, &obj->data.i2c.arg, obj->data.i2c.devtype); END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T"); @@ -1032,7 +1033,7 @@ OBJ(i2c) { double r; - r = get_i2c_info(obj->data.i2c.fd, obj->data.i2c.arg); + r = get_i2c_info(&obj->data.i2c.fd, obj->data.i2c.arg, obj->data.i2c.devtype); if (r >= 100.0 || r == 0) snprintf(p, n, "%d", (int) r); diff -ruN torsmo-0.18/torsmo.h torsmo-0.18.new/torsmo.h --- torsmo-0.18/torsmo.h 2004-12-21 22:49:17.000000000 +0100 +++ torsmo-0.18.new/torsmo.h 2005-04-19 11:16:42.000000000 +0200 @@ -172,8 +172,8 @@ void update_running_processes(void); char* get_freq(); void update_load_average(); -int open_i2c_sensor(const char *dev, const char *type, int n, int *div); -double get_i2c_info(int fd, int arg); +int open_i2c_sensor(const char *dev, const char *type, int n, int *div, char *devtype); +double get_i2c_info(int *fd, int arg, char *devtype); char* get_adt746x_cpu(void); char* get_adt746x_fan(void);