All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] hwmon: sht15: Fix sht15_calc_temp
@ 2010-03-26 21:30 Jerome Oufella
  2010-03-29 16:23 ` Jerome Oufella
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Jerome Oufella @ 2010-03-26 21:30 UTC (permalink / raw)
  To: lm-sensors

I discovered two issues.
First the previous sht15_calc_temp() loop did not iterate through the
temppoints array since the (data->supply_uV > temppoints[i - 1].vdd)
test is always true in this direction.

Also the two-points linear interpolation function was returning biased
values which I adressed using a different form of interpolation.

Signed-off-by: Jerome Oufella <jerome.oufella@savoirfairelinux.com>
---

 drivers/hwmon/sht15.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)


diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index 864a371..a6ad93b 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -303,15 +303,15 @@ error_ret:
 static inline int sht15_calc_temp(struct sht15_data *data)
 {
 	int d1 = 0;
-	int i;
+	int i, t;
 
-	for (i = 1; i < ARRAY_SIZE(temppoints); i++)
+	for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--)
 		/* Find pointer to interpolate */
-		if (data->supply_uV > temppoints[i - 1].vdd) {
-			d1 = (data->supply_uV/1000 - temppoints[i - 1].vdd)
-				* (temppoints[i].d1 - temppoints[i - 1].d1)
-				/ (temppoints[i].vdd - temppoints[i - 1].vdd)
-				+ temppoints[i - 1].d1;
+		if (data->supply_uV >= temppoints[i - 1].vdd) {
+			t = (data->supply_uV - temppoints[i-1].vdd) / 
+				((temppoints[i].vdd - temppoints[i-1].vdd) / 10000);
+
+			d1 = (temppoints[i].d1 * t + (10000 - t) * temppoints[i-1].d1) / 10000;
 			break;
 		}
 
-- 
1.6.3.3


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [lm-sensors] [PATCH] hwmon: (sht15) Fix sht15_calc_temp
@ 2010-04-01 15:02 Jean Delvare
  0 siblings, 0 replies; 14+ messages in thread
From: Jean Delvare @ 2010-04-01 15:02 UTC (permalink / raw)
  To: lm-sensors

From: Jerome Oufella <jerome.oufella@savoirfairelinux.com>

I discovered two issues.
First the previous sht15_calc_temp() loop did not iterate through the
temppoints array since the (data->supply_uV > temppoints[i - 1].vdd)
test is always true in this direction.

Also the two-points linear interpolation function was returning biased
values due to a stray division by 1000 which shouldn't be there.

[JD: Also change the default value for d1 from 0 to something saner.]

Signed-off-by: Jerome Oufella <jerome.oufella@savoirfairelinux.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: stable@kernel.org
---
 drivers/hwmon/sht15.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- linux-2.6.34-rc3.orig/drivers/hwmon/sht15.c	2010-04-01 16:24:33.000000000 +0200
+++ linux-2.6.34-rc3/drivers/hwmon/sht15.c	2010-04-01 16:49:45.000000000 +0200
@@ -302,13 +302,13 @@ error_ret:
  **/
 static inline int sht15_calc_temp(struct sht15_data *data)
 {
-	int d1 = 0;
+	int d1 = temppoints[0].d1;
 	int i;
 
-	for (i = 1; i < ARRAY_SIZE(temppoints); i++)
+	for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--)
 		/* Find pointer to interpolate */
 		if (data->supply_uV > temppoints[i - 1].vdd) {
-			d1 = (data->supply_uV/1000 - temppoints[i - 1].vdd)
+			d1 = (data->supply_uV - temppoints[i - 1].vdd)
 				* (temppoints[i].d1 - temppoints[i - 1].d1)
 				/ (temppoints[i].vdd - temppoints[i - 1].vdd)
 				+ temppoints[i - 1].d1;


-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-04-01 15:02 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-26 21:30 [lm-sensors] [PATCH] hwmon: sht15: Fix sht15_calc_temp Jerome Oufella
2010-03-29 16:23 ` Jerome Oufella
2010-03-29 18:42 ` Jonathan Cameron
2010-03-29 19:58 ` Jerome Oufella
2010-03-30 11:36 ` Jonathan Cameron
2010-03-30 14:00 ` Jerome Oufella
2010-03-30 14:00 ` Jerome Oufella
2010-04-01 12:01 ` Jean Delvare
2010-04-01 12:01   ` [lm-sensors] [PATCH] hwmon: sht15: Fix sht15_calc_temp interpolation function Jean Delvare
2010-04-01 12:54 ` [lm-sensors] [PATCH] hwmon: sht15: Fix sht15_calc_temp Jerome Oufella
2010-04-01 12:54   ` [lm-sensors] [PATCH] hwmon: sht15: Fix sht15_calc_temp interpolation function Jerome Oufella
2010-04-01 13:49   ` [lm-sensors] [PATCH] hwmon: sht15: Fix sht15_calc_temp Jonathan Cameron
2010-04-01 13:49     ` [lm-sensors] [PATCH] hwmon: sht15: Fix sht15_calc_temp interpolation function Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2010-04-01 15:02 [lm-sensors] [PATCH] hwmon: (sht15) Fix sht15_calc_temp Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.