Ver código fonte

Also support DS18S20 in this module

Resolve device differences before converting temperature to F or K.
Nick Andrew 8 anos atrás
pai
commit
de692f3540
1 arquivos alterados com 13 adições e 6 exclusões
  1. 13 6
      lua_modules/ds18b20/ds18b20.lua

+ 13 - 6
lua_modules/ds18b20/ds18b20.lua

@@ -101,12 +101,19 @@ function readNumber(addr, unit)
         if (t > 32767) then
           t = t - 65536
         end
-        if(unit == nil or unit == C) then
-          t = t * 625
-        elseif(unit == F) then
-          t = t * 1125 + 320000
-        elseif(unit == K) then
-          t = t * 625 + 2731500
+
+		if (addr:byte(1) == 0x28) then
+		  t = t * 625  -- DS18B20, 4 fractional bits
+		else
+		  t = t * 5000 -- DS18S20, 1 fractional bit
+		end
+
+        if(unit == nil or unit == 'C') then
+          -- do nothing
+        elseif(unit == 'F') then
+          t = t * 1.8 + 320000
+        elseif(unit == 'K') then
+          t = t + 2731500
         else
           return nil
         end