]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
ws2812 vs gpio, take 2
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Thu, 4 Jun 2020 10:31:55 +0000 (11:31 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Thu, 4 Jun 2020 10:40:05 +0000 (11:40 +0100)
Just use tmr.delay().  It's gross, but it's 350 microseconds.  We should
be OK.

init-early: here, too

blackouts: rather than have lamp-touch know what to do, push the logic
over to init2 and use the same "later" mechanism to disconnect the UART
from the LED array.

init-early.lua
init2.lua
lamp-touch.lua

index 3232176a162ef698fffdbd9ffb07d986e1a42e73..56b8ebda7f1644a601eb132d75ad0e61e306c417 100644 (file)
@@ -6,6 +6,7 @@ local fb = ws2812.newBuffer(32,3)
 fb:fill(0,0,0)
 gpio.write(3,gpio.HIGH)
 ws2812.write(fb)
+tmr.delay(350)
 gpio.write(3,gpio.LOW)
 
 -- Do we have a new LFS blob?  If so, install it.
index 44f752796f3c786193eb2a9f5db96162fb6953ae..0dc4a44d6bb88db5f82ba0b3c3bdedf2117d5dfb 100644 (file)
--- a/init2.lua
+++ b/init2.lua
@@ -35,8 +35,6 @@ 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
@@ -58,17 +56,27 @@ function dodraw()
       -- bits after summation, so adding 127 more means that we now round up
       -- (i.e., by ceil), so an active channel will remain active.
       doublefb:mix(127,baselinefb,256/(dimfactor+1),ledfb)
-      gpio.write(3,gpio.HIGH) ws2812.write(doublefb)
+      gpio.write(3,gpio.HIGH)
+      ws2812.write(doublefb)
     else
-      gpio.write(3,gpio.HIGH) ws2812.write(ledfb)
+      gpio.write(3,gpio.HIGH)
+      ws2812.write(ledfb)
     end
-    -- 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)
+    -- Wait for the UART to drain and for the LED strip to latch (nominally
+    -- 350 usec).  This isn't really OK, but we're probably not pushing the
+    -- 15 mSec or so that the SDK says we have?
+    tmr.delay(350)
+    gpio.write(3,gpio.LOW)
   end
 end
+-- Not ideal, but at least this keeps all the gpio wibbling to this one file
+function doblackout()
+  isblackout = true
+  gpio.write(3,gpio.HIGH)
+    ws2812.write(string.char(0):rep(32*3))
+    tmr.delay(350)
+  gpio.write(3,gpio.LOW)
+end
 
 function removeremote()
   local k,v
index 5ff2e02e2104bb57cb4035f362b3f61f3f414eb4..65548177a4dbd3987aff339687394b7171c9b00e 100644 (file)
@@ -1,4 +1,5 @@
--- globals referenced: isblackout, dimfactor, isDim, dodraw, ledfb, remotefb, remotetmr, lamp_announce, tq, loaddrawfn
+-- globals referenced: isblackout, doblackout, dimfactor, isDim, dodraw, ledfb, remotefb, \
+--                     remotetmr, lamp_announce, tq, loaddrawfn
 --
 -- globals asserted: touchcolor, touchlastfn
 --
@@ -48,10 +49,7 @@ local set0 = function(o) return bit.bor(o,0x01) end
 local clear0 = function(o) return bit.band(o,0xFE) end
 local function setblackout(nb)
   if nb then
-    isblackout = true
-    gpio.write(3,gpio.HIGH)
-    ws2812.write(string.char(0):rep(32*3))
-    gpio.write(3,gpio.LOW)
+    doblackout()
     cap:mr(0x81,function(o) return bit.bor(o,0x03) end) -- breathe
     cap:mr(0x74,set0) -- drive
     cap:mr(0x72,clear0) -- unlink