Color is again set

This commit is contained in:
ollo 2018-12-27 14:25:51 +01:00
parent 613cf39086
commit 9aa94b3372

View File

@ -6,36 +6,32 @@ function updateColor(data, inverseRow, characters2draw)
end end
-- special case, and there are exactly 4 words to display (so each word for each minute) -- special case, and there are exactly 4 words to display (so each word for each minute)
if (not inverseRow) then -- nomral row if (not inverseRow) then -- nomral row
if (data.drawnCharacters < data.charsPerMinute) then 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.colorFg
return data.colorMin1
else
return data.colorFg
end
elseif (data.drawnCharacters < data.charsPerMinute*2) then 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.colorMin1
return data.colorMin2
else
return data.colorFg
end
elseif (data.drawnCharacters < data.charsPerMinute*3) then elseif (data.drawnCharacters < data.charsPerMinute*3) then
if (data.words.min3 == 1 or data.words.min4 == 1) then return data.colorMin2
return data.colorMin3 elseif (data.drawnCharacters > data.charsPerMinute*4) then
else return data.colorMin3
return data.colorFg elseif (data.drawnCharacters > data.charsPerMinute*5) then
end return data.colorMin4
elseif (data.drawnCharacters > data.charsPerMinute*3) then
if (data.words.min4 == 1) then
return data.colorMin4
else
return data.colorFg
end
else else
return data.colorFg return data.colorFg
end end
else -- inverse row else -- inverse row
--FIXME magic missing --FIXME magic missing to start on the left side
return data.colorFg if (data.drawnCharacters < data.charsPerMinute) then
return data.colorMin1
elseif (data.drawnCharacters < data.charsPerMinute*2) then
return data.colorMin2
elseif (data.drawnCharacters < data.charsPerMinute*3) then
return data.colorMin3
elseif (data.drawnCharacters > data.charsPerMinute*4) then
return data.colorMin4
else
return data.colorFg
end
end end
end end
@ -43,7 +39,10 @@ function drawLEDs(data, numberNewChars, inverseRow)
if (inverseRow == nil) then if (inverseRow == nil) then
inverseRow=false inverseRow=false
end end
print("charactes " .. tostring(data.charsPerMinute) .. " per minute; " .. tonumber(data.drawnCharacters) .. " used characters") if (numberNewChars == nil) then
numberNewChars=0
end
print(tostring(numberNewChars) .. " charactes " .. tostring(data.charsPerMinute) .. " per minute; " .. tonumber(data.drawnCharacters) .. " used characters")
local tmpBuf=nil local tmpBuf=nil
for i=1,numberNewChars do for i=1,numberNewChars do
if (tmpBuf == nil) then if (tmpBuf == nil) then
@ -72,12 +71,11 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
elseif (words.min4 == 1) then elseif (words.min4 == 1) then
minutes = minutes + 4 minutes = minutes + 4
end end
print("Minutes : " .. tostring(minutes) )
-- data.charsPerMinute=characters - math.floor(characters / minutes) * minutes -- modulo
data.charsPerMinute = math.ceil(characters / minutes) data.charsPerMinute = math.ceil(characters / minutes)
-- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars) -- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars)
print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) )
data.words=words data.words=words
data.colorFg=colorFg data.colorFg=colorForground
data.colorMin1=colorMin1 data.colorMin1=colorMin1
data.colorMin2=colorMin2 data.colorMin2=colorMin2
data.colorMin3=colorMin3 data.colorMin3=colorMin3
@ -96,134 +94,134 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
-- line 1---------------------------------------------- -- line 1----------------------------------------------
if (words.it==1) then if (words.it==1) then
buf=colorFg:rep(2) -- ES buf=drawLEDs(data,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 .. colorFg:rep(3) -- IST buf=buf .. drawLEDs(data,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 .. colorFg: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 .. colorFg:rep(7,true) -- ZWANZIG buf= buf .. drawLEDs(data,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 .. colorFg:rep(4,true) -- ZEHN buf= buf .. drawLEDs(data,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 .. colorFg: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 .. colorFg: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 .. colorFg:rep(3,true) -- VOR buf= buf .. drawLEDs(data,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 .. colorFg:rep(4,true) -- NACH buf= buf .. drawLEDs(data,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 .. colorFg: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 .. colorFg: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 .. colorFg:rep(6,true) -- SIEBEN buf= buf .. drawLEDs(data,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 .. colorFg:rep(4,true) -- EINS buf= buf .. drawLEDs(data,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 .. colorFg:rep(3,true) -- EIN buf= buf .. drawLEDs(data,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 .. colorFg:rep(4,true) -- ZWEI buf= buf .. drawLEDs(data,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 .. colorFg: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 .. colorFg: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 .. colorFg:rep(4,true) -- VIER buf= buf .. drawLEDs(data,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 .. colorFg:rep(4,true) -- NEUN buf= buf .. drawLEDs(data,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 .. colorFg:rep(3,true) -- ELEVEN buf= buf .. drawLEDs(data,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 .. colorFg: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 .. colorFg: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 .. colorFg:rep(3,true) -- UHR buf= buf .. drawLEDs(data,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 .. colorFg:rep(5,true) -- SECHS buf= buf .. drawLEDs(data,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)
@ -251,56 +249,6 @@ if (words.fiveMin== 1) then
end end
collectgarbage() collectgarbage()
local bufColored = string.char() return buf
--function to set some color to the LEDs
local word=0
local firstCharAfterSpace=true
for x=0,9 do
for y=0, (charsPerLine-1) do
local start = ((x * charsPerLine) + y)*3 + 1
item=string.byte(buf, start)
-- Color the visible words
if (item > 0) then
if (firstCharAfterSpace == true) then
word = word + 1
end
firstCharAfterSpace=false
if (characters == 4) then -- we have a word for each minute to color differently
if (words.min4 == 1 and word == 4) then
bufColored = bufColored .. colorMin4
elseif (words.min3 == 1 and word == 3) then
bufColored = bufColored .. colorMin3
elseif (words.min2 == 1 and word == 2) then
bufColored = bufColored .. colorMin2
elseif (words.min1 == 1 and word == 1) then
bufColored = bufColored .. colorMin1
else
bufColored = bufColored .. colorForground
end
else -- FIXME some more magic should be added here
if (words.min4 == 1) then
bufColored = bufColored .. colorMin4
elseif (words.min3 == 1) then
bufColored = bufColored .. colorMin3
elseif (words.min2 == 1) then
bufColored = bufColored .. colorMin2
elseif (words.min1 == 1) then
bufColored = bufColored .. colorMin1
else
bufColored = bufColored .. colorForground
end
end
else
firstCharAfterSpace=true
-- update the background color, if set
if (colorBg ~= nil) then
bufColored = bufColored .. colorBg
end
end
print (x .. "x" .. y .. " : " .. start .. " color " .. tostring(item) .. " len " .. string.len(buf) .. " word " .. tostring(word))
end
end
collectgarbage()
return bufColored
end end