public void SetColor(double hue, double saturation, double lightness, int lightIx, uint source, byte sequence) { double[] hsb = LiFXUtils.HSL2HSB(hue, saturation, lightness); // нормирование значений // Hue: range 0 to 65535 // Saturation: range 0 to 65535 // Brightness: range 0 to 65535 // Kelvin: range 2500° (warm) to 9000° (cool) UInt16 Hue = (UInt16)((hsb[0] * 65535) / 360.0); //Console.WriteLine($"HueUint16 {Hue}"); UInt16 Sat = (UInt16)(hsb[1] * 65535); UInt16 Bri = (UInt16)(hsb[2] * 65535); SetColor payload = new SetColor(Hue, Sat, Bri, 2500, 0); Message msg = new Message(); msg.Header.Target = LE_EntryList[lightIx].MacUInt64; msg.Header.Tagged = false; msg.Header.Addressable = true; msg.Header.Res_required = false; msg.Ack_required = true; msg.Header.Source = source; msg.Header.MessageType = MsgTypeEnum.SetColor; msg.Header.Sequence = sequence; msg.Payload = payload; SendMessage(LE_EntryList[lightIx].Channel.LE_EndPoint.IPAddress, msg.RawMessage); }
public void SetColor(IPAddress ipAddress, UInt64 mac, double h, double s, double l, int transitiontime = 0) { double[] hsb = LiFXUtils.HSL2HSB(h, s, l); // нормирование значений // Hue: range 0 to 65535 // Saturation: range 0 to 65535 // Brightness: range 0 to 65535 // Kelvin: range 2500° (warm) to 9000° (cool) UInt16 Hue = (UInt16)((hsb[0] * 65535) / 360.0); //Console.WriteLine($"HueUint16 {Hue}"); UInt16 Sat = (UInt16)(hsb[1] * 65535); UInt16 Bri = (UInt16)(hsb[2] * 65535); SetColor payload = new SetColor(Hue, Sat, Bri, 2500, (ushort)transitiontime); Message msg = new Message(); msg.Header.Target = mac; msg.Header.Tagged = false; msg.Header.Addressable = true; msg.Header.Res_required = false; msg.Ack_required = true; //msg.Header.Source = source; msg.Header.MessageType = MsgTypeEnum.SetColor; //msg.Header.Sequence = sequence; msg.Payload = payload; requestQueue.Enqueue(new MessageCmd(ipAddress, msg)); //SendMessage(LE_EntryList[lightIx].Channel.LE_EndPoint.IPAddress, msg.RawMessage); }
static void Main(string[] args) { List <LightDescriptor> lights = LiFXUtils.GetLights(); List <LiFXControlChannel> channels = new List <LiFXControlChannel>(); WriteLine("Найдены LiFX лампы \r\n"); foreach (LightDescriptor ld in lights) { WriteLine($"{ld.Address} {ld.MacStr}\r\n"); } //WriteLine("Ввернуть лампу, нажать Enter\r\n"); //ReadLine(); //List<LightDescriptor> newLights = LiFXUtils.GetNewLights(lights); //if (newLights.Count != 0) //{ // WriteLine("Новые LiFX лампы\r\n"); // foreach (LightDescriptor ld in newLights) // WriteLine($"{ld.Address} {ld.MacStr}"); //} //else // WriteLine("Новых ламп не найдено\r\n"); //lights.AddRange(newLights); LiFX_Service service = new LiFX_Service(); if (lights.Count == 2) { // тестирование LiFXControlChannel для 2х ламп LiFX LightDescriptor ld = lights[0]; LiFXControlChannel channel = new LiFXControlChannel($"<Params IP = \"{ld.Address}\" MAC = \"{ld.MAC}\"/>"); channel.CSService = service; channels.Add(channel); ld = lights[1]; channel = new LiFXControlChannel($"<Params IP = \"{ld.Address}\" MAC = \"{ld.MAC}\"/>"); channels.Add(channel); channel.CSService = service; double hue = 0.0; while (true) { channels[0].SetRGB(hue, 1.0, 0.2); channels[1].SetRGB(hue, 1.0, 0.2); //Console.WriteLine($"Hue {hue}"); Thread.Sleep(25); hue += 1.0; if (hue >= 360.0) { hue = 0.0; } } } if (lights.Count == 1) { // тестирование LiFXControlChannel для лампы LiFX LightDescriptor ld = lights[0]; LiFXControlChannel channel = new LiFXControlChannel($"<Params IP = \"{ld.Address}\" MAC = \"{ld.MAC}\"/>"); channel.CSService = service; channels.Add(channel); //ld = lights[1]; //channel = new LiFXControlChannel($"<Params IP = \"{ld.Address}\" MAC = \"{ld.MAC}\"/>"); //channels.Add(channel); //channel.CSService = service; double hue = 0.0; while (true) { channels[0].SetRGB(hue, 1.0, 0.2); //channels[1].SetRGB(hue, 1.0, 0.2); //Console.WriteLine($"Hue {hue}"); Thread.Sleep(40); hue += 1.0; if (hue >= 360.0) { hue = 0.0; } } } WriteLine("\r\nEnter - to Exit"); ReadLine(); }