Seperate function to calculate the amount of characters to draw

This commit is contained in:
Ollo 2020-12-13 16:37:40 +01:00
parent 6746d62567
commit 7b02f1a447
2 changed files with 69 additions and 6 deletions

View File

@ -305,12 +305,77 @@ if (words.fiveMin== 1) then
collectgarbage() collectgarbage()
return buf return buf
end end
-- Count amount of characters to display
local countChars = function(words)
local characters = 0
for key,value in pairs(words) do
if (value > 0) then
if (key == "it") then
characters = characters + 2
elseif (key == "is") then
characters = characters + 3
elseif (key == "fiveMin") then
characters = characters + 4
elseif (key == "tenMin") then
characters = characters + 4
elseif (key == "after") then
characters = characters + 4
elseif (key == "before") then
characters = characters + 3
elseif (key == "threeHour") then
characters = characters + 4
elseif (key == "quater") then
characters = characters + 7
elseif (key == "threequater") then
characters = characters + 11
elseif (key == "half") then
characters = characters + 4
elseif (key == "one") then
characters = characters + 3
elseif (key == "oneLong") then
characters = characters + 4
elseif (key == "two") then
characters = characters + 4
elseif (key == "three") then
characters = characters + 4
elseif (key == "four") then
characters = characters + 4
elseif (key == "five") then
characters = characters + 4
elseif (key == "six") then
characters = characters + 4
elseif (key == "seven") then
characters = characters + 6
elseif (key == "eight") then
characters = characters + 4
elseif (key == "nine") then
characters = characters + 4
elseif (key == "ten") then
characters = characters + 4
elseif (key == "eleven") then
characters = characters + 3
elseif (key == "twelve") then
characters = characters + 5
elseif (key == "twenty") then
characters = characters + 7
elseif (key == "clock") then
characters = characters + 3
elseif (key == "sr_nc") then
characters = characters + 3
end
end
end
return characters
end
M = { M = {
generateLEDs = generateLEDs, generateLEDs = generateLEDs,
round = round, round = round,
drawLEDs = drawLEDs, drawLEDs = drawLEDs,
updateColor = updateColor, updateColor = updateColor,
data = data, data = data,
countChars = countChars
} }
end end
displayword = M displayword = M

View File

@ -71,10 +71,8 @@ function displayTime()
if ((inv46 ~= nil) and (inv46 == "on")) then if ((inv46 ~= nil) and (inv46 == "on")) then
invertRows=true invertRows=true
end end
displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows) local characters = displayword.countChars(words)
if (displayword.data.drawnCharacters ~= nil) then ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows, characters)
ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows, displayword.data.drawnCharacters)
end
end end
displayword = nil displayword = nil
if (ledBuf ~= nil) then if (ledBuf ~= nil) then