]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
added a reset button to immediately undim the lamp (using the dimming button to do...
authorRachael <srbennett@gmail.com>
Tue, 20 Feb 2018 01:07:32 +0000 (17:07 -0800)
committerRachael <srbennett@gmail.com>
Tue, 20 Feb 2018 01:07:32 +0000 (17:07 -0800)
lamp-touch.lua

index 84b66a716cd5eea67039f61cb9fcc560638f4b17..856316ef2386e1a2f77c93bf5cb2dcbd68d28d28 100644 (file)
@@ -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