]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
cleans up a bunch of prints and allows a 3rd (or nth) color to be sent over the network
authorRachael <srbennett@gmail.com>
Tue, 20 Feb 2018 07:39:57 +0000 (23:39 -0800)
committerRachael <srbennett@gmail.com>
Tue, 20 Feb 2018 07:39:57 +0000 (23:39 -0800)
init2.lua
lamp-touch.lua

index 1ae366fe544428e7832fc2363cf09be840e4a782..9fb386a2731b61b6f933d59ff3c116bb5ca6ef96 100644 (file)
--- a/init2.lua
+++ b/init2.lua
@@ -92,26 +92,19 @@ end
 
 -- TODO: messages to specific lamps?  Multiple brokers?
 function lamp_announce(fn,colors)
-  print("trying to announce ", colors)
   if #colors > 1 then
-    if colors then
-      for k,v in pairs(colors[1]) do print(k,v) end
-    else
-      print("nil colors")
+    local broadcaststring
+    for i=1,#colors do
+      local r,g,b = transformcolors(colors[i]);
+      if (i == 1) then
+        broadcaststring = string.format("draw %s %x %x %x;", fn, r,g,b);
+      else
+        broadcaststring = string.format("color %x %x %x %x; ", i, r, g, b) .. broadcaststring
+      end
     end
-    -- TODO more than 2 colors?
-    local r,g,b = transformcolors(colors[1]);
-    local r2,g2,b2 = transformcolors(colors[2])
-    mqc:publish(mqttBcastPfx,string.format("color 2 %x %x %x; draw %s %x %x %x;",r2,g2,b2,fn,r,g,b),1,1)
+    mqc:publish(mqttBcastPfx,broadcaststring,1,1)
   else
-    print("one color")
-    if colors then
-      for k,v in pairs(colors[1]) do print(k,v) end
-    else
-      print("nil colors")
-    end
     local r,g,b = transformcolors(colors[1])
-    print(r,g,b)
     mqc:publish(mqttBcastPfx,string.format("draw %s %x %x %x;",fn,r,g,b),1,1)
   end
 end
index 942864685cdc2306a56d2a0e8150e1c989c12ada..f2b30500813ff281fc273a1027b92fdaecfacaf9 100644 (file)
@@ -135,10 +135,8 @@ local function ontouch()
     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
 
@@ -172,14 +170,12 @@ local function ontouch()
      if     touchcolor >= 48 then touchcolor = touchcolor - 48
      elseif touchcolor < 0  then touchcolor = touchcolor + 48
      end
-     print(colors, "colorindex is while changing color", colorindex);
      colors[colorindex] = string.char(touchcolorvec(touchcolor))
      networkcolors[colorindex] = {touchcolorvec(touchcolor)}
     end
 
     -- front middle: mode select (rate-limited, not exactly debounced)
     if bit.isset(down,3) then
-      print("front middle touched", touch_db_fn)
       if touch_db_fn == nil then
        if bit.isset(down,2)
         then touchfnix = touchfnix - 1
@@ -204,13 +200,11 @@ local function ontouch()
 
   -- XXX left side middle button; change colors!
   if bit.isset(down, 6) then
-    print("ncolors is ", ncolors);
     if ncolors and colorindex < ncolors then
       colorindex = colorindex + 1;
     else
       colorindex = 1;
     end
-        print("should increment color", colorindex);
   end
 
   -- XXX front left
@@ -219,22 +213,15 @@ local function ontouch()
 
   -- draw if we've claimed it!
   if (ledfb == touchfb) and not didChangeFn and didChangeColor and cccb ~= nil then
-    print("colors only");
     -- all we did was change the color(s); inform the existing animation
     cccb()
   elseif didChangeFn or didChangeColor then
     -- full (re)load
     touchtmr:unregister()
     touchlastfn = touchfns[touchfnix]
-    print(touchlastfn);
     local drawinfo = loaddrawfn(touchlastfn)(touchtmr,touchfb,colors)
-    print(touchlasstfn, "trying drawinfo", drawinfo);
-    if drawinfo then
-      for k,v in pairs(drawinfo) do print(k,v) end
-    end
     cccb = drawinfo and drawinfo['cccb']
     ncolors = drawinfo and drawinfo['ncolors'] or 1
-    print(ncolors);
 
     dodraw()
     touchtmr:start()