Wordclock/init.lua

86 lines
2.5 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()
2022-01-23 15:14:04 +01:00
bootledtimer:register(75, tmr.ALARM_AUTO, function (timer)
counter1=counter1+1
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
end)
bootledtimer:start()
function mydofile(mod)
2022-12-09 22:19:27 +01:00
print("load:" .. 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()
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" }
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")
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
2022-12-09 22:32:40 +01:00
collectgarbage()
wifi.setmode(wifi.SOFTAP)
cfg={}
cfg.ssid="wordclock"
cfg.pwd="wordclock"
wifi.ap.config(cfg)
-- Write the buffer to the LEDs
local color=string.char(0,128,0)
local white=string.char(0,0,0)
local ledBuf= white:rep(6) .. color .. white:rep(7) .. color:rep(3) .. white:rep(44) .. color:rep(3) .. white:rep(50)
ws2812.write(ledBuf)
color=nil
white=nil
ledBuf=nil
print("Waiting in access point >wordclock< for Clients")
print("Please visit 192.168.4.1")
-- start the webserver module
mydofile("webserver")
end
end)
2021-01-31 20:22:32 +01:00
initTimer:start()