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
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
return data.colorFg
end
function drawLEDs(data, numberNewChars, inverseRow)
function M.drawLEDs(data, numberNewChars, inverseRow)
if (inverseRow == nil) then
inverseRow=false
end
@ -25,7 +30,7 @@ function drawLEDs(data, numberNewChars, inverseRow)
end
-- Utility function for round
function round(num)
function M.round(num)
under = math.floor(num)
upper = math.floor(num) + 1
underV = -(under - num)
@ -38,11 +43,11 @@ function round(num)
end
-- Initial value of percentage
briPercent=50
data={}
local briPercent=50
local data={}
-- 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
data={}

View File

@ -42,18 +42,20 @@ function syncTimeFromInternet()
end
function displayTime()
sec, usec = rtctime.get()
local sec, usec = rtctime.get()
-- Handle lazy programmer:
if (timezoneoffset == nil) then
timezoneoffset=0
end
time = getTime(sec, timezoneoffset)
words = display_timestat(time.hour, time.minute)
local time = getTime(sec, timezoneoffset)
local words = display_timestat(time.hour, time.minute)
print(package.path)
dp = require("displayword")
ledBuf = 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))
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
--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
@ -115,7 +117,7 @@ function normalOperation()
print('IP: ',wifi.sta.getip())
-- Here the WLAN is found, and something is done
print("Solving dependencies")
local dependModules = { "timecore" , "wordclock", "displayword" }
local dependModules = { "timecore" , "wordclock" }
for _,mod in pairs(dependModules) do
print("Loading " .. mod)
mydofile(mod)