Changed architecture of lua modules

This commit is contained in:
Ollo 2021-02-11 21:23:32 +01:00
parent 407ea2d2fa
commit bb1aaa32a6
4 changed files with 53 additions and 31 deletions

View File

@ -448,4 +448,4 @@ M = {
countChars = countChars
}
end
displayword = M
dw = M

View File

@ -1,7 +1,5 @@
-- Main Module
local looptimer = tmr.create()
displayword = {}
rowbgColor= {}
function syncTimeFromInternet()
@ -13,7 +11,7 @@ function syncTimeFromInternet()
syncRunning=nil
end,
function()
print('failed!')
print('NTP failed!')
syncRunning=nil
end
)
@ -27,8 +25,16 @@ function displayTime()
if (timezoneoffset == nil) then
timezoneoffset=0
end
local time = getTime(sec, timezoneoffset)
local words = display_timestat(time.hour, time.minute)
mydofile("timecore")
if (tc == nil) then
return
end
local time = tc.getTime(sec, timezoneoffset)
tc = nil
collectgarbage()
mydofile("wordclock")
if (wc ~= nil) then
local words = wc.timestat(time.hour, time.minute)
if ((dim ~= nil) and (dim == "on")) then
words.briPer=briPer
if (words.briPer ~= nil and words.briPer < 3) then
@ -37,17 +43,21 @@ function displayTime()
else
words.briPer=nil
end
end
wc = nil
collectgarbage()
print("Heap: " .. tostring(node.heap()))
mydofile("displayword")
if (displayword ~= nil) then
if (dw ~= nil) then
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
local invertRows=false
if ((inv46 ~= nil) and (inv46 == "on")) then
invertRows=true
end
local characters = displayword.countChars(words)
ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters)
local c = dw.countChars(words)
ledBuf = dw.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, c)
end
displayword = nil
dw = nil
if (ledBuf ~= nil) then
ws2812.write(ledBuf)
else
@ -114,12 +124,7 @@ function normalOperation()
t:unregister()
print('IP: ',wifi.sta.getip())
-- Here the WLAN is found, and something is done
print("Solving dependencies")
local dependModules = { "timecore" , "wordclock", "mqtt" }
for _,mod in pairs(dependModules) do
print("Loading " .. mod)
mydofile(mod)
end
mydofile("mqtt")
local setupCounter=5
local alive=0

View File

@ -1,3 +1,6 @@
local M
do
--Summer winter time convertion
--See: https://arduinodiy.wordpress.com/2015/10/13/the-arduino-and-daylight-saving-time/
--
@ -27,7 +30,7 @@
-- @var dow Current day of week range (1 - 7) (1 is Monday, 7 is Sunday)
-- @return <code>true</code> if we have currently summer time
-- @return <code>false</code> if we have winter time
function isSummerTime(time)
local function isSummerTime(time)
-- we are in 100% in the summer time
if (time.month > 3 and time.month < 10) then
return true
@ -103,7 +106,7 @@ local yearsize = function(year)
end
end
function getUTCtime(unixtimestmp)
local function getUTCtime(unixtimestmp)
local year = EPOCH_YR
local dayclock = math.floor(unixtimestmp % SECS_DAY)
local dayno = math.floor(unixtimestmp / SECS_DAY)
@ -131,10 +134,16 @@ function getUTCtime(unixtimestmp)
end
function getTime(unixtimestmp, timezoneoffset)
local getTime = function(unixtimestmp, timezoneoffset)
local time = getUTCtime(unixtimestmp + (3600 * timezoneoffset))
if ( isSummerTime(time) ) then
time = getUTCtime(unixtimestmp + (3600 * (timezoneoffset + 1)) )
end
return time
end
-- Pack everything into a module
M = {
getTime = getTime
}
end
tc = M

View File

@ -1,12 +1,14 @@
-- Revese engeeniered code of display_wc_ger.c by Vlad Tepesch
-- See https://www.mikrocontroller.net/articles/Word_cl_Variante_1#Download
local M
do
-- @fn display_timestat
-- @fn wc_timestat
-- Return the leds to use the granuality is 5 minutes
-- @param hours the current hours (0-23)
-- @param minutes the current minute (0-59)
-- @param longmode (optional parameter) 0: no long mode, 1: long mode (itis will be set)
function display_timestat(hours, minutes, longmode)
local timestat=function (hours, minutes, longmode)
if (longmode == nil) then
longmode=0
end
@ -138,3 +140,9 @@ function display_timestat(hours, minutes, longmode)
collectgarbage()
return ret
end
-- Pack everything into a module
M = {
timestat = timestat
}
end
wc = M