summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-02 14:04:11 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-02 14:04:11 -0400
commita615d23b65291307929b2a2542b594a7dc5b8f2d (patch)
treeb92fe0721c1695efb0c9c9e10ecdc0ef9afbb58e
parent981413b1aee00dd143fdab08b4fa983f801d652e (diff)
downloadnodeMCU_rf_source_lmx2487-a615d23b65291307929b2a2542b594a7dc5b8f2d.tar.gz
nodeMCU_rf_source_lmx2487-a615d23b65291307929b2a2542b594a7dc5b8f2d.zip
added init with possibility of aborting
-rw-r--r--init.lua57
-rw-r--r--init.old.lua30
-rw-r--r--main.lua5
3 files changed, 65 insertions, 27 deletions
diff --git a/init.lua b/init.lua
index 34c744e..25a33aa 100644
--- a/init.lua
+++ b/init.lua
@@ -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")
diff --git a/init.old.lua b/init.old.lua
new file mode 100644
index 0000000..34c744e
--- /dev/null
+++ b/init.old.lua
@@ -0,0 +1,30 @@
+-- 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
+
+local serverFiles = {
+ 'microwire.lua',
+ 'lmx2487lib.lua',
+ 'binaryLib.lua',
+ 'freq2lmx2487settings.lua'
+}
+--for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end
+
+compileAndRemoveIfNeeded = nil
+serverFiles = nil
+collectgarbage()
+
+
+-- some diagnostic
+print('chip: ',node.chipid())
+print('heap: ',node.heap())
+
+dofile("main.lua")
diff --git a/main.lua b/main.lua
index 0d22c58..3ba8113 100644
--- a/main.lua
+++ b/main.lua
@@ -3,6 +3,11 @@ Eugeniy Mikhailov
1 June 2021
]]
+startup=nil
+abortTest=nil
+abortInit=nil
+
+
dofile("binaryLib.lua")
dofile("microwire.lua")
dofile("lmx2487lib.lua")