private void LoadButton_Click(object sender, EventArgs e) { if (hasChanged) { var result = MessageBox.Show("Are you sure?", "Confirm Load", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } } CustomPalette customPalette = comboBoxSavedPalettes.SelectedItem as CustomPalette; if (customPalette == null) { return; } BlendCheckBox.Checked = customPalette.Blend; AnimateCheckBox.Checked = customPalette.Animate; numericUpDown.Value = customPalette.increment; SelectSize(customPalette.paletteSize); for (int i = 0; i < 16; i++) { ColorsButtons[i].BackColor = customPalette.PatternColors[i]; } hasChanged = false; UpdatePalettePreview(); }
private void LoadConfigs() { try { SelectedComPort = Properties.Settings.Default.COMPort; AnalogComboBox.SelectedIndex = Properties.Settings.Default.AnalogLastMode; DigitalComboBox.SelectedIndex = Properties.Settings.Default.DigitalLastMode; foreach (Control item in AnalogCustomButtons) { if (item.BackColor.Equals(SystemColors.Control) == false) { AnalogCustomColors.Enqueue(item.BackColor); } } foreach (Control item in DigitalCustomButtons) { if (item.BackColor.Equals(SystemColors.Control) == false) { DigitalCustomColors.Enqueue(item.BackColor); } } Settings s = Settings.Load(); if (s == null) { return; } UpdateAnalogCustomButtons(); UpdateDigitalCustomButtons(); UpdateAnalogButtons(AnalogComboBox.SelectedItem as FirmataMode); UpdateDigitalButtons(DigitalComboBox.SelectedItem as FirmataMode); for (int i = 0; i < s.AnalogModesAvailable.Count; i++) { firmata.AnalogModesAvailable[i].Speed = s.AnalogModesAvailable[i].Speed; firmata.AnalogModesAvailable[i].Bright = s.AnalogModesAvailable[i].Bright; } for (int i = 0; i < s.DigitalModesAvailable.Count; i++) { firmata.DigitalModesAvailable[i].Speed = s.DigitalModesAvailable[i].Speed; firmata.DigitalModesAvailable[i].Bright = s.DigitalModesAvailable[i].Bright; } if (s.LastActivatedPalette != null) { LastActivatedPalette = s.LastActivatedPalette; } } catch (Exception e) { Console.WriteLine("Erro ao carregar configs: " + e.Message); } }
public void SetLastActivatePalette(CustomPalette customPalette) { if (customPalette == null) { return; } this._LastActivePalette = customPalette; }
private void SaveButton_Click(object sender, EventArgs e) { string name = comboBoxSavedPalettes.Text.Trim(); if (string.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name)) { MessageBox.Show("Enter a valid name.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Color[] BackColors = new Color[16]; for (int i = 0; i < 16; i++) { BackColors[i] = ColorsButtons[i].BackColor; } CustomPalette PaletteToSave = new CustomPalette(name, BackColors, AnimateCheckBox.Checked, BlendCheckBox.Checked, (byte)numericUpDown.Value, GetPaletteSize()); foreach (CustomPalette cp in comboBoxSavedPalettes.Items) { if (cp.Equals(PaletteToSave)) { var result = MessageBox.Show("There is already a custom palette named " + comboBoxSavedPalettes.SelectedItem.ToString() + ". Are you sure to overwrite?", "Confirm Overwrite", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } else { xmlHandler.ModifySavedPalette(PaletteToSave); MessageBox.Show("Save success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); hasChanged = false; return; } } } xmlHandler.AddPalette(PaletteToSave); UpdateSavedCombobox(); MessageBox.Show("Save success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); hasChanged = false; }
public void SendDigitalCustomPalette(CustomPalette customPalette) { if (customPalette == null || !Ready) { return; } //ensure that the cummunication channel is clear as possible //if analog musicalmode is active, it will not send any updates to analog strip //while a custom digital palette is being sent isSendingCustomPalette = true; //it will send 16 short messages for each color //then it will send a message with the properties byte[] command = new byte[11]; command[0] = 0xF0; command[1] = STRIP_DATA; command[2] = DIGITAL_CUSTOM_PALETTE; //payload bytes on for loop below command[10] = 0xF7; for (int i = 0; i < 16; i++) { command[3] = (byte)i; command[4] = (byte)(customPalette.PatternColors[i].R & 0x7F); command[5] = (byte)((customPalette.PatternColors[i].R >> 7) & 0x7F); command[6] = (byte)(customPalette.PatternColors[i].G & 0x7F); command[7] = (byte)((customPalette.PatternColors[i].G >> 7) & 0x7F); command[8] = (byte)(customPalette.PatternColors[i].B & 0x7F); command[9] = (byte)((customPalette.PatternColors[i].B >> 7) & 0x7F); FirmataSerialWrite(command, command.Length); } command = new byte[8]; command[0] = 0xF0; command[1] = STRIP_DATA; command[2] = DIGITAL_CUSTOM_PALETTE_PROPERTIES; command[3] = (customPalette.Blend) ? (byte)0x01 : (byte)0x00; command[4] = (customPalette.Animate) ? (byte)0x01 : (byte)0x00; command[5] = customPalette.increment; command[6] = (byte)customPalette.paletteSize; command[7] = 0xF7; FirmataSerialWrite(command, command.Length); isSendingCustomPalette = false; }
private void SendToArduinoButton_Click(object sender, EventArgs e) { Color[] BackColors = new Color[16]; for (int i = 0; i < 16; i++) { BackColors[i] = ColorsButtons[i].BackColor; } CustomPalette PaletteToSend = new CustomPalette("SentPalette", BackColors, AnimateCheckBox.Checked, BlendCheckBox.Checked, (byte)numericUpDown.Value, GetPaletteSize()); _LastActivePalette = PaletteToSend; _firmata.SendDigitalCustomPalette(PaletteToSend); }
public void AddPalette(CustomPalette cp) { XElement palette = new XElement("Palette"); palette.Add(new XAttribute("name", cp.Name)); palette.Add(new XAttribute("animated", cp.Animate)); palette.Add(new XAttribute("blend", cp.Blend)); palette.Add(new XAttribute("incr", cp.increment)); palette.Add(new XAttribute("palettesize", cp.paletteSize)); for (int i = 0; i < 16; i++) { palette.Add(new XAttribute(("color" + i), cp.PatternColors[i].ToArgb())); } xml.Add(palette); xml.Save(xmlPath); }
public List <CustomPalette> LoadSavedPalettes() { List <CustomPalette> LoadedPalettes = new List <CustomPalette>(); foreach (XElement x in xml.Elements()) { Color[] LoadedPaletteColors = new Color[16]; for (int i = 0; i < 16; i++) { LoadedPaletteColors[i] = Color.FromArgb(Convert.ToInt32(x.Attribute("color" + i).Value)); } CustomPalette.PaletteSize savedSize; if (x.Attribute("palettesize").Value == "P16") { savedSize = CustomPalette.PaletteSize.P16; } else if (x.Attribute("palettesize").Value == "P32") { savedSize = CustomPalette.PaletteSize.P32; } else { savedSize = CustomPalette.PaletteSize.P256; } CustomPalette loadedPalette = new CustomPalette(x.Attribute("name").Value, LoadedPaletteColors, Convert.ToBoolean(x.Attribute("animated").Value), Convert.ToBoolean(x.Attribute("blend").Value), Convert.ToByte(x.Attribute("incr").Value), savedSize ); LoadedPalettes.Add(loadedPalette); } return(LoadedPalettes); }
public void ModifySavedPalette(CustomPalette paletteToModify) { XElement x = xml.Elements().Where(p => p.Attribute("name").Value.Equals(paletteToModify.Name.ToString())).First(); if (x == null) { return; } else { x.Attribute("name").SetValue(paletteToModify.Name); x.Attribute("animated").SetValue(paletteToModify.Animate); x.Attribute("blend").SetValue(paletteToModify.Blend); x.Attribute("incr").SetValue(paletteToModify.increment); x.Attribute("palettesize").SetValue(paletteToModify.paletteSize); for (int i = 0; i < 16; i++) { x.Attribute("color" + i).SetValue(paletteToModify.PatternColors[i].ToArgb()); } xml.Save(xmlPath); } }