From d53ac8db9011ec68196bf568b8d1ff2b64bf9523 Mon Sep 17 00:00:00 2001 From: Jonathan Karras Date: Mon, 6 Mar 2017 23:06:50 -0700 Subject: [PATCH] Change address printing to Hex from Base64. (#1840) --- lua_modules/ds18b20/ds18b20-example.lua | 4 +-- lua_modules/ds18b20/ds18b20.lua | 35 ++++++++++++------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lua_modules/ds18b20/ds18b20-example.lua b/lua_modules/ds18b20/ds18b20-example.lua index d8ab621b..9921829c 100644 --- a/lua_modules/ds18b20/ds18b20-example.lua +++ b/lua_modules/ds18b20/ds18b20-example.lua @@ -7,7 +7,7 @@ pin = 3 -- gpio0 = 3, gpio2 = 4 function readout(temp) for addr, temp in pairs(temp) do -- print(string.format("Sensor %s: %s 'C", addr, temp)) - print(string.format("Sensor %s: %s 'C", encoder.toBase64(addr), temp)) -- readable address with base64 encoding is preferred when encoder module is available + print(string.format("Sensor %s: %s °C", encoder.toHex(addr), temp)) -- readable address with base64 encoding is preferred when encoder module is available end -- Module can be released when it is no longer needed @@ -21,6 +21,6 @@ if t.sens then print("Total number of DS18B20 sensors: "..table.getn(t.sens)) for i, s in ipairs(t.sens) do -- print(string.format(" sensor #%d address: %s%s", i, s.addr, s.parasite == 1 and " (parasite)" or "")) - print(string.format(" sensor #%d address: %s%s", i, encoder.toBase64(s.addr), s.parasite == 1 and " (parasite)" or "")) -- readable address with base64 encoding is preferred when encoder module is available + print(string.format(" sensor #%d address: %s%s", i, encoder.toHex(s.addr), s.parasite == 1 and " (parasite)" or "")) -- readable address with base64 encoding is preferred when encoder module is available end end diff --git a/lua_modules/ds18b20/ds18b20.lua b/lua_modules/ds18b20/ds18b20.lua index 7571ad39..dddd9dee 100644 --- a/lua_modules/ds18b20/ds18b20.lua +++ b/lua_modules/ds18b20/ds18b20.lua @@ -12,12 +12,12 @@ return({ pin=3, sens={}, temp={}, - + conversion = function(self) local pin = self.pin for i,s in ipairs(self.sens) do if s.status == 0 then - print("starting conversion:", encoder.toBase64(s.addr), s.parasite == 1 and "parasite" or " ") + print("starting conversion:", encoder.toHex(s.addr), s.parasite == 1 and "parasite" or " ") ow.reset(pin) ow.select(pin, s.addr) -- select the sensor ow.write(pin, 0x44, 1) -- and start conversion @@ -27,14 +27,14 @@ return({ end tmr.alarm(tmr.create(), 750, tmr.ALARM_SINGLE, function() self:readout() end) end, - + readTemp = function(self, cb, lpin) local pin = self.pin self.cb = cb self.temp={} if lpin then pin = lpin end ow.setup(pin) - + self.sens={} ow.reset_search(pin) -- ow.target_search(pin,0x28) @@ -50,25 +50,25 @@ return({ ow.write(pin, 0xB4, 1) -- Read Power Supply [B4h] local parasite = (ow.read(pin)==0 and 1 or 0) table.insert(self.sens,{addr=addr, parasite=parasite, status=0}) - print("contact: ", encoder.toBase64(addr), parasite == 1 and "parasite" or " ") + print("contact: ", encoder.toHex(addr), parasite == 1 and "parasite" or " ") end addr = ow.search(pin) tmr.wdclr() end - + -- place powered sensors first table.sort(self.sens, function(a,b) return a.parasite= 5 and 1 or 0) - + if tH and (tH~=85) then self.temp[s.addr]=(sgn<0 and "-" or "")..tH.."."..tL - print(encoder.toBase64(s.addr),(sgn<0 and "-" or "")..tH.."."..tL) + print(encoder.toHex(s.addr),(sgn<0 and "-" or "")..tH.."."..tL) s.status = 2 end -- end integer version -- -- float version -- if t and (math.floor(t/10000)~=85) then -- self.temp[s.addr]=t - -- print(encoder.toBase64(s.addr), t) + -- print(encoder.toHex(s.addr), t) -- s.status = 2 -- end -- -- end float version end next = next or s.status == 0 end - if next then + if next then node.task.post(node.task.MEDIUM_PRIORITY, function() self:conversion() end) else self.sens = nil - if self.cb then - node.task.post(node.task.MEDIUM_PRIORITY, function() self.cb(self.temp) end) + if self.cb then + node.task.post(node.task.MEDIUM_PRIORITY, function() self.cb(self.temp) end) end end - + end }) -