Exemplo n.º 1
0
    public static async void SetHue(LightBulb target, ushort newHue)
    {
        Debug.Log(target.HostName + ".Hue = " + newHue);
        var last = LastOnLightState;
        await Client.SetColorAsync(target, newHue, last.Saturation, last.Brightness, last.Kelvin, TimeSpan.FromTicks(0));

        LastOnLightState = (await Client.GetLightStateAsync(target));
    }
Exemplo n.º 2
0
        public async void StartStream(CancellationToken ct)
        {
            LogUtil.Write("Lifx: Starting stream.");
            var col = new Color {
                R = 0x00, G = 0x00, B = 0x00
            };

            Streaming = true;
            await _client.SetLightPowerAsync(B, TimeSpan.Zero, true).ConfigureAwait(false);

            await _client.SetColorAsync(B, col, 2700).ConfigureAwait(false);

            LogUtil.Write("Lifx: Streaming is active...");
            while (!ct.IsCancellationRequested)
            {
                Streaming = true;
            }

            StopStream();
        }
Exemplo n.º 3
0
        private static async Task SetColor(LightBulb bulb, string eventID, ushort hue, ushort saturation, ushort brightness,
                                           ushort kelvin)
        {
            var taskTimeOut    = GetAppSetting("TaskTimeout", TaskTimeoutDefault);
            var taskTimeOutInc = GetAppSetting("TaskTimeoutInc", TaskTimeoutIncDefault);
            var commandSends   = GetAppSetting("CommandSends", CommandSendsDef);

            //  bulb.State = await _client.GetLightStateAsync(bulb);

            var chue        = bulb.State.Hue;
            var csaturation = bulb.State.Saturation;
            var cbrightness = bulb.State.Brightness;
            var ckelvin     = bulb.State.Kelvin;

            if (kelvin == ckelvin && hue == chue && saturation == csaturation && brightness == cbrightness)
            {
                return;
            }
            if (kelvin < KelvinLow)
            {
                kelvin = KelvinLow;
            }

            if (kelvin > KelvinHigh)
            {
                kelvin = KelvinHigh;
            }

            for (var count = 0; count < commandSends; ++count)
            {
                // var to = new TimeSpan(taskTimeOut + taskTimeOutInc * commandSends);
                var rr = taskTimeOut + (taskTimeOutInc * count);
                var to = GetTS(rr);

                Log.Bulb($"{eventID} SetColor {bulb.State.Label} Try: {count}/{commandSends} TimeOut: {to}");

                var res = await
                          _client.SetColorAsync(bulb, hue, saturation, brightness, kelvin, new TimeSpan(0)).TimeoutAfter(to);

                if (!res)
                {
                    continue;
                }

                count                 = commandSends + 10;
                bulb.State.Hue        = hue;
                bulb.State.Saturation = saturation;
                bulb.State.Brightness = brightness;
                bulb.State.Kelvin     = kelvin;
            }

            Log.Bulb($"{eventID} SetColor {bulb.State.Label} Done");
        }
Exemplo n.º 4
0
    private async void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e)
    {
        var bulb = e.Device as LightBulb;
        await client.SetDevicePowerStateAsync(bulb, true);         //Turn bulb on

        // await client.SetColorAsync(bulb, red, 2700); //Set color to Red and 2700K Temperature
        // LightBulb bulb,
        //  UInt16 hue,
        //  UInt16 saturation,
        //  UInt16 brightness,
        //  UInt16 kelvin,
        //  TimeSpan transitionDuration

        await client.SetColorAsync(bulb,
                                   (ushort)hue,
                                   (ushort)sat,
                                   (ushort)brightness,
                                   2700,
                                   new System.TimeSpan(0, 0, (int)duration)
                                   );
    }
        public async Task SetDeviceRgbColorAsync(string label, Windows.UI.Color color)
        {
            LifxDevice lifx = await GetDeviceByLabelAsync(label);

            if (lifx == null)
            {
                Debug.WriteLine($"Device with label {label} was not found.");
                return;
            }

            LightBulb bulb = GetBulb(lifx);

            LifxNet.Color lifxColor = new LifxNet.Color
            {
                R = color.R,
                G = color.G,
                B = color.B
            };

            // Allowed values for kelvin parameter are between 2500 and 9000.
            Task task = _client.SetColorAsync(bulb, lifxColor, 5000, TimeSpan.FromSeconds(1));

            await Task.WhenAny(task, Task.Delay(5000));
        }