From 7b02f1a447782e34b133db2798cea0134eb6bf27 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 13 Dec 2020 16:37:40 +0100 Subject: [PATCH] Seperate function to calculate the amount of characters to draw --- displayword.lua | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ main.lua | 10 +++----- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/displayword.lua b/displayword.lua index 04bfde2..a87c43d 100644 --- a/displayword.lua +++ b/displayword.lua @@ -305,12 +305,77 @@ if (words.fiveMin== 1) then collectgarbage() return buf 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 = { generateLEDs = generateLEDs, round = round, drawLEDs = drawLEDs, updateColor = updateColor, data = data, + countChars = countChars } end displayword = M diff --git a/main.lua b/main.lua index 81ce2c4..cd85dc3 100644 --- a/main.lua +++ b/main.lua @@ -70,16 +70,14 @@ function displayTime() local invertRows=false if ((inv46 ~= nil) and (inv46 == "on")) then 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) - end + end + local characters = displayword.countChars(words) + ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows, characters) end displayword = nil if (ledBuf ~= nil) then ws2812.write(ledBuf) - else + else if ((colorBg ~= nil) and (color ~= nil)) then ws2812.write(colorBg:rep(107) .. color:rep(3)) else