Removed the coloring from the code

This commit is contained in:
C3MA 2018-05-02 19:52:08 +02:00
parent e01d699e8a
commit 83934efeaa

View File

@ -1,235 +1,146 @@
-- Module filling a buffer, sent to the LEDs
function updateColor(data, inverseRow, characters2draw)
if (inverseRow == nil) then
inverseRow=false
end
-- special case, and there are exactly 4 words to display (so each word for each minute)
if (data.amountWords == 4) then
print ("Amount words are " .. tostring(data.amountWords))
if (data.words.min1 == 1 and data.drawnWords == 0) then
print "Color1"
return data.colorMin1
elseif (data.words.min2 == 1 and data.drawnWords == 1) then
print "Color2"
return data.colorMin2
elseif (data.words.min3 == 1 and data.drawnWords == 2) then
print "Color3"
return data.colorMin3
elseif (data.words.min4 == 1 and data.drawnWords == 3) then
print "Color4"
return data.colorMin4
else
print "Color default"
return data.colorFg
end
else -- we must do some magic calculation FIXME the magic should be improved
if (not inverseRow) then -- nomral row
if (data.drawnCharacters < data.charsPerMinute) then
if (data.words.min1 == 1 or data.words.min2 == 1 or data.words.min3 == 1 or data.words.min4 == 1) then
return data.colorMin1
else
return data.colorFg
end
elseif (data.drawnCharacters < data.charsPerMinute*2) then
if (data.words.min2 == 1 or data.words.min3 == 1 or data.words.min4 == 1) then
return data.colorMin2
else
return data.colorFg
end
elseif (data.drawnCharacters < data.charsPerMinute*3) then
if (data.words.min3 == 1 or data.words.min4 == 1) then
return data.colorMin3
else
return data.colorFg
end
elseif (data.drawnCharacters > data.charsPerMinute*3) then
if (data.words.min4 == 1) then
return data.colorMin4
else
return data.colorFg
end
else
return data.colorFg
end
else -- inverse row
--FIXME magic missing
return data.colorFg
end
end
end
function drawLEDs(data, numberNewChars, inverseRow)
if (inverseRow == nil) then
inverseRow=false
end
print("charactes " .. tostring(data.charsPerMinute) .. " per minute; " .. tonumber(data.drawnCharacters) .. " used characters")
local tmpBuf=nil
for i=1,numberNewChars do
if (tmpBuf == nil) then
tmpBuf = updateColor(data, inverseRow, numberNewChars)
else
tmpBuf=tmpBuf .. updateColor(data, inverseRow, numberNewChars)
end
data.drawnCharacters=data.drawnCharacters+1
end
data.drawnWords=data.drawnWords+1
return tmpBuf
end
-- Module displaying of the words -- Module displaying of the words
function generateLEDs(words, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, characters) function generateLEDs(words, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, characters)
-- Set the local variables needed for the colored progress bar -- Set the local variables needed for the colored progress bar
data={} local charsPerMinute=math.floor(characters/5)
data.charsPerMinute=math.floor(characters/4) -- devide by three (Minute 1 to Minute 3, Minute 4 takes the last chars) -- Space / background has no color by default
data.words=words
data.colorFg=colorFg
data.colorMin1=colorMin1
data.colorMin2=colorMin2
data.colorMin3=colorMin3
data.colorMin4=colorMin4
data.drawnCharacters=0
data.drawnWords=0
data.amountWords=display_countwords_de(words)
local space=string.char(0,0,0) local space=string.char(0,0,0)
-- update the background color, if set -- set FG to fix value:
if (colorBg ~= nil) then colorFg = string.char(128,128,128)
space = colorBg
end
-- Set the foreground color as the default color -- Set the foreground color as the default color
local buf=colorFg local buf=colorFg
-- line 1---------------------------------------------- -- line 1----------------------------------------------
if (words.it==1) then if (words.it==1) then
buf=drawLEDs(data,2) -- ES buf=colorFg:rep(2) -- ES
else else
buf=space:rep(2) buf=space:rep(2)
end end
-- K fill character -- K fill character
buf=buf .. space:rep(1) buf=buf .. space:rep(1)
if (words.is == 1) then if (words.is == 1) then
buf=buf .. drawLEDs(data,3) -- IST buf=buf .. colorFg:rep(3) -- IST
else else
buf=buf .. space:rep(3) buf=buf .. space:rep(3)
end end
-- L fill character -- L fill character
buf=buf .. space:rep(1) buf=buf .. space:rep(1)
if (words.fiveMin== 1) then if (words.fiveMin== 1) then
buf= buf .. drawLEDs(data,4) -- FUENF buf= buf .. colorFg:rep(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 .. drawLEDs(data,7,true) -- ZWANZIG buf= buf .. colorFg:rep(7,true) -- 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 .. drawLEDs(data,4,true) -- ZEHN buf= buf .. colorFg:rep(4,true) -- 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 .. drawLEDs(data,11) -- Dreiviertel buf= buf .. colorFg:rep(11) -- Dreiviertel
elseif (words.quater == 1) then elseif (words.quater == 1) then
buf= buf .. space:rep(4) buf= buf .. space:rep(4)
buf= buf .. drawLEDs(data,7) -- VIERTEL buf= buf .. colorFg:rep(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 .. drawLEDs(data,3,true) -- VOR buf= buf .. colorFg:rep(3,true) -- 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 .. drawLEDs(data,4,true) -- NACH buf= buf .. colorFg:rep(4,true) -- 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 .. drawLEDs(data,4) -- HALB buf= buf .. colorFg:rep(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 .. drawLEDs(data,5) -- ZWOELF buf= buf .. colorFg:rep(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 .. drawLEDs(data,6,true) -- SIEBEN buf= buf .. colorFg:rep(6,true) -- 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 .. drawLEDs(data,4,true) -- EINS buf= buf .. colorFg:rep(4,true) -- 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 .. drawLEDs(data,3,true) -- EIN buf= buf .. colorFg:rep(3,true) -- 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 .. drawLEDs(data,4,true) -- ZWEI buf= buf .. colorFg:rep(4,true) -- 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 .. drawLEDs(data,4) -- DREI buf= buf .. colorFg:rep(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 .. drawLEDs(data,4) -- FUENF buf= buf .. colorFg:rep(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 .. drawLEDs(data,4,true) -- VIER buf= buf .. colorFg:rep(4,true) -- 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 .. drawLEDs(data,4,true) -- NEUN buf= buf .. colorFg:rep(4,true) -- 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 .. drawLEDs(data,3,true) -- ELEVEN buf= buf .. colorFg:rep(3,true) -- 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 .. drawLEDs(data,4) -- ACHT buf= buf .. colorFg:rep(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 .. drawLEDs(data,4) -- ZEHN buf= buf .. colorFg:rep(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 .. drawLEDs(data,3,true) -- UHR buf= buf .. colorFg:rep(3,true) -- 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 .. drawLEDs(data,5,true) -- SECHS buf= buf .. colorFg:rep(5,true) -- SECHS
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
else else
buf= buf .. space:rep(8) buf= buf .. space:rep(8)
@ -256,5 +167,8 @@ if (words.fiveMin== 1) then
buf= buf .. space:rep(1) buf= buf .. space:rep(1)
end end
collectgarbage() collectgarbage()
--FIXME function to set some color to the LEDs
return buf return buf
end end