From c9d9c6c68270d12f355a4f060eb926a2ff2f3141 Mon Sep 17 00:00:00 2001 From: Frodo Looijaard Date: Tue, 22 Dec 1998 02:06:51 +0000 Subject: [PATCH] Library addition (sensors_get_detected_chips), program addition (print detected chips) Yes! I am getting somewhere now. The sensors program does at last something visible: it prints all detected chips. OK, cat /proc/sys/dev/sensors/chips is faster. But it is a start... git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@102 7894878c-1315-0410-8ee3-d5d059ff63e0 --- lib/access.c | 8 ++++++++ lib/sensors.h | 7 +++++++ prog/sensors/main.c | 12 ++++++++++++ 3 files changed, 27 insertions(+) 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); }