]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
example/lamp: Small tweaks
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 8 Jul 2017 23:38:14 +0000 (19:38 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 8 Jul 2017 23:38:14 +0000 (19:38 -0400)
Fixes doing lots of framebuffer math in a loop unnecessarily, too!

README.rst
init-early.lua [new file with mode: 0644]
init2.lua

index 024932bbee6aee99240d2229248b849fb67e795f..bd54bd1869c8afde30b4fde1728009aa4a0caf51 100644 (file)
@@ -93,7 +93,7 @@ expected to *return a function* which takes, in order,
   drawing function returns and will be stopped when appropriate by the rest
   of the system.
 
-* a ws2812 framebuffer object into which all drwaing should happen.  This
+* a ws2812 framebuffer object into which all drawing should happen.  This
   framebuffer should be closed over in any timer callbacks.
 
 * a color parameter, expressed as three arguments 0-255: green, red, blue
diff --git a/init-early.lua b/init-early.lua
new file mode 100644 (file)
index 0000000..f540778
--- /dev/null
@@ -0,0 +1,4 @@
+ws2812.init(ws2812.MODE_SINGLE)     -- uses GPIO2
+local fb = ws2812.newBuffer(32,3)
+fb:fill(0,0,0)
+ws2812.write(fb)
index 11c0815a02394606eb1c245abd0b1ef6c3411edd..04ebc417f8235581db171c55a483965e72d0de54 100644 (file)
--- a/init2.lua
+++ b/init2.lua
@@ -50,14 +50,11 @@ local doublefb = ws2812.newBuffer(32,3)
 function dodraw()
   if not isblackout then
     if dimfactor > 0 then
-      for i=1, ledfb:size() do
-        local g,r,b = ledfb:get(i)
-        -- dimming, so mix the baseline "all channels on minimum" as 128/256ths
-        -- to act as a rounding factor.  The image in "ledfb" will be mixed in
-        -- as 256/(dimfactor+1) 256ths
-        doublefb:mix(128,baselinefb,256/(dimfactor+1),ledfb)
-        ws2812.write(doublefb)
-      end
+      -- dimming, so mix the baseline "all channels on minimum" as 255/256ths
+      -- to act as a rounding factor.  The image in "ledfb" will be mixed in
+      -- as 256/(dimfactor+1) 256ths
+      doublefb:mix(255,baselinefb,256/(dimfactor+1),ledfb)
+      ws2812.write(doublefb)
     else
       ws2812.write(ledfb)
     end