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

View File

@ -142,9 +142,9 @@ local timestat=function (hours, minutes, longmode)
end end
-- Logic to display Mqtt -- Logic to display number from Mqtt as text
function temp(dw, rgbBuffer, invertRows, dispTemp) function showText(dw, rgbBuffer, invertRows, dispNumber)
if (dispTemp ~= nil) then if (dispNumber ~= nil) then
-- Values: it, is, 5 minutes, 10 minutes, afer, before, three hour, quarter, dreiviertel, half, s -- 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 -- 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 -- 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, 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 } m20=0, cl=0, m1=0, m2=0, m3=0, m4=0 }
print("Mqtt Display of temperature: " .. tostring(dispTemp) ) print("Mqtt Display of temperature: " .. tostring(dispNumber) )
if (dispTemp == 1) or (dispTemp == -1) then if (dispNumber == 1) or (dispNumber == -1) then
ret.h1=1 ret.h1=1
elseif (dispTemp == 2) or (dispTemp == -2) then elseif (dispNumber == 2) or (dispNumber == -2) then
ret.h2=1 ret.h2=1
elseif (dispTemp == 3) or (dispTemp == -3) then elseif (dispNumber == 3) or (dispNumber == -3) then
ret.h3=1 ret.h3=1
elseif (dispTemp == 4) or (dispTemp == -4) then elseif (dispNumber == 4) or (dispNumber == -4) then
ret.h4=1 ret.h4=1
elseif (dispTemp == 5) or (dispTemp == -5) then elseif (dispNumber == 5) or (dispNumber == -5) then
ret.h5=1 ret.h5=1
elseif (dispTemp == 6) or (dispTemp == -6) then elseif (dispNumber == 6) or (dispNumber == -6) then
ret.h6=1 ret.h6=1
elseif (dispTemp == 7) or (dispTemp == -7) then elseif (dispNumber == 7) or (dispNumber == -7) then
ret.h7=1 ret.h7=1
elseif (dispTemp == 8) or (dispTemp == -8) then elseif (dispNumber == 8) or (dispNumber == -8) then
ret.h8=1 ret.h8=1
elseif (dispTemp == 9) or (dispTemp == -9) then elseif (dispNumber == 9) or (dispNumber == -9) then
ret.h9=1 ret.h9=1
elseif (dispTemp == 10) or (dispTemp == -10) then elseif (dispNumber == 10) or (dispNumber == -10) then
ret.h10=1 ret.h10=1
elseif (dispTemp == 11) or (dispTemp == -11) then elseif (dispNumber == 11) or (dispNumber == -11) then
ret.h11=1 ret.h11=1
elseif (dispTemp == 12) or (dispTemp == -12) then elseif (dispNumber == 12) or (dispNumber == -12) then
ret.h12=1 ret.h12=1
else else
-- over or under temperature -- over or under temperature
end end
local col=string.char(128,0,0) -- red; positive degrees return ret
if (dispTemp < 0) then
col=string.char(0,0,128) -- blue; negative degrees
end
return ret, col
else else
return nil, nil return nil
end end
end end
-- Pack everything into a module -- Pack everything into a module
M = { M = {
timestat = timestat, timestat = timestat,
temp = temp showText = showText
} }
end end
wc = M wc = M