From 2501e957764f6a982907454695df3a7f9e1ac9a2 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 5 Aug 2017 04:29:01 -0400 Subject: [PATCH] Begin deprecation of tq in favor of dyn. tmr API --- README.rst | 44 ++++++++++++++++++++++++++------------------ net/nwfmqtt.lua | 2 +- net/nwfnet-sntp.lua | 7 ------- util/ow-ds18b20.lua | 4 ++-- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/README.rst b/README.rst index 08d0953..19619d5 100644 --- a/README.rst +++ b/README.rst @@ -34,19 +34,6 @@ Generic Utilities `_ or via an existing telnet server with file overlay (see below). See the readme in ``host/`` for more. -Timer Queue ------------ - -* ``tq/tq.lua`` -- a tickless event queue wrapping around a single nodemcu - timer. Useful for managing complex lifecycles and/or many infrequent events. - Enqueue events with ``:queue(time,function,args...)``; ``:queue`` returns - a handle suitable for use with ``:dequeue()`` to unregister a pending - future event. All ESP-specific behavior is overridable by replacing - ``:now`` and ``:arm``. Use as ``tq = dofile("tq.lc")(timer)``. - -* ``tq/tq-diag.lua`` -- knows how to traverse a ``tq`` for diagnostic - utility. Use as ``dofile("tq-diag.lc")(tq,print,print)``, e.g. - Networking Utilities -------------------- @@ -95,9 +82,30 @@ cap1188 driver chip through a reset cycle. See ``examples/lamp/init2.lua`` and ``examples/lamp/lamp-touch.lua`` for usage example. -Completed Projects ------------------- +Deprecated +########## + +Timer Queue +----------- + +.. warning:: + + Now that nodemcu supports dynamic timers, this is much less interesting + unless you imagine having periods of very large numbers of events + pending, as each referenced dynamic timer holds a slot in the lua + registry, which never shrinks from its maximum occupancy. + + This module is still used within several modules here, however, for the + moment. Its removal and deprecation is being staged. + +* ``tq/tq.lua`` -- a tickless event queue wrapping around a single nodemcu + timer. Useful for managing complex lifecycles and/or many infrequent events. + Enqueue events with ``:queue(time,function,args...)``; ``:queue`` returns + a handle suitable for use with ``:dequeue()`` to unregister a pending + future event. All ESP-specific behavior is overridable by replacing + ``:now`` and ``:arm``. Use as ``tq = dofile("tq.lc")(timer)``. + +* ``tq/tq-diag.lua`` -- knows how to traverse a ``tq`` for diagnostic + utility. Use as ``dofile("tq-diag.lc")(tq,print,print)``, e.g. + -* ``examples/lamp`` -- a reimplementation of ``http://filimin.com/`` which - speaks MQTT and uses the CAP1188 chip above and Adafruit's WS2812 RGB - LEDs. diff --git a/net/nwfmqtt.lua b/net/nwfmqtt.lua index 1eeec95..7e67859 100644 --- a/net/nwfmqtt.lua +++ b/net/nwfmqtt.lua @@ -40,7 +40,7 @@ end function self.heartbeat(m,topic,tq,period) -- set up lw&t and periodically heartbeat using tq until cancelled m:lwt(topic,"dead",1,1) local handle - local function beat() mqc:publish(topic,"beat",1,1); handle = tq:queue(period, beat) end + local function beat() m:publish(topic,"beat",1,1); handle = tq:queue(period, beat) end handle = tq:queue(period,beat) return function() tq:dequeue(handle) end end diff --git a/net/nwfnet-sntp.lua b/net/nwfnet-sntp.lua index a337301..ee5b0c7 100644 --- a/net/nwfnet-sntp.lua +++ b/net/nwfnet-sntp.lua @@ -19,13 +19,6 @@ local function dosntp(server) ) end --- XXX deprecated in favor of new cron upstream module -local function loopsntp(tq,period,server) - local function f() dosntp(server); tq:queue(period,f) end - tq:queue(period,f) -end - local self = {} self.dosntp = dosntp -self.loopsntp = loopsntp return self diff --git a/util/ow-ds18b20.lua b/util/ow-ds18b20.lua index 85b1613..d4def6b 100644 --- a/util/ow-ds18b20.lua +++ b/util/ow-ds18b20.lua @@ -1,4 +1,4 @@ -return function(tq, pin, addr, power, k) +return function(pin, addr, power, k) local function doread() ow.reset(pin) ow.select(pin, addr) @@ -16,5 +16,5 @@ return function(tq, pin, addr, power, k) ow.reset(pin) ow.select(pin, addr) ow.write(pin, 0x44, power) - tq:queue(1000,doread) + tmr.create():alarm(1000,tmr.ALARM_SINGLE,doread) end -- 2.50.1