Seperate number and color in seperat topics: cmd/num/val and cmd/num/col

This commit is contained in:
Ollo 2022-01-23 15:15:23 +01:00
parent f30143709a
commit 158f989c53
2 changed files with 31 additions and 28 deletions

View File

@ -129,10 +129,9 @@ function registerMqtt()
print("MQTT " .. topic .. ":" .. data)
if (topic == (mqttPrefix .. "/cmd/single")) then
handleSingleCommand(client, topic, data)
elseif (topic == (mqttPrefix .. "/cmd/temp")) then
elseif (topic == (mqttPrefix .. "/cmd/num/val")) then
if (( data == "" ) or (data == nil)) then
tw=nil
tcol=nil
print("MQTT | wordclock failed")
else
-- generate the temperatur to display, once as it will not change
@ -140,13 +139,21 @@ function registerMqtt()
collectgarbage()
mydofile("wordclock")
if (wc ~= nil) then
tw, tcol = wc.temp(dw, rgbBuffer, invertRows)
tw = wc.showText(dw, rgbBuffer, invertRows, dispTemp)
wc = nil
print("MQTT | generated words for: " + tostring(dispTemp))
print("MQTT | generated words for: " .. tostring(dispTemp))
else
print("MQTT | wordclock failed")
end
end
elseif (topic == (mqttPrefix .. "/cmd/num/col")) then
-- Set number of the color to display
if (( data ~= "" ) and (data ~= nil)) then
tcol = parseBgColor(data, "num/col")
else
tcol = nil
print("MQTT | Hide number")
end
else
-- Handle here the /cmd/# sublevel
if (string.match(topic, "telnet$")) then

View File

@ -142,9 +142,9 @@ local timestat=function (hours, minutes, longmode)
end
-- Logic to display Mqtt
function temp(dw, rgbBuffer, invertRows, dispTemp)
if (dispTemp ~= nil) then
-- Logic to display number from Mqtt as text
function showText(dw, rgbBuffer, invertRows, dispNumber)
if (dispNumber ~= 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
@ -152,48 +152,44 @@ if (dispTemp ~= nil) then
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
print("Mqtt Display of temperature: " .. tostring(dispNumber) )
if (dispNumber == 1) or (dispNumber == -1) then
ret.h1=1
elseif (dispTemp == 2) or (dispTemp == -2) then
elseif (dispNumber == 2) or (dispNumber == -2) then
ret.h2=1
elseif (dispTemp == 3) or (dispTemp == -3) then
elseif (dispNumber == 3) or (dispNumber == -3) then
ret.h3=1
elseif (dispTemp == 4) or (dispTemp == -4) then
elseif (dispNumber == 4) or (dispNumber == -4) then
ret.h4=1
elseif (dispTemp == 5) or (dispTemp == -5) then
elseif (dispNumber == 5) or (dispNumber == -5) then
ret.h5=1
elseif (dispTemp == 6) or (dispTemp == -6) then
elseif (dispNumber == 6) or (dispNumber == -6) then
ret.h6=1
elseif (dispTemp == 7) or (dispTemp == -7) then
elseif (dispNumber == 7) or (dispNumber == -7) then
ret.h7=1
elseif (dispTemp == 8) or (dispTemp == -8) then
elseif (dispNumber == 8) or (dispNumber == -8) then
ret.h8=1
elseif (dispTemp == 9) or (dispTemp == -9) then
elseif (dispNumber == 9) or (dispNumber == -9) then
ret.h9=1
elseif (dispTemp == 10) or (dispTemp == -10) then
elseif (dispNumber == 10) or (dispNumber == -10) then
ret.h10=1
elseif (dispTemp == 11) or (dispTemp == -11) then
elseif (dispNumber == 11) or (dispNumber == -11) then
ret.h11=1
elseif (dispTemp == 12) or (dispTemp == -12) then
elseif (dispNumber == 12) or (dispNumber == -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
return ret
else
return nil, nil
return nil
end
end
-- Pack everything into a module
M = {
timestat = timestat,
temp = temp
showText = showText
}
end
wc = M