private void ChangeLedButton_Click(object sender, EventArgs e) { if (CheckTextFieldValue(RecIdTextBox.Text) && CheckTextFieldValue(IntRTextBox.Text) && CheckTextFieldValue(IntGTextBox.Text) && CheckTextFieldValue(IntBTextBox.Text)) { LED changeLed = new LED(); changeLed.Color = new byte[3] { 0, 0, 0 }; changeLed.Intensity = new double[3] { Convert.ToDouble(IntRTextBox.Text), Convert.ToDouble(IntGTextBox.Text), Convert.ToDouble(IntBTextBox.Text) }; changeLed.RectID = Convert.ToInt32(RecIdTextBox.Text); for (int i = 0; i < LedListBox.SelectedIndices.Count; ++i) { // TODO: Get correct IDs changeLed._id = 0; bool suc = newAmbi.SetLed(changeLed); if (suc == false) { MessageBox.Show("Id was not found!"); } } } else { MessageBox.Show("Please insert valid numbers to change LEDs!"); } }
/* --------------------------------------------------------------------------------------------- */ private void CreateLedButton_Click(object sender, EventArgs e) { // TODO: Check for double values and not int. Will not work with the check right now. Instead improve the method with a template for different types (int/double). if (CheckTextFieldValue(RecIdTextBox.Text) && CheckTextFieldValue(IntRTextBox.Text) && CheckTextFieldValue(IntGTextBox.Text) && CheckTextFieldValue(IntBTextBox.Text)) { LED[] addLeds = new LED[Convert.ToInt32(NumLedUpDown.Value)]; for (int i = 0; i < addLeds.Length; ++i) { ++idindex; addLeds[i]._id = idindex; addLeds[i].Intensity = new double[] { Convert.ToDouble(IntRTextBox.Text), Convert.ToDouble(IntGTextBox.Text), Convert.ToDouble(IntBTextBox.Text) }; addLeds[i].RectID = Convert.ToInt32(RecIdTextBox.Text); } newAmbi.AddLeds(addLeds); showData(); } else { MessageBox.Show("Please insert valid numbers to create LEDs!"); } }
public void AddLeds(LED[] newLed) { // TODO: With resize instead of new declaration we can remove extra LedList and save first copy command // Add new leds to ledlist array LED[] newLedList = new LED[LedList.Length + newLed.Length]; Array.Copy(LedList, newLedList, LedList.Length); Array.Copy(newLed, 0, newLedList, LedList.Length, newLed.Length); // Replace old ledList with new one LedList = newLedList; }
public LED GetLedData(int ledId) { LED foundLed = new LED(); // Find led with ledId and return values for (int i = 0; i < LedList.Length; ++i) { if (LedList[i]._id == ledId) { foundLed = LedList[i]; } } return(foundLed); }
private void ChangeButton_Click(object sender, EventArgs e) { // Change it so it works with multiple selected elements LED LedChange = new LED(); for (int i = 0; i < LedListBox.SelectedIndices.Count; ++i) { int selId = Convert.ToInt32(LedListBox.SelectedIndices[i]); LedChange.Color = new byte[] { Convert.ToByte(ColorRTextBox.Text), Convert.ToByte(ColorGTextBox.Text), Convert.ToByte(ColorBTextBox.Text) }; LedChange.Intensity = new double[] { Convert.ToDouble(IntRTextBox.Text), Convert.ToDouble(IntGTextBox.Text), Convert.ToDouble(IntBTextBox.Text) }; LedChange._id = selId; newMulti.SetLed(LedChange); } showData(); }
private void CreateLedButton_Click(object sender, EventArgs e) { LED[] addLeds = new LED[Convert.ToInt32(NumLedUpDown.Value)]; for (int i = 0; i < addLeds.Length; ++i) { addLeds[i]._id = idindex; addLeds[i].Color = new byte[] { Convert.ToByte(ColorRTextBox.Text), Convert.ToByte(ColorGTextBox.Text), Convert.ToByte(ColorBTextBox.Text) }; addLeds[i].Intensity = new double[] { Convert.ToDouble(IntRTextBox.Text), Convert.ToDouble(IntGTextBox.Text), Convert.ToDouble(IntBTextBox.Text) }; // PRINT_OUT Console.WriteLine("New Led added with id: " + idindex + ", Color: " + addLeds[i].Color[0] + " " + addLeds[i].Color[1] + " " + addLeds[i].Color[2] + " and Intensity: " + addLeds[i].Intensity[0] + " " + addLeds[i].Intensity[1] + " " + addLeds[i].Intensity[2]); idindex++; } newMulti.AddLeds(addLeds); showData(); }
public void RemLeds(int[] LedIdSet) { // Remove leds from profile LED[] newLedList = new LED[LedList.Length - LedIdSet.Length]; int index = 0; for (int i = 0; i < LedIdSet.Length; ++i) { if (LedIdSet[index] != LedList[i]._id) { newLedList[i] = LedList[i + index]; } else { index++; } } LedList = newLedList; }
// TODO: Only change values that are set and keep old ones public bool SetLed(LED changeLed) { int index = -1; for (int i = 0; i < LedList.Length; ++i) { if (changeLed._id == LedList[i]._id) { index = i; } } if (index != -1) { // Change values of LED LedList[index] = changeLed; return(true); } else { return(false); } }
public Ambilight() { // Make objects for storage/processing of images MultScreen = Screen.AllScreens; ScreenNumber = MultScreen.Length; //BMP erstellen screenrect = new Rectangle(int.MaxValue, int.MaxValue, int.MinValue, int.MinValue); for (int i = 0; i < ScreenNumber; i++) { screenrect = Rectangle.Union(screenrect, MultScreen[i].Bounds); } screenrect1 = new Rectangle(0, 0, screenrect.Width - 1, screenrect.Height - 1); bmp = new Bitmap(screenrect.Width, screenrect.Height, PixelFormat.Format24bppRgb); //BMP fuellen gfx = Graphics.FromImage(bmp); // Initialize empty parts mon = new ScreenDevice[0]; LedList = new LED[0]; }
public override bool LoadProfile(string profileName) { // Get multilight data from xml file Console.WriteLine("Loading Profile: " + profileName); try { XDocument loadedXmlDoc = XDocument.Load(profileName); var screens = loadedXmlDoc.Element("LedProfile").Descendants("Screen"); var leds = loadedXmlDoc.Element("LedProfile").Descendants("LED"); // Loading Mode mode = loadedXmlDoc.Element("LedProfile").Attribute("Mode").Value; // Find leds int id = 0; int numLed = leds.Count(); Console.WriteLine(numLed + " LEDs found..."); LedList = new LED[numLed]; byte[] r = new byte[numLed]; byte[] g = new byte[numLed]; byte[] b = new byte[numLed]; foreach (var led in leds) { LedList[id]._id = Convert.ToByte(led.Attribute("LedID").Value); // Set color LedList[id].Color = new byte[3]; LedList[id].Color[0] = Convert.ToByte(led.Element("Color").Attribute("R").Value); LedList[id].Color[1] = Convert.ToByte(led.Element("Color").Attribute("G").Value); LedList[id].Color[2] = Convert.ToByte(led.Element("Color").Attribute("B").Value); // Set intensity LedList[id].Intensity = new double[3]; LedList[id].Intensity[0] = Convert.ToDouble(led.Element("Intensity").Attribute("R").Value); LedList[id].Intensity[1] = Convert.ToDouble(led.Element("Intensity").Attribute("G").Value); LedList[id].Intensity[2] = Convert.ToDouble(led.Element("Intensity").Attribute("B").Value); // Test output Console.WriteLine("Loading LED " + LedList[id]._id); id++; } // Initialise RGBdata array with numLed*3 + 2 and set start and stop byte RGBdata = new byte[leds.Count() * 3 + 2]; RGBdata[0] = 0x01; RGBdata[leds.Count() * 3 + 1] = 0x02; Console.WriteLine("Loading done..."); return(true); } catch (FileNotFoundException e) { return(false); } }
public override bool LoadProfile(string profileName) { Console.WriteLine("Loading Profile: " + profileName); try { XDocument loadedXmlDoc = XDocument.Load(profileName); var screens = loadedXmlDoc.Element("LedProfile").Descendants("Screen"); var leds = loadedXmlDoc.Element("LedProfile").Descendants("LED"); // Loading Mode mode = loadedXmlDoc.Element("LedProfile").Attribute("Mode").Value; // Find screens and define rectangles int screenid = 0; mon = new ScreenDevice[screens.Count()]; Console.WriteLine("new mons: " + screens.Count()); foreach (var screen in screens) { screenid = Convert.ToInt32(screen.Attribute("ScreenId").Value); mon[screenid] = new ScreenDevice(); int numRect = screen.Elements("Rectangle").Count(); mon[screenid].Rect = new Rectangle[numRect]; mon[screenid].Width = Convert.ToInt32(screen.Element("ScreenData").Attribute("Width").Value); mon[screenid].Height = Convert.ToInt32(screen.Element("ScreenData").Attribute("Height").Value); mon[screenid].XPos = Convert.ToInt32(screen.Element("ScreenData").Attribute("XPos").Value); mon[screenid].YPos = Convert.ToInt32(screen.Element("ScreenData").Attribute("YPos").Value); var rects = screen.Descendants("Rectangle"); int rectNr = 0; foreach (var rect in rects) { mon[screenid].Rect[rectNr] = new Rectangle(); mon[screenid].Rect[rectNr].X = Convert.ToInt32(rect.Attribute("X").Value); mon[screenid].Rect[rectNr].Y = Convert.ToInt32(rect.Attribute("Y").Value); mon[screenid].Rect[rectNr].Width = Convert.ToInt32(rect.Attribute("W").Value); mon[screenid].Rect[rectNr].Height = Convert.ToInt32(rect.Attribute("H").Value); // Console.WriteLine("Loading Rectangle " + rectNr + " with X = " + mon[screenid].Rect[rectNr].X + " and Y = " + mon[screenid].Rect[rectNr].Y + " ScreenId = " + screenid); rectNr++; } } // Find leds int id = 0; int numLed = leds.Count(); LedList = new LED[numLed]; r = new byte[numLed]; g = new byte[numLed]; b = new byte[numLed]; foreach (var led in leds) { LedList[id]._id = Convert.ToByte(led.Attribute("LedID").Value); // Set color LedList[id].Color = new byte[3]; LedList[id].Color[0] = Convert.ToByte(led.Element("Color").Attribute("R").Value); LedList[id].Color[1] = Convert.ToByte(led.Element("Color").Attribute("G").Value); LedList[id].Color[2] = Convert.ToByte(led.Element("Color").Attribute("B").Value); // Set intensity LedList[id].Intensity = new double[3]; LedList[id].Intensity[0] = Convert.ToDouble(led.Element("Intensity").Attribute("R").Value); LedList[id].Intensity[1] = Convert.ToDouble(led.Element("Intensity").Attribute("G").Value); LedList[id].Intensity[2] = Convert.ToDouble(led.Element("Intensity").Attribute("B").Value); //Set rectangleID LedList[id].RectID = Convert.ToInt32(led.Element("RectID").Attribute("Id").Value); // Test output //Console.WriteLine("Loading LED " + LedList[id]._id + ": " + "RectId = " + LedList[id].RectID); id++; } int RectTot = 0; for (int i = 0; i < mon.Length; i++) { RectTot += mon[i].Rect.Length; } avgRect = new byte[RectTot * 3]; // Initialise RGBdata array with numLed*3 + 2 and set start and stop byte RGBdata = new byte[leds.Count() * 3 + 2]; RGBdata[0] = 0x01; RGBdata[leds.Count() * 3 + 1] = 0x02; Console.WriteLine("Loading done..."); return(true); } catch (FileNotFoundException e) { return(false); } }