Now that we can deduce the scaling factor required for each feature

from its type, there's no need to store this scaling factor. We can
instead compute it at runtime. This saves some memory (about 10 kB
in my real-world test), and the runtime overhead is totally
negligible.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4762 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-09-05 08:21:19 +00:00
1 parent ed480f2edd
commit b836fc0b53
2 files changed
+7 -16

No files matched your search

+6 -12
View File
@@ -48,16 +48,16 @@ int get_type_scaling(int type)
switch (type & 0xFF10) {
case SENSORS_FEATURE_IN:
case SENSORS_FEATURE_TEMP:
return 3;
return 1000;
case SENSORS_FEATURE_FAN:
return 0;
return 1;
}
switch (type) {
case SENSORS_FEATURE_VID:
return 3;
return 1000;
default:
return 0;
return 1;
}
}
@@ -155,8 +155,6 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
if (attr->method & SYSFS_METHOD_STORE)
feature.data.flags |= SENSORS_MODE_W;
feature.scaling = get_type_scaling(type);
features[i] = feature;
fnum++;
}
@@ -422,7 +420,6 @@ int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature,
double *value)
{
const sensors_chip_feature *the_feature;
int mag;
char n[NAME_MAX];
FILE *f;
const char *suffix = "";
@@ -443,8 +440,7 @@ int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature,
fclose(f);
if (res != 1)
return -SENSORS_ERR_PROC;
for (mag = the_feature->scaling; mag > 0; mag --)
*value /= 10.0;
*value /= get_type_scaling(the_feature->data.type);
} else
return -SENSORS_ERR_PROC;
@@ -455,7 +451,6 @@ int sensors_write_sysfs_attr(const sensors_chip_name *name, int feature,
double value)
{
const sensors_chip_feature *the_feature;
int mag;
char n[NAME_MAX];
FILE *f;
const char *suffix = "";
@@ -472,8 +467,7 @@ int sensors_write_sysfs_attr(const sensors_chip_name *name, int feature,
snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->data.name,
suffix);
if ((f = fopen(n, "w"))) {
for (mag = the_feature->scaling; mag > 0; mag --)
value *= 10.0;
value *= get_type_scaling(the_feature->data.type);
fprintf(f, "%d", (int) value);
fclose(f);
} else