]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
simpler dimming function that merely cuts values in half
authorRachael <srbennett@gmail.com>
Sun, 30 Apr 2017 22:45:24 +0000 (15:45 -0700)
committerRachael <srbennett@gmail.com>
Sun, 30 Apr 2017 22:45:24 +0000 (15:45 -0700)
lamp-touch.lua

index 128403a5d8e11b24eef0c96e1b45da3679cdbaa4..7d17c316d67e5b0353a9478a0e49e0a5cd51de1c 100644 (file)
@@ -10,7 +10,7 @@ local touch_db_blackout = nil
 local touch_db_fn = nil
 local touchfns    = { }
 local touchfnix = 1
-local dimfactor = 1
+local dimfactor = 0
 
 if touchcolor == nil then touchcolor = 40 end
 if touchlastfn == nil then touchlastfn = "fill" end
@@ -53,8 +53,7 @@ end
 local function toggleblackout() setblackout(not isblackout) end
 
 local function dimdisplay()
-  dimfactor = dimfactor + 10
-  dimfactor = dimfactor % 100
+  dimfactor= dimfactor + 1 % 16
 end
 
 local function touchcolorvec(c)
@@ -67,65 +66,12 @@ local function touchcolorvec(c)
   if (dimfactor > 0) then
     print("before green is ", g)
     print("before blue is ", b)
-    local h = 0
-    local s = 0
-    local l = 0
-    local maxcolor = math.max(r,g,b)
-    local mincolor = math.min(r,g,b)
-    local delta = maxcolor - mincolor
-    l = math.floor((maxcolor + mincolor)/2)
-
-    if (maxcolor == r) then
-      h = (math.floor(((g)-(b))/delta) % 6)
-    else if (maxcolor == g) then
-      h = (math.floor(((b)- (r))/delta) + 2)
-    else if (maxcolor == b) then
-      h = (math.floor(((r)- (g))/delta) + 4)
-    end
-    if (delta == 0) then
-      h = 0
-      s = 0
-    else
-      s = math.floor((maxcolor - mincolor)/(1-math.abs(2*l -1)))
-    end
-    l = math.floor(l/dimfactor)
-
-    local c, x, m
-    c = (1- math.abs(2*l - 1)) * s
-    x = c * (1-math.abs((h) % 2 - 1))
-    m = l-math.floor(c/2)
-
-    local rprime, gprime, bprime
-
-    if ( h < 1) then
-      rprime = c
-      gprime = x
-      bprime = 0
-    else if (h < 2) then
-      rprime = x
-      gprime = c
-      bprime = 0
-    else if (h < 3) then
-      rprime = 0
-      gprime = c
-      bprime = x
-    else if (h < 4) then
-      rprime = 0
-      gprime = x
-      bprime = c
-    else if (h < 5) then
-      rprime = x
-      gprime = 0
-      bprime = c
-    else if (h < 6) then
-      rprime = c
-      gprime = 0
-      bprime = x
-    end
 
-    g = math.abs(math.floor((gprime + m)))
-    b = math.abs(math.floor((bprime + m)))
-    r = math.abs(math.floor((rprime + m)))
+    for i = 0, dimfactor do
+      g = math.floor((g+1)/2)
+      b = math.floor((b+1)/2)
+      r = math.floor((r+1)/2)
+    end
     print("green is ", g)
     print("blue is ", b)
   end