From c61277eac9dc0da11ce94c3cf16f11b208a44da0 Mon Sep 17 00:00:00 2001 From: Rachael Date: Mon, 19 Feb 2018 17:07:32 -0800 Subject: [PATCH] added a reset button to immediately undim the lamp (using the dimming button to do it is annoying and error-prone) --- lamp-touch.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lamp-touch.lua b/lamp-touch.lua index 84b66a7..856316e 100644 --- a/lamp-touch.lua +++ b/lamp-touch.lua @@ -81,6 +81,7 @@ local function touchcolorvec(c) end local colors = { string.char(touchcolorvec(touchcolor)) } +local colorindex = 1; local function onblackdebounce() touch_db_blackout = nil end local function onfndebounce() touch_db_fn = nil end @@ -140,9 +141,11 @@ local function ontouch() touch_db_blackout = tq:queue(300,onblackdebounce) end - -- left side back button: dim the display. + -- left side back button: reset colors and dimming. if bit.isset(down,7) then - dimdisplay() + dimfactor = 0; + colors = { string.char(touchcolorvec(touchcolor)) } + colorindex = 1; -- Don't claim the image, just dim whatever is currently on the screen. dodraw() end @@ -167,7 +170,7 @@ local function ontouch() if touchcolor >= 48 then touchcolor = touchcolor - 48 elseif touchcolor < 0 then touchcolor = touchcolor + 48 end - colors[1] = string.char(touchcolorvec(touchcolor)) + colors[colorindex] = string.char(touchcolorvec(touchcolor)) end -- front middle: mode select (rate-limited, not exactly debounced) @@ -188,12 +191,20 @@ local function ontouch() end end - -- XXX left side front button + -- XXX left side front button, dim the display if bit.isset(down,5) then + dimdisplay() + -- Don't claim the image, just dim whatever is currently on the screen. + dodraw() end -- XXX left side middle button if bit.isset(down, 6) then + if colorindex < ncolors then + colorindex = colorindex + 1; + else + colorindex = 1; + end end -- XXX front left @@ -208,8 +219,9 @@ local function ontouch() -- full (re)load touchtmr:unregister() touchlastfn = touchfns[touchfnix] - + print(touchlastfn); local drawinfo = loaddrawfn(touchlastfn)(touchtmr,touchfb,colors) + print(drawinfo); cccb = drawinfo and drawinfo['cccb'] ncolors = drawinfo and drawinfo['ncolors'] or 1 -- 2.50.1