Пример #1
0
        /// <summary>
        /// Set group brightness by percentage with min and max
        /// </summary>
        /// <param name="level">from 0.0 to 1.0</param>
        /// <param name="min">minimum brightness, from 0.0 to 1.0<</param>
        /// <param name="max">maximum brightness, from 0.0 to 1.0<</param>
        public void SetBrightnessAndSaturation(double level, double min, double max, int saturation)
        {
            NextHue();
            double brightness = min + (max - min) * level;

            entGroup.SetState(HueToRGB(hue, saturation, 255), brightness, TimeSpan.FromMilliseconds(100));
            //if (brightness != min) Console.WriteLine("set brightness : " + brightness);
        }
Пример #2
0
        public async void Init(Label labelHint)
        {
            client = new StreamingHueClient(ip, key, entertainmentKey);

            //Get the entertainment group
            IReadOnlyList <Group> all = null;

            try
            {
                all = await client.LocalHueClient.GetEntertainmentGroups();
            }
            catch (Exception e)
            {
                labelHint.Text = "Hue init exception: " + e.Message;
                return;
            }
            var group = all.FirstOrDefault();

            if (group == null)
            {
                //throw new Exception("No Entertainment Group found. Create one using the Q42.HueApi.UniversalWindows.Sample");
                labelHint.Text = "No Entertainment Group found";
                return;
            }
            else
            {
                labelHint.Text = $"Using Entertainment Group {group.Id}";
                Console.WriteLine($"Using Entertainment Group {group.Id}");
            }

            //Create a streaming group
            entGroup = new StreamingGroup(group.Locations);

            //Connect to the streaming group
            await client.Connect(group.Id);

            //Start auto updating this entertainment group
            client.AutoUpdate(entGroup, 50);

            //Optional: calculated effects that are placed in the room
            client.AutoCalculateEffectUpdate(entGroup);

            //Optional: Check if streaming is currently active
            var bridgeInfo = await client.LocalHueClient.GetBridgeAsync();

            Console.WriteLine(bridgeInfo.IsStreamingActive ? "Streaming is active" : "Streaming is not active");
            labelHint.Text = bridgeInfo.IsStreamingActive ? "Streaming is active" : "Streaming is not active";

            //Order lights based on position in the room
            var orderedLeft      = entGroup.GetLeft().OrderByDescending(x => x.LightLocation.Y).ThenBy(x => x.LightLocation.X);
            var orderedRight     = entGroup.GetRight().OrderByDescending(x => x.LightLocation.Y).ThenByDescending(x => x.LightLocation.X);
            var allLightsOrdered = orderedLeft.Concat(orderedRight.Reverse()).ToArray();

            var allLightsReverse = allLightsOrdered.ToList();

            allLightsReverse.Reverse();

            Random rnd = new Random();

            hue = rnd.Next(0, 65535);

            entGroup.SetState(HueToRGB(hue, 1, 1), 1, TimeSpan.FromMilliseconds(0));

            isInit = true;
        }