]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
Wes's new and improved dimming function.
authorRachael <srbennett@gmail.com>
Mon, 1 May 2017 16:41:35 +0000 (09:41 -0700)
committerRachael <srbennett@gmail.com>
Mon, 1 May 2017 16:41:35 +0000 (09:41 -0700)
init2.lua

index 26ad9935b7dd390894c8dfe929b0e450f2d12955..11c0815a02394606eb1c245abd0b1ef6c3411edd 100644 (file)
--- a/init2.lua
+++ b/init2.lua
@@ -44,22 +44,23 @@ ledfb_claimed = 0 -- 0 : unclaimed, set remote immediately
 
 isblackout = false
 dimfactor = 0
+local baselinefb = ws2812.newBuffer(32,3)
+baselinefb:fill(1,1,1)
+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)
-        -- need to allocate two buffers, reading from one and writing to the other to allow for some pixels only being set once then dimmed into infinity and others being redrawn each frame.
-        for dimindex = 0, dimfactor do
-          g = math.floor((g+1)/2)
-          b = math.floor((b+1)/2)
-          r = math.floor((r+1)/2)
-        end
-        ledfb:set(i, g, r, b)
+        -- 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
+    else
+      ws2812.write(ledfb)
     end
-    --print(ledfb)
-    ws2812.write(ledfb)
   end
 end
 function doremotedraw()