From 91c0a1521217c0d9f74bb4670f3c296b9b1f2824 Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 22 May 2019 21:25:33 +0200 Subject: [PATCH] Display one color after the other --- displayword.lua | 37 +++++++++++++++++++++++++++++-------- main.lua | 7 +++++-- simulation/config.lua | 15 +++++++-------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/displayword.lua b/displayword.lua index 714b74c..93c8eaf 100644 --- a/displayword.lua +++ b/displayword.lua @@ -2,8 +2,30 @@ local M do local updateColor = function (data) - --FIXME magic missing to start on the left side - return data.colorFg + if (data.amountOfChars > 0) then + local div = tonumber(data.drawnCharacters/data.amountOfChars) + if (div < 1) then + print(tostring(data.drawnCharacters) .. " blocks: " .. tostring(data.amountOfChars) .. " FG " .. tostring(string.byte(data.colorFg,1)) .. "x" .. tostring(string.byte(data.colorFg,2)) .. "x" .. tostring(string.byte(data.colorFg,3)) ) + return data.colorFg + elseif (div < 2) then + print(tostring(data.drawnCharacters) .. " blocks: " .. tostring(data.amountOfChars) .. " C1") + return data.colorMin1 + elseif (div < 3) then + print(tostring(data.drawnCharacters) .. " blocks: " .. tostring(data.amountOfChars) .. " C2") + return data.colorMin2 + elseif (div < 4) then + print(tostring(data.drawnCharacters) .. " blocks: " .. tostring(data.amountOfChars) .. " C3") + return data.colorMin3 + elseif (div < 5) then + print(tostring(data.drawnCharacters) .. " blocks: " .. tostring(data.amountOfChars) .. " C4") + return data.colorMin4 + else + print(tostring(data.drawnCharacters) .. " blocks: " .. tostring(data.amountOfChars) .. " ELSE") + return data.colorFg + end + else + return data.colorFg + end end local drawLEDs = function(data, numberNewChars) @@ -38,7 +60,7 @@ end local data={} -- Module displaying of the words -local generateLEDs = function(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars) +local generateLEDs = function(words, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars) -- Set the local variables needed for the colored progress bar if (words == nil) then return nil @@ -47,7 +69,7 @@ local generateLEDs = function(words, colorForground, colorMin1, colorMin2, color invertRows=false end - local minutes=0 + local minutes=1 if (words.min1 == 1) then minutes = minutes + 1 elseif (words.min2 == 1) then @@ -58,13 +80,12 @@ local generateLEDs = function(words, colorForground, colorMin1, colorMin2, color minutes = minutes + 4 end -- always set a foreground value - local colorFg = string.char(255,255,255) - if (colorForground ~= nil) then - colorFg = colorForground + if (colorFg == nil) then + colorFg = string.char(255,255,255) end if (amountOfChars ~= nil) then - data.amountOfChars = amountOfChars + data.amountOfChars = amountOfChars/minutes else data.amountOfChars = 0 end diff --git a/main.lua b/main.lua index b230fb8..928bd81 100644 --- a/main.lua +++ b/main.lua @@ -64,8 +64,10 @@ function displayTime() invertRows=true end displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows) - ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows, displayword.data.drawnCharacters) - print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " char: " .. tostring(displayword.data.drawnCharacters)) + if (displayword.data.drawnCharacters ~= nil) then + ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows, displayword.data.drawnCharacters) + print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " char: " .. tostring(displayword.data.drawnCharacters)) + end end displayword = nil if (ledBuf ~= nil) then @@ -101,6 +103,7 @@ function normalOperation() -- Color is defined as GREEN, RED, BLUE color=string.char(0,0,250) end + print("Fg Color: " .. tostring(string.byte(color,1)) .. "x" .. tostring(string.byte(color,2)) .. "x" .. tostring(string.byte(color,3)) ) connect_counter=0 -- Wait to be connect to the WiFi access point. diff --git a/simulation/config.lua b/simulation/config.lua index 7c38a41..c6b8f5e 100644 --- a/simulation/config.lua +++ b/simulation/config.lua @@ -1,13 +1,12 @@ -green=0 -green2=128 +green2=200 red=128 -blue=0 +blue=200 -color=string.char(0, 0, 128) -color1=string.char(128, 0, 0) -color2=string.char(tonumber(green2*0.8), 0, 0) -color3=string.char(tonumber(green2*0.4), 0, 0) -color4=string.char(tonumber(green2*0.2), 0, 0) +color=string.char(0, 0, blue) +color1=string.char(red, 0, 0) +color2=string.char(tonumber(red*0.8), 0, 0) +color3=string.char(0, tonumber(green2*0.4), 0) +color4=string.char(0,0 ,tonumber(blue*0.2)) colorBg=string.char(0,0,0) -- black is the default background color sntpserverhostname="ptbtime1.ptb.de"