From: Rachael Date: Tue, 20 Feb 2018 00:41:22 +0000 (-0800) Subject: fixes shifty to not interrupt the animation when changing colors and make it support... X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=a98c99822be45cb14718f7c46c2fcfb64248e1d6;p=acmetensortoys-esp-lua_lamp fixes shifty to not interrupt the animation when changing colors and make it support two colors --- diff --git a/draw-shifty.lua b/draw-shifty.lua index f9823e5..4470972 100644 --- a/draw-shifty.lua +++ b/draw-shifty.lua @@ -1,18 +1,33 @@ return function(t,fb,p) fb:fill(0,0,0) local ix = 0 - local c = p[1] - fb:set( 2,c) fb:set( 3,c) fb:set( 6,c) fb:set( 7,c) - fb:set( 9,c) fb:set(12,c) fb:set(13,c) fb:set(16,c) - fb:set(17,c) fb:set(19,c) fb:set(20,c) fb:set(21,c) - fb:set(23,c) fb:set(24,c) fb:set(26,c) fb:set(27,c) - fb:set(30,c) fb:set(31,c) + local c, c2 + + local function drawEyes() + fb:set( 2,c) fb:set( 3,c) fb:set( 6,c) fb:set( 7,c) + fb:set( 9,c) fb:set(12,c) fb:set(13,c) fb:set(16,c) + fb:set(17,c) fb:set(19,c) fb:set(20,c) fb:set(21,c) + fb:set(23,c) fb:set(24,c) fb:set(26,c) fb:set(27,c) + fb:set(30,c) fb:set(31,c) + end + + local function reinit() + c = p[1] + c2 = p[2] or c + drawEyes() + end + reinit() + + local ft = { + [0] = function() fb:set(18,c2) fb:set(19,0,0,0) fb:set(22,c2) fb:set(23,0,0,0) end, + [1] = function() fb:set(18,0,0,0) fb:set(19,c2) fb:set(22,0,0,0) fb:set(23,c2) end + } + t:register(1000,tmr.ALARM_AUTO, function() - if ix == 1 - then fb:set(18,0,0,0) fb:set(19,c) fb:set(22,0,0,0) fb:set(23,c) - else fb:set(18,c) fb:set(19,0,0,0) fb:set(22,c) fb:set(23,0,0,0) - end + ft[ix]() ix = 1 - ix dodraw() end) + drawEyes() + return { ['ncolors'] = 2, ['cccb'] = function() reinit(); ft[ix](); dodraw() end } end