From 83934efeaa9593de1c669ef5dac054a3f0a8a1c1 Mon Sep 17 00:00:00 2001 From: C3MA Date: Wed, 2 May 2018 19:52:08 +0200 Subject: [PATCH 1/4] Removed the coloring from the code --- displayword.lua | 148 ++++++++++-------------------------------------- 1 file changed, 31 insertions(+), 117 deletions(-) diff --git a/displayword.lua b/displayword.lua index a9722fd..129d0a7 100644 --- a/displayword.lua +++ b/displayword.lua @@ -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 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/4) -- 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.drawnCharacters=0 - data.drawnWords=0 - data.amountWords=display_countwords_de(words) + local charsPerMinute=math.floor(characters/5) + -- Space / background has no color by default local space=string.char(0,0,0) - -- update the background color, if set - if (colorBg ~= nil) then - space = colorBg - end + -- set FG to fix value: + colorFg = string.char(128,128,128) -- Set the foreground color as the default color local buf=colorFg -- line 1---------------------------------------------- if (words.it==1) then - buf=drawLEDs(data,2) -- ES + buf=colorFg:rep(2) -- ES else buf=space:rep(2) end -- K fill character buf=buf .. space:rep(1) if (words.is == 1) then - buf=buf .. drawLEDs(data,3) -- IST + buf=buf .. colorFg:rep(3) -- IST else buf=buf .. space:rep(3) end -- L fill character buf=buf .. space:rep(1) if (words.fiveMin== 1) then - buf= buf .. drawLEDs(data,4) -- FUENF + buf= buf .. colorFg:rep(4) -- FUENF else buf= buf .. space:rep(4) end -- line 2-- even row (so inverted) -------------------- if (words.twenty == 1) then - buf= buf .. drawLEDs(data,7,true) -- ZWANZIG + buf= buf .. colorFg:rep(7,true) -- ZWANZIG else buf= buf .. space:rep(7) end if (words.tenMin == 1) then - buf= buf .. drawLEDs(data,4,true) -- ZEHN + buf= buf .. colorFg:rep(4,true) -- ZEHN else buf= buf .. space:rep(4) end -- line3---------------------------------------------- if (words.threequater == 1) then - buf= buf .. drawLEDs(data,11) -- Dreiviertel + buf= buf .. colorFg:rep(11) -- Dreiviertel elseif (words.quater == 1) then buf= buf .. space:rep(4) - buf= buf .. drawLEDs(data,7) -- VIERTEL + buf= buf .. colorFg:rep(7) -- VIERTEL else buf= buf .. space:rep(11) end --line 4-------- even row (so inverted) ------------- if (words.before == 1) then buf=buf .. space:rep(2) - buf= buf .. drawLEDs(data,3,true) -- VOR + buf= buf .. colorFg:rep(3,true) -- VOR else buf= buf .. space:rep(5) end 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 else buf= buf .. space:rep(6) end ------------------------------------------------ if (words.half == 1) then - buf= buf .. drawLEDs(data,4) -- HALB + buf= buf .. colorFg:rep(4) -- HALB buf= buf .. space:rep(1) -- X else buf= buf .. space:rep(5) end if (words.twelve == 1) then - buf= buf .. drawLEDs(data,5) -- ZWOELF + buf= buf .. colorFg:rep(5) -- ZWOELF buf= buf .. space:rep(1) -- P else buf= buf .. space:rep(6) end ------------even row (so inverted) --------------------- if (words.seven == 1) then - buf= buf .. drawLEDs(data,6,true) -- SIEBEN + buf= buf .. colorFg:rep(6,true) -- SIEBEN buf= buf .. space:rep(5) elseif (words.oneLong == 1) then buf= buf .. space:rep(5) - buf= buf .. drawLEDs(data,4,true) -- EINS + buf= buf .. colorFg:rep(4,true) -- EINS buf= buf .. space:rep(2) elseif (words.one == 1) then buf= buf .. space:rep(6) - buf= buf .. drawLEDs(data,3,true) -- EIN + buf= buf .. colorFg:rep(3,true) -- EIN buf= buf .. space:rep(2) elseif (words.two == 1) then buf= buf .. space:rep(7) - buf= buf .. drawLEDs(data,4,true) -- ZWEI + buf= buf .. colorFg:rep(4,true) -- ZWEI else buf= buf .. space:rep(11) end ------------------------------------------------ if (words.three == 1) then buf= buf .. space:rep(1) - buf= buf .. drawLEDs(data,4) -- DREI + buf= buf .. colorFg:rep(4) -- DREI buf= buf .. space:rep(6) elseif (words.five == 1) then buf= buf .. space:rep(7) - buf= buf .. drawLEDs(data,4) -- FUENF + buf= buf .. colorFg:rep(4) -- FUENF else buf= buf .. space:rep(11) end ------------even row (so inverted) --------------------- if (words.four == 1) then - buf= buf .. drawLEDs(data,4,true) -- VIER + buf= buf .. colorFg:rep(4,true) -- VIER buf= buf .. space:rep(7) elseif (words.nine == 1) then buf= buf .. space:rep(4) - buf= buf .. drawLEDs(data,4,true) -- NEUN + buf= buf .. colorFg:rep(4,true) -- NEUN buf= buf .. space:rep(3) elseif (words.eleven == 1) then buf= buf .. space:rep(8) - buf= buf .. drawLEDs(data,3,true) -- ELEVEN + buf= buf .. colorFg:rep(3,true) -- ELEVEN else buf= buf .. space:rep(11) end ------------------------------------------------ if (words.eight == 1) then buf= buf .. space:rep(1) - buf= buf .. drawLEDs(data,4) -- ACHT + buf= buf .. colorFg:rep(4) -- ACHT buf= buf .. space:rep(6) elseif (words.ten == 1) then buf= buf .. space:rep(5) - buf= buf .. drawLEDs(data,4) -- ZEHN + buf= buf .. colorFg:rep(4) -- ZEHN buf= buf .. space:rep(2) else buf= buf .. space:rep(11) end ------------even row (so inverted) --------------------- if (words.clock == 1) then - buf= buf .. drawLEDs(data,3,true) -- UHR + buf= buf .. colorFg:rep(3,true) -- UHR else buf= buf .. space:rep(3) end if (words.six == 1) then buf= buf .. space:rep(2) - buf= buf .. drawLEDs(data,5,true) -- SECHS + buf= buf .. colorFg:rep(5,true) -- SECHS buf= buf .. space:rep(1) else buf= buf .. space:rep(8) @@ -256,5 +167,8 @@ if (words.fiveMin== 1) then buf= buf .. space:rep(1) end collectgarbage() + + --FIXME function to set some color to the LEDs + return buf end From c9924f4a22e29be278f102fc8dc92ec82c314013 Mon Sep 17 00:00:00 2001 From: C3MA Date: Wed, 2 May 2018 20:40:20 +0200 Subject: [PATCH 2/4] Color and characters seperated --- displayword.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/displayword.lua b/displayword.lua index 129d0a7..2c1fa5c 100644 --- a/displayword.lua +++ b/displayword.lua @@ -1,12 +1,13 @@ -- Module displaying of the words -function generateLEDs(words, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, characters) +function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4, characters) -- Set the local variables needed for the colored progress bar local charsPerMinute=math.floor(characters/5) + local charsPerLine=11 -- Space / background has no color by default local space=string.char(0,0,0) -- set FG to fix value: - colorFg = string.char(128,128,128) + colorFg = string.char(255,255,255) -- Set the foreground color as the default color local buf=colorFg @@ -168,7 +169,25 @@ if (words.fiveMin== 1) then end collectgarbage() - --FIXME function to set some color to the LEDs + local bufColored = string.char() + --function to set some color to the LEDs + for x=0,9 do + for y=0, (charsPerLine-1) do + local start = ((x * charsPerLine) + y)*3 + 1 + item=string.byte(buf, start) + -- Color + if (item > 0) then + bufColored = bufColored .. colorForground + else + -- 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)) + end + end + collectgarbage() - return buf + return bufColored end From 3f8abd30bfe21acb279cc6375b219c25bd50ecd1 Mon Sep 17 00:00:00 2001 From: C3MA Date: Wed, 2 May 2018 21:03:43 +0200 Subject: [PATCH 3/4] Handle 4 words differently --- displayword.lua | 35 +++++++++++++++++++++++++++++++++-- simulation/config.lua | 6 +++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/displayword.lua b/displayword.lua index 2c1fa5c..d69babb 100644 --- a/displayword.lua +++ b/displayword.lua @@ -171,14 +171,45 @@ if (words.fiveMin== 1) then local bufColored = string.char() --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 + -- Color the visible words if (item > 0) then - bufColored = bufColored .. colorForground + 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 diff --git a/simulation/config.lua b/simulation/config.lua index ed91742..ece2ce3 100644 --- a/simulation/config.lua +++ b/simulation/config.lua @@ -4,9 +4,9 @@ red=128 blue=0 color=string.char(green, red, blue) -color1=string.char(tonumber(green2*0.8), red, blue) -color2=string.char(tonumber(green2*0.8), red, blue) -color3=string.char(tonumber(green2*0.8), red, blue) +color1=string.char(tonumber(green2*0.2), red, blue) +color2=string.char(tonumber(green2*0.4), red, blue) +color3=string.char(tonumber(green2*0.6), red, blue) color4=string.char(tonumber(green2*0.8), red, blue) colorBg=string.char(0,0,0) -- black is the default background color From 08b0a9372ba32b7fa300ffd82a844983508af1c1 Mon Sep 17 00:00:00 2001 From: C3MA Date: Wed, 2 May 2018 21:13:44 +0200 Subject: [PATCH 4/4] Include current word into debug line --- displayword.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/displayword.lua b/displayword.lua index d69babb..f1ba630 100644 --- a/displayword.lua +++ b/displayword.lua @@ -215,7 +215,7 @@ if (words.fiveMin== 1) then bufColored = bufColored .. colorBg end end - print (x .. "x" .. y .. " : " .. start .. " color " .. tostring(item) .. " len " .. string.len(buf)) + print (x .. "x" .. y .. " : " .. start .. " color " .. tostring(item) .. " len " .. string.len(buf) .. " word " .. tostring(word)) end end collectgarbage()