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...")
|
2016-06-19 17:04:30 +02:00
|
|
|
|
2016-07-03 18:41:32 +02:00
|
|
|
ws2812.init() -- WS2812 LEDs initialized on GPIO2
|
2021-02-07 17:57:58 +01:00
|
|
|
local MAXLEDS=110
|
|
|
|
local counter1=0
|
2016-07-03 18:41:32 +02:00
|
|
|
ws2812.write(string.char(0,0,0):rep(114))
|
2021-01-31 20:41:03 +01:00
|
|
|
local bootledtimer = tmr.create()
|
2022-01-23 15:14:04 +01:00
|
|
|
bootledtimer:register(75, tmr.ALARM_AUTO, function (timer)
|
2016-06-19 17:04:30 +02:00
|
|
|
counter1=counter1+1
|
2017-12-29 21:47:23 +01:00
|
|
|
spaceLeds = math.max(MAXLEDS - (counter1*2), 0)
|
2021-12-04 13:07:29 +01:00
|
|
|
ws2812.write(string.char(16,0,0):rep(counter1) .. string.char(0,0,0):rep(spaceLeds) .. string.char(0,0,8):rep(counter1))
|
2021-02-05 21:50:02 +01:00
|
|
|
if ((counter1*2) > 114) then
|
2022-01-23 15:14:04 +01:00
|
|
|
timer:unregister()
|
2021-02-05 21:50:02 +01:00
|
|
|
end
|
2016-06-19 17:04:30 +02:00
|
|
|
end)
|
2021-01-31 20:41:03 +01:00
|
|
|
bootledtimer:start()
|
2016-06-19 17:04:30 +02:00
|
|
|
|
|
|
|
function mydofile(mod)
|
2022-12-09 22:19:27 +01:00
|
|
|
print("load:" .. mod)
|
2016-06-19 17:04:30 +02:00
|
|
|
if (file.open(mod .. ".lua")) then
|
|
|
|
dofile( mod .. ".lua")
|
2021-02-07 17:51:57 +01:00
|
|
|
elseif (file.open(mod .. "_diet.lua")) then
|
|
|
|
dofile(mod .. "_diet.lua")
|
2021-02-11 22:14:04 +01:00
|
|
|
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
|
2021-02-11 22:14:04 +01:00
|
|
|
print("NA: " .. mod)
|
2016-06-19 17:04:30 +02:00
|
|
|
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)
|
2021-01-31 20:41:03 +01:00
|
|
|
bootledtimer:unregister()
|
2021-03-17 21:52:44 +01:00
|
|
|
initTimer:unregister()
|
2021-02-07 17:57:58 +01:00
|
|
|
initTimer=nil
|
|
|
|
bootledtimer=nil
|
2022-12-09 22:19:27 +01:00
|
|
|
local modlist = { "timecore" , "displayword", "ds18b20", "mqtt", "main", "webserver" }
|
2021-02-11 22:14:04 +01:00
|
|
|
for i,mod in pairs(modlist) do
|
|
|
|
if (file.open(mod .. "_diet.lua")) then
|
2021-03-21 20:37:53 +01:00
|
|
|
file.remove(mod .. "_diet.lc")
|
2021-02-11 22:14:04 +01:00
|
|
|
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
|
|
|
|
|
2021-02-08 19:18:55 +01:00
|
|
|
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
|
2021-02-08 19:18:55 +01:00
|
|
|
-- Logic for inital setup
|
|
|
|
mydofile("webserver")
|
2016-06-19 17:04:30 +02:00
|
|
|
end
|
|
|
|
end)
|
2021-01-31 20:22:32 +01:00
|
|
|
initTimer:start()
|