diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-02 14:04:11 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-02 14:04:11 -0400 |
commit | a615d23b65291307929b2a2542b594a7dc5b8f2d (patch) | |
tree | b92fe0721c1695efb0c9c9e10ecdc0ef9afbb58e /init.lua | |
parent | 981413b1aee00dd143fdab08b4fa983f801d652e (diff) | |
download | nodeMCU_rf_source_lmx2487-a615d23b65291307929b2a2542b594a7dc5b8f2d.tar.gz nodeMCU_rf_source_lmx2487-a615d23b65291307929b2a2542b594a7dc5b8f2d.zip |
added init with possibility of aborting
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 57 |
1 files changed, 30 insertions, 27 deletions
@@ -1,30 +1,33 @@ --- Compile server code and remove original .lua files. --- This only happens the first time after the .lua files are uploaded. -local compileAndRemoveIfNeeded = function(f) - if file.open(f) then - file.close() - print('Compiling:', f) - node.compile(f) - file.remove(f) - collectgarbage() - end -end +-- allows to interrupt start up in the first 5 seconds by hitting <ENTER> +-- borrowed from https://bigdanzblog.wordpress.com/2015/04/24/esp8266-nodemcu-interrupting-init-lua-during-boot/ +function abortInit() + -- initailize abort boolean flag + abort = false + print('Press ENTER within 5 seconds to abort startup') + -- if <CR> is pressed, call abortTest + uart.on('data', '\r', abortTest, 0) + -- start timer to execute startup function in 5 seconds + tmr.create():alarm(5000,tmr.ALARM_SINGLE,startup) + end + +function abortTest(data) + -- user requested abort + abort = true + -- turns off uart scanning + uart.on('data') + end -local serverFiles = { - 'microwire.lua', - 'lmx2487lib.lua', - 'binaryLib.lua', - 'freq2lmx2487settings.lua' -} ---for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end +function startup() + uart.on('data') + -- if user requested abort, exit + if abort == true then + print('startup aborted') + return + end + -- otherwise, start up + print('in startup') + dofile('main.lua') + end -compileAndRemoveIfNeeded = nil -serverFiles = nil -collectgarbage() +tmr.create():alarm(1000,tmr.ALARM_SINGLE,abortInit) -- call abortInit after 1s - --- some diagnostic -print('chip: ',node.chipid()) -print('heap: ',node.heap()) - -dofile("main.lua") |