Display one color after the other
This commit is contained in:
		@@ -2,8 +2,30 @@
 | 
			
		||||
local M
 | 
			
		||||
do
 | 
			
		||||
local updateColor = function (data)
 | 
			
		||||
    --FIXME magic missing to start on the left side
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								main.lua
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								main.lua
									
									
									
									
									
								
							@@ -64,9 +64,11 @@ function displayTime()
 | 
			
		||||
            invertRows=true
 | 
			
		||||
        end 
 | 
			
		||||
        displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows)
 | 
			
		||||
	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
 | 
			
		||||
     	  ws2812.write(ledBuf)
 | 
			
		||||
@@ -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. 
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user