From 55332eaa6803638e1a5b382a8f639544c576266b Mon Sep 17 00:00:00 2001 From: Jose Barros Date: Wed, 31 Oct 2018 22:46:11 +0000 Subject: [PATCH] Fixes ISSUE#5 Prevent wrong adc value calc with weird calibration values --- Drivers/generalIO/tempsensors.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Drivers/generalIO/tempsensors.c b/Drivers/generalIO/tempsensors.c index ec4f6e68..89655387 100644 --- a/Drivers/generalIO/tempsensors.c +++ b/Drivers/generalIO/tempsensors.c @@ -67,7 +67,10 @@ tipData * getCurrentTip() { uint16_t human2adc(uint16_t t) { uint16_t temp = t; uint16_t ambientTemperature = readColdJunctionSensorTemp_mC() / 1000; - t = t - ambientTemperature; + if(ambientTemperature > 50) + ambientTemperature = 50; + if(t > ambientTemperature) + t = t - ambientTemperature; if (t < temp_minC) t = temp_minC; if (t > temp_maxC) t = temp_maxC; if (t >= currentTipData->calADC_At_300) @@ -113,5 +116,9 @@ uint16_t adc2Human(uint16_t adc_value) { long map(long x, long in_min, long in_max, long out_min, long out_max) { - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + long ret; + ret = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + if(ret < 0) + ret = 0; + return ret; }