Extracted temperatur functionality into wordclock.lua

This commit is contained in:
Ollo 2021-11-01 13:38:22 +01:00
parent 0f2855aafa
commit 7cf761c7a5
3 changed files with 68 additions and 61 deletions

View File

@ -48,6 +48,11 @@ function displayTime()
words.briPer=nil words.briPer=nil
end end
end end
local tw=nil
local tcol=nil
if (mqttDispTemp ~= nil) then
tw, tcol = wc.temp(dw, rgbBuffer, invertRows)
end
wc = nil wc = nil
collectgarbage() collectgarbage()
print("wc: " .. tostring(node.heap())) print("wc: " .. tostring(node.heap()))
@ -61,13 +66,10 @@ function displayTime()
local c = dw.countChars(words) local c = dw.countChars(words)
dw.generateLEDs(rgbBuffer, words, colorBg, color, color1, color2, color3, color4, invertRows, c) dw.generateLEDs(rgbBuffer, words, colorBg, color, color1, color2, color3, color4, invertRows, c)
end end
if (mqttDispTemp ~= nil) then
local tw, tcol = mqttDispTemp(dw, rgbBuffer, invertRows)
if ( (tw ~= nil) and (tcol ~= nil) ) then if ( (tw ~= nil) and (tcol ~= nil) ) then
local c1 = dw.countChars(tw) local c1 = dw.countChars(tw)
dw.generateLEDs(rgbBuffer, tw, nil, tcol, nil, nil, nil, nil, invertRows, c1) dw.generateLEDs(rgbBuffer, tw, nil, tcol, nil, nil, nil, nil, invertRows, c1)
end end
end
dw = nil dw = nil
collectgarbage() collectgarbage()
print("dw: " .. tostring(node.heap())) print("dw: " .. tostring(node.heap()))

View File

@ -3,7 +3,7 @@ local m=nil
local mqttConnected = false local mqttConnected = false
-- Temp: -- Temp:
local t=nil local t=nil
local dispTemp=nil dispTemp=nil
function handleSingleCommand(client, topic, data) function handleSingleCommand(client, topic, data)
if (data == "ON") then if (data == "ON") then
@ -106,55 +106,6 @@ function reConnectMqtt()
end end
end end
-- Logic to display Mqtt
function mqttDispTemp(dw, rgbBuffer, invertRows)
if (dispTemp ~= nil) then
-- Values: it, is, 5 minutes, 10 minutes, afer, before, three hour, quarter, dreiviertel, half, s
-- hours: one, one Long, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve
-- Special ones: twenty, clock, minute 1 flag, minute 2 flag, minute 3 flag, minute 4 flag
local ret = { it=0, is=0, m5=0, m10=0, ha=0, hb=0, h3=0, hq=0, h3q=0, half=0, s=0,
h1=0, h1l=0, h2=0, h3=0, h4=0, h5=0, h6=0, h7=0, h8=0, h9=0, h10=0, h11=0, h12=0,
m20=0, cl=0, m1=0, m2=0, m3=0, m4=0 }
print("Mqtt Display of temperature: " .. tostring(dispTemp) )
if (dispTemp == 1) or (dispTemp == -1) then
ret.h1=1
elseif (dispTemp == 2) or (dispTemp == -2) then
ret.h2=1
elseif (dispTemp == 3) or (dispTemp == -3) then
ret.h3=1
elseif (dispTemp == 4) or (dispTemp == -4) then
ret.h4=1
elseif (dispTemp == 5) or (dispTemp == -5) then
ret.h5=1
elseif (dispTemp == 6) or (dispTemp == -6) then
ret.h6=1
elseif (dispTemp == 7) or (dispTemp == -7) then
ret.h7=1
elseif (dispTemp == 8) or (dispTemp == -8) then
ret.h8=1
elseif (dispTemp == 9) or (dispTemp == -9) then
ret.h9=1
elseif (dispTemp == 10) or (dispTemp == -10) then
ret.h10=1
elseif (dispTemp == 11) or (dispTemp == -11) then
ret.h11=1
elseif (dispTemp == 12) or (dispTemp == -12) then
ret.h12=1
else
-- over or under temperature
end
local col=string.char(128,0,0) -- red; positive degrees
if (dispTemp < 0) then
col=string.char(0,0,128) -- blue; negative degrees
end
return ret, col
else
return nil, nil
end
end
-- MQTT extension -- MQTT extension
function registerMqtt() function registerMqtt()
m = mqtt.Client("wordclock", 120) m = mqtt.Client("wordclock", 120)
@ -235,12 +186,15 @@ function startMqttClient()
if (mqttServer ~= nil and mqttPrefix ~= nil) then if (mqttServer ~= nil and mqttPrefix ~= nil) then
registerMqtt() registerMqtt()
print "Started MQTT client" print "Started MQTT client"
local dstimer = tmr.create()
dstimer:register(123, tmr.ALARM_SINGLE, function (t)
if (file.open("ds18b20_diet.lc")) then if (file.open("ds18b20_diet.lc")) then
t=require("ds18b20_diet") t=require("ds18b20_diet")
t.setup(2) -- GPIO4 t.setup(2) -- GPIO4
readTemp() -- read once, to setup chip readTemp() -- read once, to setup chip
print "Setup temperature" print "Setup temperature"
end end
end)
local oldBrightness=0 local oldBrightness=0
oldTemp=0 oldTemp=0
local mqtttimer = tmr.create() local mqtttimer = tmr.create()

View File

@ -140,9 +140,60 @@ local timestat=function (hours, minutes, longmode)
collectgarbage() collectgarbage()
return ret return ret
end end
-- Logic to display Mqtt
function temp(dw, rgbBuffer, invertRows, dispTemp)
if (dispTemp ~= nil) then
-- Values: it, is, 5 minutes, 10 minutes, afer, before, three hour, quarter, dreiviertel, half, s
-- hours: one, one Long, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve
-- Special ones: twenty, clock, minute 1 flag, minute 2 flag, minute 3 flag, minute 4 flag
local ret = { it=0, is=0, m5=0, m10=0, ha=0, hb=0, h3=0, hq=0, h3q=0, half=0, s=0,
h1=0, h1l=0, h2=0, h3=0, h4=0, h5=0, h6=0, h7=0, h8=0, h9=0, h10=0, h11=0, h12=0,
m20=0, cl=0, m1=0, m2=0, m3=0, m4=0 }
print("Mqtt Display of temperature: " .. tostring(dispTemp) )
if (dispTemp == 1) or (dispTemp == -1) then
ret.h1=1
elseif (dispTemp == 2) or (dispTemp == -2) then
ret.h2=1
elseif (dispTemp == 3) or (dispTemp == -3) then
ret.h3=1
elseif (dispTemp == 4) or (dispTemp == -4) then
ret.h4=1
elseif (dispTemp == 5) or (dispTemp == -5) then
ret.h5=1
elseif (dispTemp == 6) or (dispTemp == -6) then
ret.h6=1
elseif (dispTemp == 7) or (dispTemp == -7) then
ret.h7=1
elseif (dispTemp == 8) or (dispTemp == -8) then
ret.h8=1
elseif (dispTemp == 9) or (dispTemp == -9) then
ret.h9=1
elseif (dispTemp == 10) or (dispTemp == -10) then
ret.h10=1
elseif (dispTemp == 11) or (dispTemp == -11) then
ret.h11=1
elseif (dispTemp == 12) or (dispTemp == -12) then
ret.h12=1
else
-- over or under temperature
end
local col=string.char(128,0,0) -- red; positive degrees
if (dispTemp < 0) then
col=string.char(0,0,128) -- blue; negative degrees
end
return ret, col
else
return nil, nil
end
end
-- Pack everything into a module -- Pack everything into a module
M = { M = {
timestat = timestat timestat = timestat,
temp = temp
} }
end end
wc = M wc = M