mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-30 13:57:41 +00:00
Yet more library and prog/sensors stuff. LM75 data is now printed!
* Added sensors_get_algorithm_name and sensors_get_adapter_name to the library. * First application of sensors_get_value is very encouraging; LM75 data is now printed. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@103 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
parent
c9d9c6c682
commit
6ad35eaa33
26
lib/access.c
26
lib/access.c
@ -140,7 +140,7 @@ int sensors_get_label(sensors_chip_name name, int feature, char **result)
|
|||||||
for (chip = NULL; (chip = sensors_for_all_config_chips(name,chip));)
|
for (chip = NULL; (chip = sensors_for_all_config_chips(name,chip));)
|
||||||
for (i = 0; i < chip->labels_count; i++)
|
for (i = 0; i < chip->labels_count; i++)
|
||||||
if (!strcmp(featureptr->name, chip->labels[i].name)) {
|
if (!strcmp(featureptr->name, chip->labels[i].name)) {
|
||||||
if (! (*result = strdup(chip->labels[i].name)))
|
if (! (*result = strdup(chip->labels[i].value)))
|
||||||
sensors_fatal_error("sensors_get_label","Allocating label text");
|
sensors_fatal_error("sensors_get_label","Allocating label text");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ int sensors_get_feature(sensors_chip_name name, int feature, double *result)
|
|||||||
/* Set the value of a feature of a certain chip. Note that chip should not
|
/* Set the value of a feature of a certain chip. Note that chip should not
|
||||||
contain wildcard values! This function will return 0 on success, and <0
|
contain wildcard values! This function will return 0 on success, and <0
|
||||||
on failure. */
|
on failure. */
|
||||||
int sensors_set_value(sensors_chip_name name, int feature, double value)
|
int sensors_set_feature(sensors_chip_name name, int feature, double value)
|
||||||
{
|
{
|
||||||
sensors_chip_feature *featureptr;
|
sensors_chip_feature *featureptr;
|
||||||
sensors_chip *chip;
|
sensors_chip *chip;
|
||||||
@ -214,3 +214,25 @@ const sensors_chip_name *sensors_get_detected_chips (int *nr)
|
|||||||
(*nr)++;
|
(*nr)++;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *sensors_get_adapter_name(int bus_nr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if (bus_nr == SENSORS_CHIP_NAME_BUS_ISA)
|
||||||
|
return "ISA adapter";
|
||||||
|
for (i=0; i < sensors_proc_bus_count; i++)
|
||||||
|
if (sensors_proc_bus[i].number == bus_nr)
|
||||||
|
return sensors_proc_bus[i].adapter;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *sensors_get_algorithm_name(int bus_nr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if (bus_nr == SENSORS_CHIP_NAME_BUS_ISA)
|
||||||
|
return "ISA algorithm";
|
||||||
|
for (i=0; i < sensors_proc_bus_count; i++)
|
||||||
|
if (sensors_proc_bus[i].number == bus_nr)
|
||||||
|
return sensors_proc_bus[i].algorithm;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -60,6 +60,12 @@ extern int sensors_match_chip(sensors_chip_name chip1,
|
|||||||
if there are wildcards. */
|
if there are wildcards. */
|
||||||
extern int sensors_chip_name_has_wildcards(sensors_chip_name chip);
|
extern int sensors_chip_name_has_wildcards(sensors_chip_name chip);
|
||||||
|
|
||||||
|
/* These functions return the adapter and algorithm names of a bus number,
|
||||||
|
as used within the sensors_chip_name structure. If it could not be found,
|
||||||
|
it returns NULL */
|
||||||
|
extern const char *sensors_get_adapter_name(int bus_nr);
|
||||||
|
extern const char *sensors_get_algorithm_name(int bus_nr);
|
||||||
|
|
||||||
/* Look up the label which belongs to this chip. Note that chip should not
|
/* Look up the label which belongs to this chip. Note that chip should not
|
||||||
contain wildcard values! *result is newly allocated (free it yourself).
|
contain wildcard values! *result is newly allocated (free it yourself).
|
||||||
This function will return 0 on success, and <0 on failure. */
|
This function will return 0 on success, and <0 on failure. */
|
||||||
@ -75,8 +81,8 @@ extern int sensors_get_feature(sensors_chip_name name, int feature,
|
|||||||
/* Set the value of a feature of a certain chip. Note that chip should not
|
/* Set the value of a feature of a certain chip. Note that chip should not
|
||||||
contain wildcard values! This function will return 0 on success, and <0
|
contain wildcard values! This function will return 0 on success, and <0
|
||||||
on failure. */
|
on failure. */
|
||||||
extern int sensors_set_value(sensors_chip_name name, int feature,
|
extern int sensors_set_feature(sensors_chip_name name, int feature,
|
||||||
double value);
|
double value);
|
||||||
|
|
||||||
/* This function returns all detected chips, one by one. To start at the
|
/* 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
|
beginning of the list, use 0 for nr; NULL is returned if we are
|
||||||
|
@ -23,14 +23,14 @@ MODULE_DIR := prog/sensors
|
|||||||
# Regrettably, even 'simply expanded variables' will not put their currently
|
# Regrettably, even 'simply expanded variables' will not put their currently
|
||||||
# defined value verbatim into the command-list of rules...
|
# defined value verbatim into the command-list of rules...
|
||||||
PROGSENSORSTARGETS := $(MODULE_DIR)/sensors
|
PROGSENSORSTARGETS := $(MODULE_DIR)/sensors
|
||||||
PROGSENSORSSOURCES := $(MODULE_DIR)/main.c
|
PROGSENSORSSOURCES := $(MODULE_DIR)/main.c $(MODULE_DIR)/chips.c
|
||||||
|
|
||||||
# Include all dependency files. We use '.rd' to indicate this will create
|
# Include all dependency files. We use '.rd' to indicate this will create
|
||||||
# executables.
|
# executables.
|
||||||
INCLUDEFILES += $(PROGSENSORSSOURCES:.c=.rd)
|
INCLUDEFILES += $(PROGSENSORSSOURCES:.c=.rd)
|
||||||
|
|
||||||
$(PROGSENSORSTARGETS): $(PROGSENSORSSOURCES:.c=.ro) lib/$(LIBSHBASENAME)
|
$(PROGSENSORSTARGETS): $(PROGSENSORSSOURCES:.c=.ro) lib/$(LIBSHBASENAME)
|
||||||
$(CC) -o $@ $^ -Llib -lsensors
|
$(CC) -o $@ $(PROGSENSORSSOURCES:.c=.ro) -Llib -lsensors
|
||||||
|
|
||||||
all-prog-sensors: $(PROGSENSORSTARGETS)
|
all-prog-sensors: $(PROGSENSORSTARGETS)
|
||||||
all :: all-prog-sensors
|
all :: all-prog-sensors
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
#include "lib/error.h"
|
#include "lib/error.h"
|
||||||
|
#include "chips.h"
|
||||||
|
|
||||||
#define PROGRAM "sensors"
|
#define PROGRAM "sensors"
|
||||||
#define VERSION "0.0"
|
#define VERSION "0.0"
|
||||||
@ -121,6 +122,7 @@ int main (int argc, char *argv[])
|
|||||||
|
|
||||||
int chip_nr;
|
int chip_nr;
|
||||||
const sensors_chip_name *chip;
|
const sensors_chip_name *chip;
|
||||||
|
const char *algo,*adap;
|
||||||
|
|
||||||
struct option long_opts[] = {
|
struct option long_opts[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
@ -163,11 +165,22 @@ int main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Here comes the real code... */
|
/* Here comes the real code... */
|
||||||
printf("Detected chips:\n");
|
for (chip_nr = 0; (chip = sensors_get_detected_chips(&chip_nr));) {
|
||||||
for (chip_nr = 0; (chip = sensors_get_detected_chips(&chip_nr));)
|
|
||||||
if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
|
if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
|
||||||
printf(" %s-isa-%04x\n",chip->prefix,chip->addr);
|
printf("%s-isa-%04x\n",chip->prefix,chip->addr);
|
||||||
else
|
else
|
||||||
printf(" %s-i2c-%d-%02x\n",chip->prefix,chip->bus,chip->addr);
|
printf("%s-i2c-%d-%02x\n",chip->prefix,chip->bus,chip->addr);
|
||||||
|
adap = sensors_get_adapter_name(chip->bus);
|
||||||
|
if (adap)
|
||||||
|
printf("Adapter: %s\n",adap);
|
||||||
|
algo = sensors_get_algorithm_name(chip->bus);
|
||||||
|
if (algo)
|
||||||
|
printf("Algorithm: %s\n",algo);
|
||||||
|
if (!algo || !adap)
|
||||||
|
printf(" ERROR: Can't get adapter or algorithm?!?\n");
|
||||||
|
if (!strcmp(chip->prefix,"lm75"))
|
||||||
|
print_lm75(chip);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user