From 0863a4c2211b32b05b813348eb6a97f7af4ab21b Mon Sep 17 00:00:00 2001 From: Sebastian Schildt Date: Sun, 17 Jan 2016 14:39:39 +0100 Subject: [PATCH] Fix unit constants to be consistent with code Extend example to show querying different units or specific sensors --- lua_modules/ds18b20/ds18b20-example.lua | 8 ++++++++ lua_modules/ds18b20/ds18b20.lua | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lua_modules/ds18b20/ds18b20-example.lua b/lua_modules/ds18b20/ds18b20-example.lua index fca1accc..c349e43a 100644 --- a/lua_modules/ds18b20/ds18b20-example.lua +++ b/lua_modules/ds18b20/ds18b20-example.lua @@ -13,6 +13,14 @@ end -- Just read temperature print("Temperature: "..t.read().."'C") +-- Get temperature of first detected sensor in Fahrenheit +print("Temperature: "..t.read(nil,t.F).."'F") + +-- Query the second detected sensor, get temperature in Kelvin +if (table.getn(addrs) >= 2) then + print("Second sensor: "..t.read(addrs[2],t.K).."'K") +end + -- Don't forget to release it after use t = nil ds18b20 = nil diff --git a/lua_modules/ds18b20/ds18b20.lua b/lua_modules/ds18b20/ds18b20.lua index 20ebd1d7..de2d869b 100644 --- a/lua_modules/ds18b20/ds18b20.lua +++ b/lua_modules/ds18b20/ds18b20.lua @@ -33,9 +33,9 @@ setfenv(1,M) -------------------------------------------------------------------------------- -- Implementation -------------------------------------------------------------------------------- -C = 0 -F = 1 -K = 2 +C = 'C' +F = 'F' +K = 'K' function setup(dq) pin = dq if(pin == nil) then