diff --git a/displayword.lua b/displayword.lua index e751e79..6871486 100644 --- a/displayword.lua +++ b/displayword.lua @@ -1,8 +1,8 @@ -- Module displaying of the words function generateLEDs(words, color) - white=string.char(0,0,0) - buf=color + local white=string.char(0,0,0) + local buf=color -- line 1---------------------------------------------- if (words.itis == 1) then buf=color:rep(2) -- ES diff --git a/main.lua b/main.lua index b91a6b3..5295ecc 100644 --- a/main.lua +++ b/main.lua @@ -1,28 +1,52 @@ -- Main Module function startSetupMode() tmr.stop(0) - dofile("webserver.lua") + tmr.stop(1) + -- start the webserver module + mod="webserver" + if (file.open(mod .. ".lua")) then + dofile( mod .. ".lua") + else + dofile(mod .. ".lc") + end + wifi.setmode(wifi.SOFTAP) - wifi.ap.config({ssid='clock',pwd='clock'}) - print("Waiting in access point >clock< for Clients") + cfg={} + cfg.ssid="wordclock" + cfg.pwd="wordclock" + wifi.ap.config(cfg) + print("Waiting in access point >wordclock< for Clients") print("Please visit 192.168.4.1") startWebServer() end -wifi.setmode(wifi.STATION) -if ( file.list()["config.lua"] ) then - dofile("config.lua") -else - startSetupMode() +print("Solving dependencies") +dependModules = { "timecore" , "wordclock", "displayword" } +for _,mod in pairs(dependModules) do + print("Loading " .. mod) + if (file.open(mod .. ".lua")) then + dofile( mod .. ".lua") + else + dofile(mod .. ".lc") + end end -dofile("timecore.lua") -dofile("wordclock.lua") -dofile("displayword.lua") ledPin=4 -- Color is defined as GREEN, RED, BLUE color=string.char(0,0,250) +function syncTimeFromInternet() +--ptbtime1.ptb.de + sntp.sync(sntpserverhostname, + function(sec,usec,server) + print('sync', sec, usec, server) + end, + function() + print('failed!') + end + ) +end + connect_counter=0 -- Wait to be connect to the WiFi access point. tmr.alarm(0, 500, 1, function() @@ -44,15 +68,7 @@ tmr.alarm(0, 500, 1, function() startWebServer() end) - --ptbtime1.ptb.de - sntp.sync(sntpserverhostname, - function(sec,usec,server) - print('sync', sec, usec, server) - end, - function() - print('failed!') - end - ) + end -- when no wifi available, open an accesspoint and ask the user if (connect_counter == 300) then -- 300 is 30 sec in 100ms cycle @@ -87,3 +103,10 @@ tmr.alarm(1, 15000, 1 ,function() collectgarbage() end) +-- Logic +if ( file.open("config.lua") ) then + wifi.setmode(wifi.STATION) + dofile("config.lua") +else + startSetupMode() +end \ No newline at end of file diff --git a/wordclock.lua b/wordclock.lua index 4efb779..20f400a 100755 --- a/wordclock.lua +++ b/wordclock.lua @@ -23,7 +23,7 @@ function display_timestat(hours, minutes, longmode) -- transcode minutes local minutesLeds = minutes%5 - minutes=math.floor(minutes/5) + local minutes=math.floor(minutes/5) -- "It is" only display each half hour and each hour -- or if longmode is set