From c20ee4abc0cc5a2f81ed47c770beb0ecad349b15 Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Tue, 24 Nov 2015 02:19:38 +0100 Subject: [PATCH] =?UTF-8?q?Temperatures=20below=200=C2=B0C=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Temperatures below the freezing point would result in temperatures above 3276.7°C, due to the overflow not getting handled. Solution is to subtract 32767 and then reverse the sign. I did the same for the humidity, just in case. --- firmware/SparkFunRHT03.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/firmware/SparkFunRHT03.cpp b/firmware/SparkFunRHT03.cpp index 6b9e78a..ebd3915 100644 --- a/firmware/SparkFunRHT03.cpp +++ b/firmware/SparkFunRHT03.cpp @@ -97,7 +97,15 @@ int RHT03::update() if (checksum(dataBytes[CHECKSUM], dataBytes, 4)) { _humidity = ((uint16_t) dataBytes[HUMIDITY_H] << 8) | dataBytes[HUMIDITY_L]; + if(_humidity & 0x8000) { + _humidity -= 0x7FFF; + _humidity *= -1; + } _temperature = ((uint16_t) dataBytes[TEMP_H] << 8) | dataBytes[TEMP_L]; + if(_temperature & 0x8000) { + _temperature -= 0x7FFF; + _temperature *= -1; + } return 1; } else @@ -135,4 +143,4 @@ bool RHT03::waitForRHT(int pinState, unsigned int timeout) return false; else return true; -} \ No newline at end of file +}