From 9df94c7ee64f34ff9621316b5ef25d94200c6e32 Mon Sep 17 00:00:00 2001 From: Martin Han Date: Mon, 6 Apr 2015 14:38:35 +0800 Subject: [PATCH] Really Fix the BUGs, add come comment Sorry for the mistake, I forgot to save the file when gitting... --- lua_modules/dht_lib/dht_lib.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lua_modules/dht_lib/dht_lib.lua b/lua_modules/dht_lib/dht_lib.lua index e1edf13a..4fb60ae3 100644 --- a/lua_modules/dht_lib/dht_lib.lua +++ b/lua_modules/dht_lib/dht_lib.lua @@ -8,10 +8,15 @@ -- *************************************************************************** --Support list: ---DHT11 Tested ->read11 ---DHT21 Not Tested->read22 ---DHT22 Tested->read22 +--DHT11 Tested +--DHT21 Not Test yet +--DHT22(AM2302) Tested +--AM2320 Not Test yet + +--Output format-> Real temperature times 10(or DHT22 will miss it float part in Int Version) +--For example, the data read form DHT2x is 24.3 degree C, and the output will be 243 +---------------the data read form DHT1x is 27 degree C, and the output will be 270 --==========================Module Part====================== local moduleName = ... local M = {} @@ -99,7 +104,12 @@ local function bit2DHT11() if(checksum ~= humidity+temperature) then humidity = nil temperature = nil + else + humidity = humidity *10 -- In order to universe the DHT22 + temperature = temperature *10 end + + end ---------------------------Convert the bitStream into Number through DHT22 Ways-------------------------- @@ -144,7 +154,7 @@ local function bit2DHT22() end ---------------------------Check out the data-------------------------- -----Auto Select the DHT11/DHT22 By check the byte[1] && byte[3]AND --- +----Auto Select the DHT11/DHT22 by checking the byte[1]==0 && byte[3]==0 --- ---------------Which is empty when using DHT11------------------------- function M.read(pin) @@ -172,7 +182,7 @@ function M.read(pin) end end - +--------------API for geting the data out------------------ function M.getTemperature() return temperature @@ -181,5 +191,5 @@ end function M.getHumidity() return humidity end - +-------------Return Index------------------------------------ return M