From 29bea1e84351aaf7caa9184583dfa7ee5464fb5d Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 5 Sep 2007 12:28:31 +0000 Subject: [PATCH] Add support for the standard beep_enable attribute (#2248). git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4766 7894878c-1315-0410-8ee3-d5d059ff63e0 --- lib/access.c | 6 ++++++ lib/sensors.h | 2 ++ lib/sysfs.c | 15 +++++++++++---- prog/sensors/chips.c | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/access.c b/lib/access.c index 44eb5198..1c799f78 100644 --- a/lib/access.c +++ b/lib/access.c @@ -562,6 +562,12 @@ sensors_feature_type sensors_feature_get_type(const char *name, int *nr) int i, count; const struct feature_subtype_match *submatches; + /* Special case */ + if (!strcmp(name, "beep_enable")) { + *nr = 0; + return SENSORS_FEATURE_BEEP_ENABLE; + } + for (i = 0; i < ARRAY_SIZE(matches); i++) if ((count = sscanf(name, matches[i].name, nr, &c))) break; diff --git a/lib/sensors.h b/lib/sensors.h index 32cd7f4b..753d4fa4 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -154,6 +154,8 @@ typedef enum sensors_feature_type { SENSORS_FEATURE_VID = 0x300, + SENSORS_FEATURE_BEEP_ENABLE = 0x1100, + SENSORS_FEATURE_UNKNOWN = INT_MAX, } sensors_feature_type; diff --git a/lib/sysfs.c b/lib/sysfs.c index d28039c8..10d69392 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -38,9 +38,10 @@ char sensors_sysfs_mount[NAME_MAX]; #define MAX_SENSORS_PER_TYPE 20 #define MAX_SUB_FEATURES 6 -/* Room for all 3 types (in, fan, temp) with all their subfeatures + VID */ +/* Room for all 3 types (in, fan, temp) with all their subfeatures + VID + + misc features */ #define ALL_POSSIBLE_FEATURES (MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6 \ - + MAX_SENSORS_PER_TYPE) + + MAX_SENSORS_PER_TYPE + 1) static int get_type_scaling(int type) @@ -109,9 +110,15 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, /* "calculate" a place to store the feature in our sparse, sorted table */ - if (type == SENSORS_FEATURE_VID) { + switch (type) { + case SENSORS_FEATURE_VID: i = nr + MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6; - } else { + break; + case SENSORS_FEATURE_BEEP_ENABLE: + i = MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6 + + MAX_SENSORS_PER_TYPE; + break; + default: i = (type >> 8) * MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 2 + nr * MAX_SUB_FEATURES * 2 + ((type & 0x10) >> 4) * MAX_SUB_FEATURES + diff --git a/prog/sensors/chips.c b/prog/sensors/chips.c index 576cf1f2..bc9d512d 100644 --- a/prog/sensors/chips.c +++ b/prog/sensors/chips.c @@ -390,6 +390,20 @@ static void print_chip_vid(const sensors_chip_name *name, int f_vid, free(label); } +static void print_chip_beep_enable(const sensors_chip_name *name, int f_beep, + int label_size) +{ + char *label; + double beep_enable; + + if ((label = sensors_get_label(name, f_beep)) + && !sensors_get_value(name, f_beep, &beep_enable)) { + print_label(label, label_size); + printf("%s\n", beep_enable ? "enabled" : "disabled"); + } + free(label); +} + void print_chip(const sensors_chip_name *name) { const sensors_feature_data *feature; @@ -415,6 +429,10 @@ void print_chip(const sensors_chip_name *name) case SENSORS_FEATURE_VID: print_chip_vid(name, feature->number, label_size); break; + case SENSORS_FEATURE_BEEP_ENABLE: + print_chip_beep_enable(name, feature->number, + label_size); + break; default: continue; }