From 3cfe91d859e7e205226ea9ecf0bb353e1f48c416 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Tue, 8 Jan 2019 19:39:07 +0000 Subject: [PATCH] init: switch to OO tmr interface We now assume exclusively the use of OO timers, so always use the "t:alarm(...)" form rather than "tmr.alarm(t, ...)". --- init.lua | 14 +++++++++----- telnetd/readme.rst | 2 +- tq/tq.lua | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index aeeb3b1..3566ecf 100644 --- a/init.lua +++ b/init.lua @@ -42,6 +42,9 @@ if rtctime then rtctime.set(0) end -- set time to 0 until someone corrects us local ie = OVL["init-early"] if ie then ie() end +local gotmr = tmr.create() +got = gotmr + local function goab() OVL["nwfnet-diag"]()(true) OVL["diag"]() @@ -50,7 +53,7 @@ local function goab() tcpserv:listen(23,function(k) local telnetd = OVL["telnetd"]() telnetd.on["conn"] = function(s) - tmr.unregister(6) + if gotmr then gotmr:stop() ; gotmr = nil end s(string.format("NODE-%06X RECOVERY (auto reboot cancelled)",node.chipid())) end telnetd.server(k) @@ -62,19 +65,20 @@ local function goi2() end local function waitFLASH() local function stop_() - gpio.mode(3,gpio.INPUT); gpio.trig(3); tmr.unregister(6) + gpio.mode(3,gpio.INPUT); gpio.trig(3) + gotmr:stop(); got = nil; gotmr = nil stop = nil; go = nil end function stop() stop_(); goab() end function go() print("Continuing boot..."); stop_(); goi2() end print("Reset delay! Bounce GPIO3 low or type 'stop()' to stop autoboot, or 'go()' to go...") gpio.mode(3,gpio.INT,gpio.PULLUP) - tmr.alarm(6,8000,tmr.ALARM_SINGLE,go) + gotmr:alarm(8000,tmr.ALARM_SINGLE,go) gpio.trig(3,"low",function(_) print("Aborting..."); stop() end) end local function bootPANIC() - print("Panic! Lingering for a minute with telnet console up; 'tmr.unregister(6)' to persist...") - tmr.alarm(6,60000,tmr.ALARM_SINGLE,node.restart) + print("Panic! Lingering for a minute with telnet console up; 'got:stop()' to persist...") + gotmr:alarm(60000,tmr.ALARM_SINGLE,node.restart) goab() end local bct = { diff --git a/telnetd/readme.rst b/telnetd/readme.rst index 0a237d6..38aa441 100644 --- a/telnetd/readme.rst +++ b/telnetd/readme.rst @@ -43,4 +43,4 @@ Some useful commands Schedule a reboot of the node "soon"; we need to give the ESP stack enough time to write back the prompt, or we risk racing and panic-ing the stack:: - diag exec tmr.alarm(tmr.create(), 1000, tmr.ALARM_SINGLE, node.restart) + diag exec tmr.create():alarm(1000, tmr.ALARM_SINGLE, node.restart) diff --git a/tq/tq.lua b/tq/tq.lua index 55c5e35..bce15c4 100644 --- a/tq/tq.lua +++ b/tq/tq.lua @@ -70,7 +70,7 @@ local function dequeue(self,what) end end end local function defl_arm(self,t) - tmr.alarm(self.tmr, t, tmr.ALARM_SINGLE, function() self:fire() end) + self.tmr:alarm(t, tmr.ALARM_SINGLE, function() self:fire() end) end return function(tmrix) return { _q = {}, _tst = 0, -- 2.50.1