]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
ws2812 vs gpio: down the AND gate "later"
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 31 May 2020 23:18:47 +0000 (00:18 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 31 May 2020 23:18:47 +0000 (00:18 +0100)
Right now, the ws2812 driver doesn't wait for the bit stream to return
control to Lua, so rather than immediately kick the AND gate off, set up
a timer to do it "soon".  This is not really the right fix, since it
leaves the AND gate high for a long while, but it works well enough I
suppose.

init2.lua

index df282518ad4af8d2e656d8ee59b5b9fd44e96f33..44f752796f3c786193eb2a9f5db96162fb6953ae 100644 (file)
--- a/init2.lua
+++ b/init2.lua
@@ -35,6 +35,8 @@ end)
 ws2812.init(ws2812.MODE_SINGLE)     -- uses GPIO2
 i2c.setup(0,2,1,i2c.SLOW)           -- init i2c as per silk screen (GPIO4, GPIO5)
 
+local inhtmr = tmr.create()
+
 -- and now we get to the lamp stuff
 remotefb = ws2812.newBuffer(32,3)
 ledfb = remotefb -- points at whichever buffer is appropriate to draw
@@ -60,7 +62,11 @@ function dodraw()
     else
       gpio.write(3,gpio.HIGH) ws2812.write(ledfb)
     end
-    gpio.write(3,gpio.LOW)
+    -- Kick the inhibit timer to turn off the AND gate in 2 msec.  That should
+    -- be ample time to drain the serial UART.  If we get here again, we'll end
+    -- up resetting the timer's firing time, making this something like a
+    -- watchdog.  Hopefully we won't crash in the interim.
+    inhtmr:alarm(2,tmr.ALARM_SINGLE,function() gpio.write(3,gpio.LOW) end)
   end
 end