Refactoring line generation

This commit is contained in:
ollo 2019-05-10 22:58:42 +02:00
parent a36dc8d033
commit 32106035c2

View File

@ -6,10 +6,7 @@ local updateColor = function (data, inverseRow)
return data.colorFg return data.colorFg
end end
local drawLEDs = function(data, numberNewChars, inverseRow) local drawLEDs = function(data, numberNewChars)
if (inverseRow == nil) then
inverseRow=false
end
if (numberNewChars == nil) then if (numberNewChars == nil) then
numberNewChars=0 numberNewChars=0
end end
@ -87,7 +84,7 @@ local generateLEDs = function(words, colorForground, colorMin1, colorMin2, color
-- Set the foreground color as the default color -- Set the foreground color as the default color
local buf=colorFg local buf=colorFg
local line=space
-- line 1---------------------------------------------- -- line 1----------------------------------------------
if (words.it==1) then if (words.it==1) then
buf=drawLEDs(data,2) -- ES buf=drawLEDs(data,2) -- ES
@ -109,120 +106,145 @@ if (words.fiveMin== 1) then
buf= buf .. space:rep(4) buf= buf .. space:rep(4)
end end
-- line 2-- even row (so inverted) -------------------- -- line 2-- even row (so inverted) --------------------
if (words.twenty == 1) then
buf= buf .. drawLEDs(data,7,true) -- ZWANZIG
else
buf= buf .. space:rep(7)
end
if (words.tenMin == 1) then if (words.tenMin == 1) then
buf= buf .. drawLEDs(data,4,true) -- ZEHN line= drawLEDs(data,4) -- ZEHN
else else
buf= buf .. space:rep(4) line= space:rep(4)
end end
if (words.twenty == 1) then
line= line .. drawLEDs(data,7) -- ZWANZIG
else
line= line .. space:rep(7)
end
-- fill, the buffer
for i = 0,10 do
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
end
-- line3---------------------------------------------- -- line3----------------------------------------------
if (words.threequater == 1) then if (words.threequater == 1) then
buf= buf .. drawLEDs(data,11) -- Dreiviertel line= drawLEDs(data,11) -- Dreiviertel
elseif (words.quater == 1) then elseif (words.quater == 1) then
buf= buf .. space:rep(4) line= space:rep(4)
buf= buf .. drawLEDs(data,7) -- VIERTEL line= line .. drawLEDs(data,7) -- VIERTEL
else else
buf= buf .. space:rep(11) line= space:rep(11)
end end
-- fill, the buffer
buf = buf .. line
--line 4-------- even row (so inverted) ------------- --line 4-------- even row (so inverted) -------------
if (words.before == 1) then
buf=buf .. space:rep(2)
buf= buf .. drawLEDs(data,3,true) -- VOR
else
buf= buf .. space:rep(5)
end
if (words.after == 1) then if (words.after == 1) then
buf= buf .. drawLEDs(data,4,true) -- NACH line= line .. space:rep(2) -- TG
buf= buf .. space:rep(2) -- TG line= drawLEDs(data,4) -- NACH
else else
buf= buf .. space:rep(6) line= space:rep(6)
end
if (words.before == 1) then
line= line .. drawLEDs(data,3) -- VOR
line= line .. space:rep(2)
else
line= line .. space:rep(5)
end
for i = 0,10 do
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
end end
------------------------------------------------ ------------------------------------------------
if (words.half == 1) then if (words.half == 1) then
buf= buf .. drawLEDs(data,4) -- HALB line= drawLEDs(data,4) -- HALB
buf= buf .. space:rep(1) -- X line= line .. space:rep(1) -- X
else else
buf= buf .. space:rep(5) line= space:rep(5)
end end
if (words.twelve == 1) then if (words.twelve == 1) then
buf= buf .. drawLEDs(data,5) -- ZWOELF line= line .. drawLEDs(data,5) -- ZWOELF
buf= buf .. space:rep(1) -- P line= line .. space:rep(1) -- P
else else
buf= buf .. space:rep(6) line= line .. space:rep(6)
end end
buf=buf .. line
------------even row (so inverted) --------------------- ------------even row (so inverted) ---------------------
if (words.seven == 1) then if (words.seven == 1) then
buf= buf .. drawLEDs(data,6,true) -- SIEBEN line= space:rep(5)
buf= buf .. space:rep(5) line= line .. drawLEDs(data,6) -- SIEBEN
elseif (words.oneLong == 1) then elseif (words.oneLong == 1) then
buf= buf .. space:rep(5) line= space:rep(2)
buf= buf .. drawLEDs(data,4,true) -- EINS line= line .. drawLEDs(data,4) -- EINS
buf= buf .. space:rep(2) line= line .. space:rep(5)
elseif (words.one == 1) then elseif (words.one == 1) then
buf= buf .. space:rep(6) line= space:rep(2)
buf= buf .. drawLEDs(data,3,true) -- EIN line= line .. drawLEDs(data,3) -- EIN
buf= buf .. space:rep(2) line= line .. space:rep(6)
elseif (words.two == 1) then elseif (words.two == 1) then
buf= buf .. space:rep(7) line= drawLEDs(data,4) -- ZWEI
buf= buf .. drawLEDs(data,4,true) -- ZWEI line= line .. space:rep(7)
else else
buf= buf .. space:rep(11) line= space:rep(11)
end
for i = 0,10 do
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
end end
------------------------------------------------ ------------------------------------------------
if (words.three == 1) then if (words.three == 1) then
buf= buf .. space:rep(1) line= space:rep(1)
buf= buf .. drawLEDs(data,4) -- DREI line= line .. drawLEDs(data,4) -- DREI
buf= buf .. space:rep(6) line= line .. space:rep(6)
elseif (words.five == 1) then elseif (words.five == 1) then
buf= buf .. space:rep(7) line= space:rep(7)
buf= buf .. drawLEDs(data,4) -- FUENF line= line .. drawLEDs(data,4) -- FUENF
else else
buf= buf .. space:rep(11) line= space:rep(11)
end end
buf = buf .. line
------------even row (so inverted) --------------------- ------------even row (so inverted) ---------------------
if (words.four == 1) then if (words.four == 1) then
buf= buf .. drawLEDs(data,4,true) -- VIER line= space:rep(7)
buf= buf .. space:rep(7) line= line .. drawLEDs(data,4) -- VIER
elseif (words.nine == 1) then elseif (words.nine == 1) then
buf= buf .. space:rep(4) line= space:rep(3)
buf= buf .. drawLEDs(data,4,true) -- NEUN line= line .. drawLEDs(data,4) -- NEUN
buf= buf .. space:rep(3) line= line .. space:rep(4)
elseif (words.eleven == 1) then elseif (words.eleven == 1) then
buf= buf .. space:rep(8) line= drawLEDs(data,3) -- ELEVEN
buf= buf .. drawLEDs(data,3,true) -- ELEVEN line= line .. space:rep(8)
else else
buf= buf .. space:rep(11) line= space:rep(11)
end
for i = 0,10 do
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
end end
------------------------------------------------ ------------------------------------------------
if (words.eight == 1) then if (words.eight == 1) then
buf= buf .. space:rep(1) line= space:rep(1)
buf= buf .. drawLEDs(data,4) -- ACHT line= line .. drawLEDs(data,4) -- ACHT
buf= buf .. space:rep(6) line= line .. space:rep(6)
elseif (words.ten == 1) then elseif (words.ten == 1) then
buf= buf .. space:rep(5) line= space:rep(5)
buf= buf .. drawLEDs(data,4) -- ZEHN line= line .. drawLEDs(data,4) -- ZEHN
buf= buf .. space:rep(2) line= line .. space:rep(2)
else else
buf= buf .. space:rep(11) line= space:rep(11)
end end
buf = buf .. line
------------even row (so inverted) --------------------- ------------even row (so inverted) ---------------------
if (words.clock == 1) then
buf= buf .. drawLEDs(data,3,true) -- UHR
else
buf= buf .. space:rep(3)
end
if (words.six == 1) then if (words.six == 1) then
buf= buf .. space:rep(2) line= space:rep(1)
buf= buf .. drawLEDs(data,5,true) -- SECHS line= line .. drawLEDs(data,5) -- SECHS
buf= buf .. space:rep(1) line= line .. space:rep(2)
else else
buf= buf .. space:rep(8) line= space:rep(8)
end end
if (words.clock == 1) then
line= line .. drawLEDs(data,3) -- UHR
else
line= line .. space:rep(3)
end
for i = 0,10 do
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
end
------ Minutes -----------
if (words.min1 == 1) then if (words.min1 == 1) then
buf= buf .. colorFg buf= buf .. colorFg
else else