diff --git a/lib/access.c b/lib/access.c index c4156eb0..a530469a 100644 --- a/lib/access.c +++ b/lib/access.c @@ -206,3 +206,11 @@ int sensors_set_value(sensors_chip_name name, int feature, double value) return -SENSORS_ERR_PROC; return 0; } + +const sensors_chip_name *sensors_get_detected_chips (int *nr) +{ + const sensors_chip_name *res; + res = *nr >= sensors_proc_chips_count?NULL:&sensors_proc_chips[*nr].name; + (*nr)++; + return res; +} diff --git a/lib/sensors.h b/lib/sensors.h index 944a9927..18f7bcf8 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -78,4 +78,11 @@ extern int sensors_get_feature(sensors_chip_name name, int feature, extern int sensors_set_value(sensors_chip_name name, int feature, double value); +/* This function returns all detected chips, one by one. To start at the + beginning of the list, use 0 for nr; NULL is returned if we are + at the end of the list. Do not try to change these chip names, as + they point to internal structures! Do not use nr for anything else. */ +extern const sensors_chip_name *sensors_get_detected_chips(int *nr); + + #endif /* def LIB_SENSORS_ERROR_H */ diff --git a/prog/sensors/main.c b/prog/sensors/main.c index bbd0d368..07a64153 100644 --- a/prog/sensors/main.c +++ b/prog/sensors/main.c @@ -119,6 +119,9 @@ int main (int argc, char *argv[]) { int c,res; + int chip_nr; + const sensors_chip_name *chip; + struct option long_opts[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v'}, @@ -158,4 +161,13 @@ int main (int argc, char *argv[]) fprintf(stderr,"%s\n",sensors_strerror(res)); exit(1); } + + /* Here comes the real code... */ + printf("Detected chips:\n"); + for (chip_nr = 0; (chip = sensors_get_detected_chips(&chip_nr));) + if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA) + printf(" %s-isa-%04x\n",chip->prefix,chip->addr); + else + printf(" %s-i2c-%d-%02x\n",chip->prefix,chip->bus,chip->addr); + exit(0); }