private void SetColor(string MAC, hexDataColor Color) { if (Instance.IsLogged()) { if (Color == null) { } if (MAC == null) { if (listView1.Items.Count > 0) { Instance.TurnOn(listView1.SelectedItems[0].SubItems[2].Text, Color); } else { MessageBox.Show("Please add at least one device."); } } else { Instance.TurnOn(MAC, Color); } } else { MessageBox.Show("Can't get user devices, please login."); } }
public string GetCRC8256_color(hexDataColor Color) { int sum = 0x31 + Color.R + Color.G + Color.B + 0xf; sum %= 0x100; return(sum.ToString("X")); }
public void TurnOn(string MAC, hexDataColor Color) { Request = createClient("http://wifij01eu.magichue.net/app/sendCommandBatch/ZG001"); Request.Method = "POST"; hexData = string.Format("31{0}{1}{2:X}", Color.getColor(), "00000F", GetCRC8256_color(Color)); using (SW = new StreamWriter(Request.GetRequestStream())) { json = "{\"dataCommandItems\":[{\"hexData\":\"" + hexData + "\",\"macAddress\":\"" + MAC + "\"}]}"; SW.Write(json); SW.Flush(); } try { httpResponse = (HttpWebResponse)Request.GetResponse(); using (SR = new StreamReader(httpResponse.GetResponseStream())) { string result = SR.ReadToEnd(); } } catch (Exception) { } }
private void blue2_Click(object sender, EventArgs e) { hexDataColor a = new hexDataColor(0xff, 0x00, 0xff, brightness); SetColor(null, a); }