From b3c545be719311cf8a1d5ce035efa8c13cf3c4b5 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 1 Jun 2020 00:18:47 +0100 Subject: [PATCH] ws2812 vs gpio: down the AND gate "later" 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/init2.lua b/init2.lua index df28251..44f7527 100644 --- 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 -- 2.50.1