From c3e48fb17a7ec4ba563963efd412bad0471604ac Mon Sep 17 00:00:00 2001 From: ollo Date: Fri, 3 May 2019 20:19:12 +0200 Subject: [PATCH] Reworked require with dofile --- displayword.lua | 24 ++++++++++++++---------- main.lua | 17 ++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/displayword.lua b/displayword.lua index 63056ae..0b446ca 100644 --- a/displayword.lua +++ b/displayword.lua @@ -1,16 +1,12 @@ -- Module filling a buffer, sent to the LEDs - -local moduleName = ... -local M = {} -- public interface -_G[moduleName] = M - - -function M.updateColor(data, inverseRow) +local M +do +local updateColor = function (data, inverseRow) --FIXME magic missing to start on the left side return data.colorFg end -function M.drawLEDs(data, numberNewChars, inverseRow) +local drawLEDs = function(data, numberNewChars, inverseRow) if (inverseRow == nil) then inverseRow=false end @@ -30,7 +26,7 @@ function M.drawLEDs(data, numberNewChars, inverseRow) end -- Utility function for round -function M.round(num) +local round = function(num) under = math.floor(num) upper = math.floor(num) + 1 underV = -(under - num) @@ -47,7 +43,7 @@ local briPercent=50 local data={} -- Module displaying of the words -function M.generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4) +local generateLEDs = function(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4) -- Set the local variables needed for the colored progress bar data={} @@ -248,3 +244,11 @@ if (words.fiveMin== 1) then collectgarbage() return buf end +M = { + generateLEDs = generateLEDs, + round = round, + drawLEDs = drawLEDs, + updateColor = updateColor, +} +end +return M \ No newline at end of file diff --git a/main.lua b/main.lua index 6f926aa..0cdeb43 100644 --- a/main.lua +++ b/main.lua @@ -50,12 +50,13 @@ function displayTime() local time = getTime(sec, timezoneoffset) local words = display_timestat(time.hour, time.minute) print(package.path) - dp = require("displayword") - - ledBuf = dp.generateLEDs(words, color, color1, color2, color3, color4) - - print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " char: " .. tostring(dp.data.drawnCharacters)) - dp = nil + dp = dofile("displayword.lc") + if (dp ~= nil) then + ledBuf = dp.generateLEDs(words, color, color1, color2, color3, color4) + print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " char: " .. tostring(dp.data.drawnCharacters)) + end + dp = nil + if (ledBuf ~= nil) then --if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here if ((inv46 ~= nil) and (inv46 == "on")) then tempstring = ledBuf:sub(1,99) -- first 33 leds @@ -72,9 +73,7 @@ function displayTime() ws2812.write(ledBuf) ledBuf=nil end - - - + end -- Used for debugging if (clockdebug ~= nil) then for key,value in pairs(words) do