Beispiel #1
0
 public async void MovieModeOff()
 {
     this.isOn = false;
     await Task.Run(() =>
     {
         Thread.Sleep(400);
         RGBColor rgb             = new RGBColor("#" + Config.defaultcolor);
         Color c                  = Color.FromArgb(Convert.ToInt32(rgb.R), Convert.ToInt32(rgb.G), Convert.ToInt32(rgb.B));
         LightColorAttributes obj = this.calcColor(c);
         foreach (var i in this.usingLights)
         {
             var client            = this.GetClient();
             var request           = new RestRequest(String.Format("lights/{0}/state", i), Method.PUT);
             request.RequestFormat = DataFormat.Json;
             request.AddBody(obj);
             var response = client.Execute(request);
         }
     });
 }
Beispiel #2
0
        private async void StartAsync()
        {
            await Task.Run(() =>
            {
                while (this.isOn)
                {
                    LightColorAttributes obj = this.calcColor(this.getAverageColor());
                    foreach (var i in this.usingLights)
                    {
                        var client            = this.GetClient();
                        var request           = new RestRequest(String.Format("lights/{0}/state", i), Method.PUT);
                        request.RequestFormat = DataFormat.Json;
                        request.AddBody(obj);
                        var response = client.Execute(request);
                    }

                    Thread.Sleep(100);
                }
            });
        }
Beispiel #3
0
        public LightColorAttributes calcColor(Color rgb)
        {
            float r     = ((float)(rgb.R));
            float g     = ((float)(rgb.G));
            float b     = ((float)(rgb.B));
            float red   = (r > 0.04045f) ? (float)(Math.Pow((r + 0.055f) / (1.0f + 0.055f), 2.4f)) : (r / 12.92f);
            float green = (g > 0.04045f) ? (float)(Math.Pow((g + 0.055f) / (1.0f + 0.055f), 2.4f)) : (g / 12.92f);
            float blue  = (b > 0.04045f) ? (float)(Math.Pow((b + 0.055f) / (1.0f + 0.055f), 2.4f)) : (b / 12.92f);
            float X     = red * 0.664511f + green * 0.154324f + blue * 0.162028f;
            float Y     = red * 0.283881f + green * 0.668433f + blue * 0.047685f;
            float Z     = red * 0.000088f + green * 0.072310f + blue * 0.986039f;
            float cx    = X / (X + Y + Z);
            float cy    = Y / (X + Y + Z);
            var   obj   = new LightColorAttributes();

            obj.xy = new List <float> {
                cx, cy
            };
            obj.bri = Convert.ToInt32(Y * 300);
            return(obj);
        }