Fix issue #111 - DHT12 negative temperature

This commit is contained in:
RobTillaart 2018-09-02 16:26:19 +02:00
parent 768fd8c92e
commit dee30a3f5b
8 changed files with 17 additions and 14 deletions

View File

@ -1,13 +1,15 @@
//
// FILE: DHT12.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// PURPOSE: I2C library for DHT12 for Arduino.
//
// HISTORY:
// 0.1.0: 2017-12-11 initial version
// 0.1.1: 2017-12-19 added ESP8266 - issue #86
// Verified by Viktor Balint
// 0.1.2: 2018-09-02 fix negative temperature DHT12 - issue #111
//
//
// Released to the public domain
//
@ -42,8 +44,8 @@ int8_t DHT12::read()
// CONVERT AND STORE
humidity = bits[0] + bits[1] * 0.1;
temperature = (bits[2] & 0x7F) + bits[3] * 0.1;
if (bits[2] & 0x80)
temperature = bits[2] + (bits[3] & 0x7F) * 0.1;
if (bits[3] & 0x80)
{
temperature = -temperature;
}

View File

@ -4,7 +4,7 @@
// FILE: DHT12.h
// AUTHOR: Rob Tillaart
// PURPOSE: DHT_I2C library for Arduino .
// VERSION: 0.1.1
// VERSION: 0.1.2
// HISTORY: See DHT12.cpp
// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/
//
@ -14,7 +14,7 @@
#include "Wire.h"
#include "Arduino.h"
#define DHT12_VERSION "0.1.1"
#define DHT12_VERSION "0.1.2"
#define DHT12_OK 0
#define DHT12_ERROR_CHECKSUM -10

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Arduino.git"
},
"version":"0.1.1",
"version":"0.1.2",
"frameworks": "arduino",
"platforms": "*",
"export": {

View File

@ -1,5 +1,5 @@
name=DHT12
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=I2C Library for DHT12 Temperature and Humidity.

View File

@ -1,11 +1,12 @@
//
// FILE: dht.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.28
// VERSION: 0.1.29
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// 0.1.29 2018-09-02 fix negative temperature DHT12 - issue #111
// 0.1.28 2018-04-03 refactor
// 0.1.27 2018-03-26 added _disableIRQ flag
// 0.1.26 2017-12-12 explicit support for AM23XX series and DHT12
@ -85,8 +86,8 @@ int8_t dht::read12(uint8_t pin)
// CONVERT AND STORE
humidity = bits[0] + bits[1] * 0.1;
temperature = (bits[2] & 0x7F) + bits[3] * 0.1;
if (bits[2] & 0x80) // negative temperature
temperature = bits[2] + (bits[3] & 0x7F) * 0.1;
if (bits[3] & 0x80) // negative temperature
{
temperature = -temperature;
}

View File

@ -1,7 +1,7 @@
//
// FILE: dht.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.28
// VERSION: 0.1.29
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
@ -19,7 +19,7 @@
#include <Arduino.h>
#endif
#define DHT_LIB_VERSION "0.1.28"
#define DHT_LIB_VERSION "0.1.29"
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Arduino.git"
},
"version":"0.1.28",
"version":"0.1.29",
"frameworks": "arduino",
"platforms": "*",
"export": {

View File

@ -1,5 +1,5 @@
name=DHTlib
version=0.1.28
version=0.1.29
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Optimized Library for DHT Temperature & Humidity Sensor on AVR only.