public BulbViewModel(LifxBulb b, LifxController controller) { Bulb = b; _controller = controller; Bulb.PropertyChanged += Bulb_PropertyChanged; }
private void HandleLightStatusMessage(LifxLightStatusMessage message, LifxBulb bulb) { if (message != null) { FadeTimeSlider.Value = message.Dim; bulb.Colour = new LifxColour() { Hue = message.Hue, Saturation = message.Saturation, Luminosity = message.Lumnosity, Kelvin = message.Kelvin }; bulb.Label = message.Label; bulb.Tags = message.Tags; bulb.IsOn = message.PowerState; StorageHelper.SaveToStorage(); if (firstLightStatusFlag) { UnBindValueChangedEventHandlers(); HueSlider.Value = message.Hue; SaturationSlider.Value = message.Saturation; LuminositySlider.Value = message.Lumnosity; KelvinSlider.Value = message.Kelvin; BindValueChangedEventHandlers(); firstLightStatusFlag = false; } } }
private void button1_Click(object sender, EventArgs e) { List <LifxPanController> panController = LifxCommunicator.Instance.Discover(); if (panController.Count == 0) { MessageBox.Show("Could not find any bulbs"); mPowerGB.Enabled = false; mLabelsGB.Enabled = false; mLightStatusGB.Enabled = false; return; } mBulb = panController[0].Bulbs[0]; mBulbIPTB.Text = mBulb.IpEndpoint.Address.ToString(); mTargetMACTB.Text = mBulb.MacAddress; mPANControllerTB.Text = mBulb.PanHandler; LifxPowerState powerState = mBulb.GetPowerState(); if (powerState == LifxPowerState.On) { mPowerStateOnCB.Checked = true; } else { mPowerStateOnCB.Checked = false; } mPowerGB.Enabled = true; mLabelsGB.Enabled = true; mLightStatusGB.Enabled = true; }
public LightsDetailPage(LifxBulb bulb) { InitializeComponent(); lifxManager = new LifxManager(); thisBulb = bulb; LightLabel.Text = bulb.Label; LightSwitch.IsToggled = bulb.Power; }
public static void StoreBulb(LifxBulb newBulb) { bool controllerFound = false; foreach (LifxPanController panController in panControllers.Values) { if (newBulb.PanController.UID == panController.UID) { panController.Bulbs.Add(newBulb); controllerFound = true; } } if (!controllerFound) { panControllers.Add(newBulb.PanController.MACAddress, newBulb.PanController); } SaveToStorage(); }
async void bulbPowerState_Tapped(object sender, TappedRoutedEventArgs e) { powerStateTapped = true; TextBlock powerTextBlock = sender as TextBlock; if (powerTextBlock != null) { LifxBulb bulb = StorageHelper.GetBulb(powerTextBlock.Tag as Byte[]); LIFX_Net.Messages.LifxPowerStateMessage psm = await bulb.SetPowerStateCommand(powerTextBlock.Text == LifxPowerState.On.ToString()?LifxPowerState.Off : LifxPowerState.On); powerTextBlock.Inlines.Clear(); powerTextBlock.Inlines.Add(new Run() { Text = psm.PowerState.ToString(), Foreground = psm.PowerState == LifxPowerState.On ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Gray) }); bulb.IsOn = psm.PowerState; StorageHelper.SaveToStorage(); } }
private async Task HandlePowerStateMessage(LifxPowerStateMessage message, LifxBulb bulb) { if (message != null) { if (message.PowerState == LifxPowerState.On) { TogglePowerSwitch(true); SetControlState(true, true); LifxLightStatusMessage lightstatus = await bulb.GetLightStatusCommand(); HandleLightStatusMessage(lightstatus, bulb); } else if (message.PowerState == LifxPowerState.Off) { TogglePowerSwitch(false); //PowerToggleSwitch.IsEnabled = true; SetControlState(false); bulb.IsOn = LifxPowerState.Off; } } }
private void InitObservableProperties() { _networkManager.UdpListener() .ObserveOn(NewThreadScheduler.Default) .Do(p => Log.Debug(TAG, "Received: {0}", p)) .Where(packet => packet.Sequence != 0) .Do(packet => { var discoveryPacket = packet as DiscoveryPacket; if (discoveryPacket != null) { var duplicate = Bulbs.Any(b => b.IP.Equals(discoveryPacket.IP)); if (!duplicate) { var bulb = new LifxBulb() { Mac = discoveryPacket.Mac, IP = discoveryPacket.IP, SiteAddress = discoveryPacket.Site }; Bulbs.Add(bulb); _discoverySubject.OnNext(bulb); _labelSubject.OnNext(bulb); _groupSubject.OnNext(bulb); } } else { var sentPacket = _sentPackets.Where(p => p.Key == packet.Sequence).FirstOrDefault(); packet.ProcessBulb(sentPacket.Value); _sentPackets.Remove(sentPacket); } }) .Subscribe(_ct); _labelSubject.Subscribe(bulb => { Thread.Sleep(750); // don't want to spam packets, bulbs might ignore some var data = new byte[PacketSize.GET_LABEL]; var seq = SequenceGenerator.Next; NativeMethods.GetLabelPacket(bulb.SiteAddress, seq, data); _sentPackets.Add(new KeyValuePair <byte, LifxBulb>(seq, bulb)); _networkManager.SendTargetedPacket(data, seq, bulb.IP); }, _ct); _groupSubject.Subscribe(bulb => { Thread.Sleep(750); var data = new Byte[PacketSize.GET_GROUP]; var seq = SequenceGenerator.Next; NativeMethods.GetGroupPacket(bulb.SiteAddress, seq, data); _sentPackets.Add(new KeyValuePair <byte, LifxBulb>(seq, bulb)); _networkManager.SendTargetedPacket(data, seq, bulb.IP); }, _ct); }
/// <summary> /// Start breathe effect on <see cref="LifxBulb"/>. /// </summary> public async Task BreatheAsync(LifxBulb bulb, string color, string fromColor = null, int cycles = 3, double period = 1.0) { var data = new { color, from_color = fromColor, cycles, period }; await PostAsync($"lights/{bulb.Id}/effects/breathe", data); }
/// <summary> /// Set color on <see cref="LifxBulb"/>, see examples below: /// /// <list type="bullet"> /// <item>"#ff0000" – Deep red, maximum brightness</item> /// <item>"hue:120 saturation:1.0 brightness:0.5" – Deep green, 50% brightness</item> /// <item>"kelvin:2700 brightness: 0.5" – Warm white (2700 K), 50% brightness</item> /// <item>"rgb:0,255,255" – Cyan, 100% brightness</item> /// <item>"kelvin:5000" – Set kelvin to cool white (5000 K) and saturation to 0 without affecting other components</item> /// <item>"kelvin:2700 saturation:1" – Set kelvin to warm (2700 K) and saturation to 1</item> /// <item>"brightness:0.75" – Set brightness to 75% without affecting other components</item> /// <item>"saturation:0.25" – Set saturation to 25% without affecting other components</item> /// <item>"red" – Sets color to red but doesn't affect brightness</item> /// </list> /// /// </summary> public async Task SetColorAsync(LifxBulb bulb, string color) { var data = new { States = new[] { new { selector = $"id:{bulb.Id}", color } } }; await PutAsync("lights/states", data); }
/// <summary> /// Turn off <see cref="LifxBulb"/>. /// </summary> public async Task TurnOffAsync(LifxBulb bulb) { var data = new { states = new[] { new { selector = $"id:{bulb.Id}", power = "off" } } }; await PutAsync("lights/states", data); }
/// <summary> /// Toggle <see cref="LifxBulb"/> (on/off). /// </summary> public async Task TogglePowerAsync(LifxBulb bulb) { await PostAsync($"lights/{bulb.Id}/toggle"); }
/// <summary> /// Set state of <see cref="LifxBulb"/>. /// </summary> public async Task SetStateAsync(LifxBulb bulb, string color = null, bool on = true, double brightness = 1.0, double duration = 1.0) { var data = new { States = new[] { new { Selector = $"id:{bulb.Id}", power = on ? "on" : "off", color, brightness, duration } } }; await PutAsync("lights/states", data); }
/// <summary> /// Stop effect on <see cref="LifxBulb"/>. /// </summary> public async Task StopEffectsAsync(LifxBulb bulb) { await PostAsync($"lights/{bulb.Id}/effects/off"); }