Remove display_countcharacters_de and display_countwords_de

This commit is contained in:
ollo 2019-04-20 21:39:50 +02:00
parent 902ebdb85f
commit 0aacfc2222
5 changed files with 9 additions and 170 deletions

View File

@ -1,38 +1,8 @@
-- 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 (not inverseRow) then -- nomral row
if (data.drawnCharacters < data.charsPerMinute) then
return data.colorFg
elseif (data.drawnCharacters < data.charsPerMinute*2) then
return data.colorMin1
elseif (data.drawnCharacters < data.charsPerMinute*3) then
return data.colorMin2
elseif (data.drawnCharacters > data.charsPerMinute*4) then
return data.colorMin3
elseif (data.drawnCharacters > data.charsPerMinute*5) then
return data.colorMin4
else
return data.colorFg
end
else -- inverse row
--FIXME magic missing to start on the left side
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
function updateColor(data, inverseRow)
--FIXME magic missing to start on the left side
return data.colorFg
end
function drawLEDs(data, numberNewChars, inverseRow)
@ -42,17 +12,15 @@ function drawLEDs(data, numberNewChars, inverseRow)
if (numberNewChars == nil) then
numberNewChars=0
end
--print(tostring(numberNewChars) .. " 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)
tmpBuf = updateColor(data, inverseRow)
else
tmpBuf=tmpBuf .. updateColor(data, inverseRow, numberNewChars)
tmpBuf=tmpBuf .. updateColor(data, inverseRow)
end
data.drawnCharacters=data.drawnCharacters+1
end
data.drawnWords=data.drawnWords+1
return tmpBuf
end
@ -73,7 +41,7 @@ end
briPercent=50
-- Module displaying of the words
function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4, characters)
function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4)
-- Set the local variables needed for the colored progress bar
data={}
@ -87,11 +55,10 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
elseif (words.min4 == 1) then
minutes = minutes + 4
end
data.charsPerMinute = round( (characters / minutes) )
if (adc ~= nil) then
local per = (100*adc.read(0)/1024)
briPercent = ( ((briPercent * 4) + per) / 5)
print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) .. " bright: " .. tostring(briPercent) .. "% " .. tostring(per) .. "%")
print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(briPercent) .. "% current: " .. tostring(per) .. "%")
data.colorFg = string.char(string.byte(colorForground,1) * briPercent / 100, string.byte(colorForground,2) * briPercent / 100, string.byte(colorForground,3) * briPercent / 100)
data.colorMin1 = string.char(string.byte(colorMin1,1) * briPercent / 100, string.byte(colorMin1,2) * briPercent / 100, string.byte(colorMin1,3) * briPercent / 100)
data.colorMin2 = string.char(string.byte(colorMin2,1) * briPercent / 100, string.byte(colorMin2,2) * briPercent / 100, string.byte(colorMin2,3) * briPercent / 100)
@ -99,7 +66,6 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
data.colorMin4 = string.char(string.byte(colorMin4,1) * briPercent / 100, string.byte(colorMin4,2) * briPercent / 100, string.byte(colorMin4,3) * briPercent / 100)
else
-- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars)
print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) )
data.colorFg=colorForground
data.colorMin1=colorMin1
data.colorMin2=colorMin2
@ -109,7 +75,6 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
data.words=words
data.drawnCharacters=0
data.drawnWords=0
data.amountWords=display_countwords_de(words)
local charsPerLine=11
-- Space / background has no color by default
local space=string.char(0,0,0)
@ -275,7 +240,5 @@ if (words.fiveMin== 1) then
buf= buf .. space:rep(1)
end
collectgarbage()
return buf
end

View File

@ -50,12 +50,9 @@ function displayTime()
time = getTime(sec, timezoneoffset)
words = display_timestat(time.hour, time.minute)
local charactersOfTime = display_countcharacters_de(words)
local wordsOfTime = display_countwords_de(words)
ledBuf = generateLEDs(words, color, color1, color2, color3, color4,
charactersOfTime)
ledBuf = generateLEDs(words, color, color1, color2, color3, color4)
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " in " .. charactersOfTime .. " chars " .. wordsOfTime .. " words")
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second)
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
if ((inv46 ~= nil) and (inv46 == "on")) then

View File

@ -56,7 +56,6 @@ expected.itis=1
expected.one=1
expected.clock=1
checkWords(leds, expected, 1, 0)
checkCharacter(display_countwords_de(leds), 11)
leds=display_timestat(2,5)
expected={}
@ -64,7 +63,6 @@ expected.two=1
expected.fiveMin=1
expected.after=1
checkWords(leds, expected, 2 , 5)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(3,10)
expected={}
@ -72,7 +70,6 @@ expected.three=1
expected.tenMin=1
expected.after=1
checkWords(leds, expected, 3 , 10)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(4,15)
expected={}
@ -80,7 +77,6 @@ expected.four=1
expected.after=1
expected.quater=1
checkWords(leds, expected, 4 , 15)
checkCharacter(display_countwords_de(leds), 15)
leds=display_timestat(5,20)
expected={}
@ -88,7 +84,6 @@ expected.five=1
expected.twenty=1
expected.after=1
checkWords(leds, expected, 5 , 20)
checkCharacter(display_countwords_de(leds), 15)
leds=display_timestat(6,25)
expected={}
@ -97,7 +92,6 @@ expected.fiveMin=1
expected.before=1
expected.half=1
checkWords(leds, expected, 6 , 25)
checkCharacter(display_countwords_de(leds), 17)
leds=display_timestat(7,30)
expected={}
@ -105,7 +99,6 @@ expected.itis=1
expected.eight=1
expected.half=1
checkWords(leds, expected, 7 , 30)
checkCharacter(display_countwords_de(leds), 13)
leds=display_timestat(8,35)
expected={}
@ -114,7 +107,6 @@ expected.half=1
expected.fiveMin=1
expected.after=1
checkWords(leds, expected, 8 , 35)
checkCharacter(display_countwords_de(leds), 16)
leds=display_timestat(9,40)
expected={}
@ -122,7 +114,6 @@ expected.ten=1
expected.twenty=1
expected.before=1
checkWords(leds, expected, 9 , 40)
checkCharacter(display_countwords_de(leds), 14)
leds=display_timestat(10,45)
expected={}
@ -130,7 +121,6 @@ expected.eleven=1
expected.quater=1
expected.before=1
checkWords(leds, expected, 10 , 45)
checkCharacter(display_countwords_de(leds), 13)
leds=display_timestat(11,50)
expected={}
@ -138,7 +128,6 @@ expected.twelve=1
expected.tenMin=1
expected.before=1
checkWords(leds, expected, 11 , 50)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(12,55)
expected={}
@ -146,7 +135,6 @@ expected.oneLong=1
expected.fiveMin=1
expected.before=1
checkWords(leds, expected, 12 , 55)
checkCharacter(display_countwords_de(leds), 11)
leds=display_timestat(13,00)
expected={}
@ -154,7 +142,6 @@ expected.itis=1
expected.one=1
expected.clock=1
checkWords(leds, expected, 13 , 00)
checkCharacter(display_countwords_de(leds), 11)
-- test the minutes inbetween
leds=display_timestat(14,01)
@ -164,7 +151,6 @@ expected.two=1
expected.min1=1
expected.clock=1
checkWords(leds, expected, 14 , 01)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(15,02)
expected={}
@ -173,7 +159,6 @@ expected.three=1
expected.min2=1
expected.clock=1
checkWords(leds, expected, 15 , 02)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(16,03)
expected={}
@ -182,7 +167,6 @@ expected.four=1
expected.min3=1
expected.clock=1
checkWords(leds, expected, 16 , 03)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(17,04)
expected={}
@ -191,7 +175,6 @@ expected.five=1
expected.min4=1
expected.clock=1
checkWords(leds, expected, 17 , 04)
checkCharacter(display_countwords_de(leds), 12)
leds=display_timestat(18,06)
expected={}
@ -200,7 +183,6 @@ expected.after=1
expected.min1=1
expected.six=1
checkWords(leds, expected, 18 , 06)
checkCharacter(display_countwords_de(leds), 13)
leds=display_timestat(19,09)
expected={}
@ -209,7 +191,6 @@ expected.after=1
expected.min4=1
expected.seven=1
checkWords(leds, expected, 19 , 09)
checkCharacter(display_countwords_de(leds), 14)
leds=display_timestat(20,17)
expected={}
@ -218,7 +199,6 @@ expected.after=1
expected.min2=1
expected.eight=1
checkWords(leds, expected, 20 , 17)
checkCharacter(display_countwords_de(leds), 15)

View File

@ -137,8 +137,6 @@ function stopWordclock()
getUTCtime = nil
getTime = nil
display_timestat = nil
display_countcharacters_de = nil
display_countwords_de = nil
collectgarbage()
end

View File

@ -136,102 +136,3 @@ function display_timestat(hours, minutes, longmode)
collectgarbage()
return ret
end
-- @fn display_countcharacters_de
-- Count the amount of characters, used to describe the current time in words
-- @param words the same structure, as generated with the function @see display_timestat
-- @return the amount of characters, used to describe the time or <code>0</code> on errors
function display_countcharacters_de(words)
local amount=0
if (words.it == 1) then
amount = amount + 2
end
if (words.is == 1) then
amount = amount + 3
end
if (words.fiveMin == 1) then
amount = amount + 4
end
if (words.tenMin == 1) then
amount = amount + 4
end
if (words.twenty == 1) then
amount = amount + 7
end
if (words.threequater == 1) then
amount = amount + 11
end
if (words.quater == 1) then
amount = amount + 7
end
if (words.before == 1) then
amount = amount + 3
end
if (words.after == 1) then
amount = amount + 4
end
if (words.half == 1) then
amount = amount + 4
end
if (words.twelve == 1) then
amount = amount + 5
end
if (words.seven == 1) then
amount = amount + 6
end
if (words.one == 1) then
amount = amount + 3
end
if (words.oneLong == 1) then
amount = amount + 4
end
if (words.two == 1) then
amount = amount + 4
end
if (words.three == 1) then
amount = amount + 4
end
if (words.five == 1) then
amount = amount + 4
end
if (words.four == 1) then
amount = amount + 4
end
if (words.nine == 1) then
amount = amount + 4
end
if (words.eleven == 1) then
amount = amount + 3
end
if (words.eight == 1) then
amount = amount + 4
end
if (words.ten == 1) then
amount = amount + 4
end
if (words.clock == 1) then
amount = amount + 3
end
if (words.six == 1) then
amount = amount + 5
end
return amount
end
-- @fn display_countcharacters_de
-- Count the amount of words, used to describe the current time in words!
-- (min1 to min4 are ignored)
-- @param words the same structure, as generated with the function @see display_timestat
-- @return the amount of words, used to describe the time or <code>0</code> on errors
function display_countwords_de(words)
local amount = 0
for k,v in pairs(words) do
if (v ~= nil and v == 1) then
if (k ~= "min1" and k ~= "min2" and k ~= "min3" and k ~= "min4") then
amount = amount + 1
end
end
end
return amount
end