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 countChars = countChars
} }
end end
displayword = M dw = M

View File

@ -1,7 +1,5 @@
-- Main Module -- Main Module
local looptimer = tmr.create() local looptimer = tmr.create()
displayword = {}
rowbgColor= {} rowbgColor= {}
function syncTimeFromInternet() function syncTimeFromInternet()
@ -13,7 +11,7 @@ function syncTimeFromInternet()
syncRunning=nil syncRunning=nil
end, end,
function() function()
print('failed!') print('NTP failed!')
syncRunning=nil syncRunning=nil
end end
) )
@ -27,8 +25,16 @@ function displayTime()
if (timezoneoffset == nil) then if (timezoneoffset == nil) then
timezoneoffset=0 timezoneoffset=0
end end
local time = getTime(sec, timezoneoffset) mydofile("timecore")
local words = display_timestat(time.hour, time.minute) 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 if ((dim ~= nil) and (dim == "on")) then
words.briPer=briPer words.briPer=briPer
if (words.briPer ~= nil and words.briPer < 3) then if (words.briPer ~= nil and words.briPer < 3) then
@ -37,17 +43,21 @@ function displayTime()
else else
words.briPer=nil words.briPer=nil
end end
end
wc = nil
collectgarbage()
print("Heap: " .. tostring(node.heap()))
mydofile("displayword") mydofile("displayword")
if (displayword ~= nil) then if (dw ~= nil) then
--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
local invertRows=false local invertRows=false
if ((inv46 ~= nil) and (inv46 == "on")) then if ((inv46 ~= nil) and (inv46 == "on")) then
invertRows=true invertRows=true
end end
local characters = displayword.countChars(words) local c = dw.countChars(words)
ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters) ledBuf = dw.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, c)
end end
displayword = nil dw = nil
if (ledBuf ~= nil) then if (ledBuf ~= nil) then
ws2812.write(ledBuf) ws2812.write(ledBuf)
else else
@ -114,12 +124,7 @@ function normalOperation()
t:unregister() t:unregister()
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") mydofile("mqtt")
local dependModules = { "timecore" , "wordclock", "mqtt" }
for _,mod in pairs(dependModules) do
print("Loading " .. mod)
mydofile(mod)
end
local setupCounter=5 local setupCounter=5
local alive=0 local alive=0

View File

@ -1,3 +1,6 @@
local M
do
--Summer winter time convertion --Summer winter time convertion
--See: https://arduinodiy.wordpress.com/2015/10/13/the-arduino-and-daylight-saving-time/ --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) -- @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>true</code> if we have currently summer time
-- @return <code>false</code> if we have winter 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 -- we are in 100% in the summer time
if (time.month > 3 and time.month < 10) then if (time.month > 3 and time.month < 10) then
return true return true
@ -103,7 +106,7 @@ local yearsize = function(year)
end end
end end
function getUTCtime(unixtimestmp) local function getUTCtime(unixtimestmp)
local year = EPOCH_YR local year = EPOCH_YR
local dayclock = math.floor(unixtimestmp % SECS_DAY) local dayclock = math.floor(unixtimestmp % SECS_DAY)
local dayno = math.floor(unixtimestmp / SECS_DAY) local dayno = math.floor(unixtimestmp / SECS_DAY)
@ -131,10 +134,16 @@ function getUTCtime(unixtimestmp)
end end
function getTime(unixtimestmp, timezoneoffset) local getTime = function(unixtimestmp, timezoneoffset)
local time = getUTCtime(unixtimestmp + (3600 * timezoneoffset)) local time = getUTCtime(unixtimestmp + (3600 * timezoneoffset))
if ( isSummerTime(time) ) then if ( isSummerTime(time) ) then
time = getUTCtime(unixtimestmp + (3600 * (timezoneoffset + 1)) ) time = getUTCtime(unixtimestmp + (3600 * (timezoneoffset + 1)) )
end end
return time return time
end 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 -- Revese engeeniered code of display_wc_ger.c by Vlad Tepesch
-- See https://www.mikrocontroller.net/articles/Word_cl_Variante_1#Download -- 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 -- Return the leds to use the granuality is 5 minutes
-- @param hours the current hours (0-23) -- @param hours the current hours (0-23)
-- @param minutes the current minute (0-59) -- @param minutes the current minute (0-59)
-- @param longmode (optional parameter) 0: no long mode, 1: long mode (itis will be set) -- @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 if (longmode == nil) then
longmode=0 longmode=0
end end
@ -138,3 +140,9 @@ function display_timestat(hours, minutes, longmode)
collectgarbage() collectgarbage()
return ret return ret
end end
-- Pack everything into a module
M = {
timestat = timestat
}
end
wc = M