From 488d20b783e9bc0420c132ec62923a4528ce1b9b Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Fri, 13 Aug 2021 17:05:28 +1200 Subject: [PATCH] prog/sensors: Only do conversion to Fahrenheit on temperatures Only apply conversion from Celsius to Fahrenheit on temperature values. Leave other sensor readings as they were returned. Fixes #357 Signed-off-by: Chris Packham --- prog/sensors/chips.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/prog/sensors/chips.c b/prog/sensors/chips.c index 0eb07418..17ada742 100644 --- a/prog/sensors/chips.c +++ b/prog/sensors/chips.c @@ -46,6 +46,7 @@ void print_chip_raw(const sensors_chip_name *name) const sensors_subfeature *sub; char *label; double val; + int is_temp; a = 0; while ((feature = sensors_get_features(name, &a))) { @@ -59,6 +60,8 @@ void print_chip_raw(const sensors_chip_name *name) b = 0; while ((sub = sensors_get_all_subfeatures(name, feature, &b))) { if (sub->flags & SENSORS_MODE_R) { + is_temp = feature->type == SENSORS_FEATURE_TEMP; + if ((err = sensors_get_value(name, sub->number, &val))) fprintf(stderr, "ERROR: Can't get " @@ -66,7 +69,7 @@ void print_chip_raw(const sensors_chip_name *name) sub->name, sensors_strerror(err)); else { - if (fahrenheit) + if (is_temp && fahrenheit) val = deg_ctof(val); printf(" %s: %.3f\n", sub->name, val); } @@ -84,6 +87,7 @@ void print_chip_json(const sensors_chip_name *name) const sensors_subfeature *sub; char *label; double val; + int is_temp; a = 0; cnt = 0; @@ -101,6 +105,8 @@ void print_chip_json(const sensors_chip_name *name) subCnt = 0; while ((sub = sensors_get_all_subfeatures(name, feature, &b))) { if (sub->flags & SENSORS_MODE_R) { + is_temp = feature->type == SENSORS_FEATURE_TEMP; + if ((err = sensors_get_value(name, sub->number, &val))) { fprintf(stderr, "ERROR: Can't get " @@ -110,7 +116,7 @@ void print_chip_json(const sensors_chip_name *name) } else { if (subCnt > 0) printf(",\n"); - if (fahrenheit) + if (is_temp && fahrenheit) val = deg_ctof(val); printf(" \"%s\": %.3f", sub->name, val); subCnt++;