From: Nathaniel Wesley Filardo Date: Sat, 8 Jul 2017 23:38:14 +0000 (-0400) Subject: example/lamp: Small tweaks X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=ef93e77d47d7f0d1c81e24333b0b8b8487e63cd5;p=acmetensortoys-esp-lua_lamp example/lamp: Small tweaks Fixes doing lots of framebuffer math in a loop unnecessarily, too! --- diff --git a/README.rst b/README.rst index 024932b..bd54bd1 100644 --- a/README.rst +++ b/README.rst @@ -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 index 0000000..f540778 --- /dev/null +++ b/init-early.lua @@ -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) diff --git a/init2.lua b/init2.lua index 11c0815..04ebc41 100644 --- 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