diff --git a/displayword.lua b/displayword.lua
index bf5303f..558697e 100644
--- a/displayword.lua
+++ b/displayword.lua
@@ -448,4 +448,4 @@ M = {
countChars = countChars
}
end
-displayword = M
+dw = M
diff --git a/main.lua b/main.lua
index b637e5e..36aeec0 100644
--- a/main.lua
+++ b/main.lua
@@ -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,27 +25,39 @@ function displayTime()
if (timezoneoffset == nil) then
timezoneoffset=0
end
- local time = getTime(sec, timezoneoffset)
- local words = display_timestat(time.hour, time.minute)
- if ((dim ~= nil) and (dim == "on")) then
- words.briPer=briPer
- if (words.briPer ~= nil and words.briPer < 3) then
- words.briPer=3
- end
- else
- words.briPer=nil
+ 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
+ words.briPer=3
+ end
+ 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
@@ -146,10 +151,10 @@ function normalOperation()
elseif ( (alive % 120) == 0) then
-- sync the time every 5 minutes
syncTimeFromInternet()
- alive = alive + 1
+ alive = alive + 1
else
- displayTime()
- alive = alive + 1
+ displayTime()
+ alive = alive + 1
end
collectgarbage()
-- Feed the system watchdog.
diff --git a/timecore.lua b/timecore.lua
index 4983a15..e7bb36c 100755
--- a/timecore.lua
+++ b/timecore.lua
@@ -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 true
if we have currently summer time
-- @return false
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
diff --git a/wordclock.lua b/wordclock.lua
index b71c206..11be758 100755
--- a/wordclock.lua
+++ b/wordclock.lua
@@ -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