From ffdb162ad4740e2da9dac924628bc2c6a2939060 Mon Sep 17 00:00:00 2001 From: Kristjan Komlosi Date: Sat, 2 Nov 2019 12:38:18 +0100 Subject: [PATCH] fixed a bug with negative uv values --- backend/sensors.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/sensors.py b/backend/sensors.py index bdfb83d..a979c85 100644 --- a/backend/sensors.py +++ b/backend/sensors.py @@ -206,14 +206,19 @@ class UVSensor: # scary computations ahead! refer to Vishay app note 84339 and Sparkfun # VEML6075 documentation. - # first, compensate for visible and IR noise + # compensate for visible and IR noise aCorr = aRaw - 2.22 * c1 - 1.33 * c2 bCorr = bRaw - 2.95 * c1 - 1.74 * c2 - # second, convert values into irradiances - a = aCorr * 0.00110 - b = bCorr * 0.00125 + # convert values into irradiances + a = aCorr * 1.06 + b = bCorr * 0.48 + # zero out negative results (readings with no uv) + if a < 0: + a = 0 + if b < 0: + b = 0 # last, calculate the UV index i = (a + b) / 2