reworked displayword into module

This commit is contained in:
ollo 2019-04-27 18:34:57 +02:00
parent ab37d28904
commit 97de5dbb78
2 changed files with 20 additions and 13 deletions

View File

@ -1,11 +1,16 @@
-- Module filling a buffer, sent to the LEDs -- Module filling a buffer, sent to the LEDs
function updateColor(data, inverseRow) local moduleName = ...
local M = {} -- public interface
_G[moduleName] = M
function M.updateColor(data, inverseRow)
--FIXME magic missing to start on the left side --FIXME magic missing to start on the left side
return data.colorFg return data.colorFg
end end
function drawLEDs(data, numberNewChars, inverseRow) function M.drawLEDs(data, numberNewChars, inverseRow)
if (inverseRow == nil) then if (inverseRow == nil) then
inverseRow=false inverseRow=false
end end
@ -25,7 +30,7 @@ function drawLEDs(data, numberNewChars, inverseRow)
end end
-- Utility function for round -- Utility function for round
function round(num) function M.round(num)
under = math.floor(num) under = math.floor(num)
upper = math.floor(num) + 1 upper = math.floor(num) + 1
underV = -(under - num) underV = -(under - num)
@ -38,11 +43,11 @@ function round(num)
end end
-- Initial value of percentage -- Initial value of percentage
briPercent=50 local briPercent=50
data={} local data={}
-- Module displaying of the words -- Module displaying of the words
function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4) function M.generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4)
-- Set the local variables needed for the colored progress bar -- Set the local variables needed for the colored progress bar
data={} data={}

View File

@ -42,18 +42,20 @@ function syncTimeFromInternet()
end end
function displayTime() function displayTime()
sec, usec = rtctime.get() local sec, usec = rtctime.get()
-- Handle lazy programmer: -- Handle lazy programmer:
if (timezoneoffset == nil) then if (timezoneoffset == nil) then
timezoneoffset=0 timezoneoffset=0
end end
time = getTime(sec, timezoneoffset) local time = getTime(sec, timezoneoffset)
words = display_timestat(time.hour, time.minute) local words = display_timestat(time.hour, time.minute)
print(package.path)
dp = require("displayword")
ledBuf = generateLEDs(words, color, color1, color2, color3, color4) 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(data.drawnCharacters))
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " char: " .. tostring(dp.data.drawnCharacters))
dp = nil
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here --if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
if ((inv46 ~= nil) and (inv46 == "on")) then if ((inv46 ~= nil) and (inv46 == "on")) then
tempstring = ledBuf:sub(1,99) -- first 33 leds tempstring = ledBuf:sub(1,99) -- first 33 leds
@ -115,7 +117,7 @@ function normalOperation()
print('IP: ',wifi.sta.getip()) print('IP: ',wifi.sta.getip())
-- Here the WLAN is found, and something is done -- Here the WLAN is found, and something is done
print("Solving dependencies") print("Solving dependencies")
local dependModules = { "timecore" , "wordclock", "displayword" } local dependModules = { "timecore" , "wordclock" }
for _,mod in pairs(dependModules) do for _,mod in pairs(dependModules) do
print("Loading " .. mod) print("Loading " .. mod)
mydofile(mod) mydofile(mod)