There is more color in the text

This commit is contained in:
ollo 2017-03-01 21:39:05 +01:00
parent f5c3064773
commit 6d3f161b09

View File

@ -1,161 +1,220 @@
-- Module displaying of the words -- Module filling a buffer, sent to the LEDs
function generateLEDs(words, color, colorMin1, colorMin2, colorMin3, colorMin4, characters)
function updateColor(data)
if (data.usedCharacters <= data.charsPerMinute) then
if (data.words.min1 == 1) then
return data.colorMin1
else
return data.colorFg
end
elseif (data.usedCharacters <= data.charsPerMinute*2) then
if (data.words.min2 == 1) then
return data.colorMin2
else
return data.colorFg
end
elseif (data.usedCharacters <= data.charsPerMinute*3) then
if (data.words.min3 == 1) then
return data.colorMin3
else
return data.colorFg
end
elseif (data.usedCharacters > data.charsPerMinute*3) then
if (data.words.min4 == 1) then
return data.colorMin4
else
return data.colorFg
end
else
return data.colorFg
end
end
function drawLEDs(data, numberNewChars)
local tmpBuf=nil
for i=1,numberNewChars do
if (tmpBuf == nil) then
tmpBuf = updateColor(data)
print("inited tmpBuf" .. tostring(tmpBuf))
else
tmpBuf=tmpBuf .. updateColor(data)
end
data.usedCharacters=data.usedCharacters+1
end
return tmpBuf
end
-- Module displaying of the words
function generateLEDs(words, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, characters)
-- Set the local variables needed for the colored progress bar
data={}
data.charsPerMinute=math.floor(characters/3) -- devide by three (Minute 1 to Minute 3, Minute 4 takes the last chars)
data.words=words
data.colorFg=colorFg
data.colorMin1=colorMin1
data.colorMin2=colorMin2
data.colorMin3=colorMin3
data.colorMin4=colorMin4
data.usedCharacters=0
local space=string.char(0,0,0) local space=string.char(0,0,0)
-- update the background color, if set -- update the background color, if set
if (colorBg ~= nil) then if (colorBg ~= nil) then
space = colorBg space = colorBg
end end
local buf=color -- Set the foreground color as the default color
local buf=colorFg
-- line 1---------------------------------------------- -- line 1----------------------------------------------
if (words.itis == 1) then if (words.itis == 1) then
buf=color:rep(2) -- ES buf=drawLEDs(data,2) -- ES
print(tostring(buf))
-- K fill character -- K fill character
buf=buf .. space:rep(1) buf=buf .. space:rep(1)
buf=buf ..color:rep(3) -- IST buf=buf .. drawLEDs(data,3) -- IST
-- L fill character -- L fill character
buf=buf .. space:rep(1) buf=buf .. space:rep(1)
else else
buf=space:rep(7) buf=space:rep(7)
end end
if (words.fiveMin== 1) then if (words.fiveMin== 1) then
buf= buf .. color:rep(4) -- FUENF buf= buf .. drawLEDs(data,4) -- FUENF
else else
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 if (words.twenty == 1) then
buf= buf .. color:rep(7) -- ZWANZIG buf= buf .. drawLEDs(data,7) -- ZWANZIG
else else
buf= buf .. space:rep(7) buf= buf .. space:rep(7)
end end
if (words.tenMin == 1) then if (words.tenMin == 1) then
buf= buf .. color:rep(4) -- ZEHN buf= buf .. drawLEDs(data,4) -- ZEHN
else else
buf= buf .. space:rep(4) buf= buf .. space:rep(4)
end end
-- line3---------------------------------------------- -- line3----------------------------------------------
if (words.threequater == 1) then if (words.threequater == 1) then
buf= buf .. color:rep(11) -- Dreiviertel buf= buf .. drawLEDs(data,11) -- Dreiviertel
elseif (words.quater == 1) then elseif (words.quater == 1) then
buf= buf .. space:rep(4) buf= buf .. space:rep(4)
buf= buf .. color:rep(7) -- VIERTEL buf= buf .. drawLEDs(data,7) -- VIERTEL
else else
buf= buf .. space:rep(11) buf= buf .. space:rep(11)
end end
--line 4-------- even row (so inverted) ------------- --line 4-------- even row (so inverted) -------------
if (words.before == 1) then if (words.before == 1) then
buf=buf .. space:rep(2) buf=buf .. space:rep(2)
buf= buf .. color:rep(3) -- VOR buf= buf .. drawLEDs(data,3) -- VOR
else else
buf= buf .. space:rep(5) buf= buf .. space:rep(5)
end end
if (words.after == 1) then if (words.after == 1) then
buf= buf .. color:rep(4) -- NACH buf= buf .. drawLEDs(data,4) -- NACH
buf= buf .. space:rep(2) -- TG buf= buf .. space:rep(2) -- TG
else else
buf= buf .. space:rep(6) buf= buf .. space:rep(6)
end end
------------------------------------------------ ------------------------------------------------
if (words.half == 1) then if (words.half == 1) then
buf= buf .. color:rep(4) -- HALB buf= buf .. drawLEDs(data,4) -- HALB
buf= buf .. space:rep(1) -- X buf= buf .. space:rep(1) -- X
else else
buf= buf .. space:rep(5) buf= buf .. space:rep(5)
end end
if (words.twelve == 1) then if (words.twelve == 1) then
buf= buf .. color:rep(5) -- ZWOELF buf= buf .. drawLEDs(data,5) -- ZWOELF
buf= buf .. space:rep(1) -- P buf= buf .. space:rep(1) -- P
else else
buf= buf .. space:rep(6) buf= buf .. space:rep(6)
end end
------------even row (so inverted) --------------------- ------------even row (so inverted) ---------------------
if (words.seven == 1) then if (words.seven == 1) then
buf= buf .. color:rep(6) -- SIEBEN buf= buf .. drawLEDs(data,6) -- SIEBEN
buf= buf .. space:rep(5) buf= buf .. space:rep(5)
elseif (words.oneLong == 1) then elseif (words.oneLong == 1) then
buf= buf .. space:rep(5) buf= buf .. space:rep(5)
buf= buf .. color:rep(4) -- EINS buf= buf .. drawLEDs(data,4) -- EINS
buf= buf .. space:rep(2) buf= buf .. space:rep(2)
elseif (words.one == 1) then elseif (words.one == 1) then
buf= buf .. space:rep(6) buf= buf .. space:rep(6)
buf= buf .. color:rep(3) -- EIN buf= buf .. drawLEDs(data,3) -- EIN
buf= buf .. space:rep(2) buf= buf .. space:rep(2)
elseif (words.two == 1) then elseif (words.two == 1) then
buf= buf .. space:rep(7) buf= buf .. space:rep(7)
buf= buf .. color:rep(4) -- ZWEI buf= buf .. drawLEDs(data,4) -- ZWEI
else else
buf= buf .. space:rep(11) buf= buf .. space:rep(11)
end end
------------------------------------------------ ------------------------------------------------
if (words.three == 1) then if (words.three == 1) then
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
buf= buf .. color:rep(4) -- DREI buf= buf .. drawLEDs(data,4) -- DREI
buf= buf .. space:rep(6) buf= buf .. space:rep(6)
elseif (words.five == 1) then elseif (words.five == 1) then
buf= buf .. space:rep(7) buf= buf .. space:rep(7)
buf= buf .. color:rep(4) -- FUENF buf= buf .. drawLEDs(data,4) -- FUENF
else else
buf= buf .. space:rep(11) buf= buf .. space:rep(11)
end end
------------even row (so inverted) --------------------- ------------even row (so inverted) ---------------------
if (words.four == 1) then if (words.four == 1) then
buf= buf .. color:rep(4) -- VIER buf= buf .. drawLEDs(data,4) -- VIER
buf= buf .. space:rep(7) buf= buf .. space:rep(7)
elseif (words.nine == 1) then elseif (words.nine == 1) then
buf= buf .. space:rep(4) buf= buf .. space:rep(4)
buf= buf .. color:rep(4) -- NEUN buf= buf .. drawLEDs(data,4) -- NEUN
buf= buf .. space:rep(3) buf= buf .. space:rep(3)
elseif (words.eleven == 1) then elseif (words.eleven == 1) then
buf= buf .. space:rep(8) buf= buf .. space:rep(8)
buf= buf .. color:rep(3) -- ELEVEN buf= buf .. drawLEDs(data,3) -- ELEVEN
else else
buf= buf .. space:rep(11) buf= buf .. space:rep(11)
end end
------------------------------------------------ ------------------------------------------------
if (words.eight == 1) then if (words.eight == 1) then
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
buf= buf .. color:rep(4) -- ACHT buf= buf .. drawLEDs(data,4) -- ACHT
buf= buf .. space:rep(6) buf= buf .. space:rep(6)
elseif (words.ten == 1) then elseif (words.ten == 1) then
buf= buf .. space:rep(5) buf= buf .. space:rep(5)
buf= buf .. color:rep(4) -- ZEHN buf= buf .. drawLEDs(data,4) -- ZEHN
buf= buf .. space:rep(2) buf= buf .. space:rep(2)
else else
buf= buf .. space:rep(11) buf= buf .. space:rep(11)
end end
------------even row (so inverted) --------------------- ------------even row (so inverted) ---------------------
if (words.clock == 1) then if (words.clock == 1) then
buf= buf .. color:rep(3) -- UHR buf= buf .. drawLEDs(data,3) -- UHR
else else
buf= buf .. space:rep(3) buf= buf .. space:rep(3)
end end
if (words.six == 1) then if (words.six == 1) then
buf= buf .. space:rep(2) buf= buf .. space:rep(2)
buf= buf .. color:rep(5) -- SECHS buf= buf .. drawLEDs(data,5) -- SECHS
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
else else
buf= buf .. space:rep(8) buf= buf .. space:rep(8)
end end
if (words.min1 == 1) then if (words.min1 == 1) then
buf= buf .. color:rep(1) buf= buf .. colorFg
else else
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
end end
if (words.min2 == 1) then if (words.min2 == 1) then
buf= buf .. color:rep(1) buf= buf .. colorFg
else else
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
end end
if (words.min3 == 1) then if (words.min3 == 1) then
buf= buf .. color:rep(1) buf= buf .. colorFg
else else
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
end end
if (words.min4 == 1) then if (words.min4 == 1) then
buf= buf .. color:rep(1) buf= buf .. colorFg
else else
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
end end