From: Rachael Date: Sun, 14 May 2017 00:22:56 +0000 (-0700) Subject: adds the un-dimming feature to the dimming feature X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=69515006a62344e57da8ff630df1f8ab32723a1c;p=acmetensortoys-esp-lua_lamp adds the un-dimming feature to the dimming feature --- diff --git a/init2.lua b/init2.lua index 11c0815..2b8633a 100644 --- a/init2.lua +++ b/init2.lua @@ -43,6 +43,7 @@ ledfb_claimed = 0 -- 0 : unclaimed, set remote immediately -- 2 : claimed locally but remote has changed isblackout = false +isDim = true dimfactor = 0 local baselinefb = ws2812.newBuffer(32,3) baselinefb:fill(1,1,1) @@ -55,7 +56,7 @@ function dodraw() -- 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) + doublefb:mix(256,baselinefb,256/(dimfactor+1),ledfb) ws2812.write(doublefb) end else diff --git a/lamp-touch.lua b/lamp-touch.lua index b66294b..79354cd 100644 --- a/lamp-touch.lua +++ b/lamp-touch.lua @@ -1,4 +1,4 @@ --- globals referenced: isblackout, dimfactor, dodraw, ledfb, ledfb_claimed, remotefb, remotetmr, lamp_announce, tq, loaddrawfn +-- globals referenced: isblackout, dimfactor, isDim, dodraw, ledfb, ledfb_claimed, remotefb, remotetmr, lamp_announce, tq, loaddrawfn -- -- globals asserted: touchcolor, touchlastfn -- @@ -52,7 +52,16 @@ end local function toggleblackout() setblackout(not isblackout) end local function dimdisplay() - dimfactor= dimfactor + 1 % 16 + if isDim then + dimfactor = dimfactor + 1 + else + dimfactor = dimfactor - 1 + end + if dimfactor == 7 then + isDim = false + elseif dimfactor == 0 then + isDim = true + end end local function touchcolorvec(c) @@ -106,7 +115,13 @@ local function ontouch() -- back right button: display toggle once per touch of button if bit.isset(down,0) then - if touch_db_blackout == nil then toggleblackout() else tq:dequeue(touch_db_blackout) end + if touch_db_blackout == nil then + toggleblackout() + else + print("dequeueing blackout call") + tq:dequeue(touch_db_blackout) + end + print("queueing blackout call") touch_db_blackout = tq:queue(300,onblackdebounce) end