Wordclock/init.lua

65 lines
1.9 KiB
Lua
Raw Normal View History

2017-01-03 14:07:23 +01:00
uart.setup(0, 115200, 8, 0, 1, 1 )
2016-12-14 18:37:56 +01:00
print("Autostart in 5 seconds...")
ws2812.init() -- WS2812 LEDs initialized on GPIO2
2021-02-07 17:57:58 +01:00
local MAXLEDS=110
local counter1=0
ws2812.write(string.char(0,0,0):rep(114))
local bootledtimer = tmr.create()
2021-02-05 20:58:15 +01:00
bootledtimer:register(500, tmr.ALARM_AUTO, function (t)
counter1=counter1+1
spaceLeds = math.max(MAXLEDS - (counter1*2), 0)
ws2812.write(string.char(128,0,0):rep(counter1) .. string.char(0,0,0):rep(spaceLeds) .. string.char(0,0,64):rep(counter1))
2021-02-05 21:50:02 +01:00
if ((counter1*2) > 114) then
t:unregister()
end
end)
bootledtimer:start()
function mydofile(mod)
if (file.open(mod .. ".lua")) then
dofile( mod .. ".lua")
elseif (file.open(mod .. "_diet.lua")) then
dofile(mod .. "_diet.lua")
elseif (file.open(mod .. "_diet.lc")) then
dofile(mod .. "_diet.lc")
2021-01-31 20:45:59 +01:00
elseif (file.open(mod)) then
dofile(mod)
2021-01-14 21:55:51 +01:00
else
print("NA: " .. mod)
end
end
2021-02-05 20:38:31 +01:00
initTimer = tmr.create()
2021-01-31 20:22:32 +01:00
initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
bootledtimer:unregister()
2021-02-05 20:58:15 +01:00
t:unregister()
2021-02-07 17:57:58 +01:00
initTimer=nil
bootledtimer=nil
local modlist = { "timecore" , "displayword" }
for i,mod in pairs(modlist) do
if (file.open(mod .. "_diet.lua")) then
print(tostring(i) .. ". Compile " .. mod)
ws2812.write(string.char(0,0,0):rep(11*i)..string.char(128,0,0):rep(11))
node.compile(mod .. "_diet.lua")
print("cleanup..")
file.remove(mod .. "_diet.lua")
node.restart()
return
end
end
if ( file.open("config.lua") ) then
--- Normal operation
print("Starting main")
mydofile("main")
wifi.setmode(wifi.STATION)
dofile("config.lua")
normalOperation()
2021-02-05 20:58:15 +01:00
else
-- Logic for inital setup
mydofile("webserver")
end
end)
2021-01-31 20:22:32 +01:00
initTimer:start()