diff --git a/Base/ComboBoxHelper.cs b/Base/ComboBoxHelper.cs index 3810c57eb..269aac2c0 100644 --- a/Base/ComboBoxHelper.cs +++ b/Base/ComboBoxHelper.cs @@ -64,11 +64,12 @@ static public bool BindMobiFlightFreePins(ComboBox comboBox, List if (Pins == null) return false; // Deep-clone list as 'Used' list List UsablePins = Pins.ConvertAll(pin => new MobiFlightPin(pin)); - // Mark current pin as free - if (UsablePins.Exists(x => x.Pin == byte.Parse(CurrentPin))) + // Mark current pin (if any specified) as free + if (CurrentPin != "" && UsablePins.Exists(x => x.Pin == byte.Parse(CurrentPin))) { UsablePins.Find(x => x.Pin == byte.Parse(CurrentPin)).Used = false; + } - if (analogOnly == true) + if (analogOnly == true) { UsablePins = UsablePins.FindAll(x => x.isAnalog == true); } @@ -78,40 +79,81 @@ static public bool BindMobiFlightFreePins(ComboBox comboBox, List comboBox.DisplayMember = "Name"; comboBox.ValueMember = "Pin"; - // Restore the original item selection - comboBox.SelectedValue = byte.Parse(CurrentPin); + // Restore the original item selection (if any) + if (CurrentPin != "") { + var pinNo = byte.Parse(CurrentPin); + try { + comboBox.SelectedValue = pinNo; + } + catch { } + } return false; } - static public void reassignPin(ComboBox comboBox, List pinList, ref string signalPin) + static public void reassignPin(string newPin, List pinList, ref string currentPin) + { + // This function updates the config data (currentPin) with the new value passed. + // The assignment flags in the "base" pin list are accordingly updated + // (the current pin is marked as free and the new one as used) + try { + if (currentPin == newPin) return; + freePin(pinList, currentPin); + // Temporarily assign desired target - will remain this if available + string newCurrentPin = newPin; + assignPin(pinList, ref newCurrentPin); + // If no errors, confirm assignment of the new value in the configuration data + currentPin = newCurrentPin; + } + catch (Exception ex) { + Log.Instance.log($"Pin reassignment from {currentPin} to {newPin} went wrong: {ex.Message}", LogSeverity.Error); + } + + } + static public void freePin(List pinList, string currentPin) { - // This function updates the config data (signalPin) with the new value read from the ComboBox. - // At the same time: - // - the assignment flags in the "base" pin list are accordingly updated (the current pin no. is marked as free - // and the new one as used) - // - an updated pin list is associated to the ComboBox - string after = comboBox.SelectedItem.ToString(); - byte nBefore = byte.Parse(signalPin); - byte nAfter = byte.Parse(after); + byte nBefore = byte.Parse(currentPin); try { - if (signalPin != after) { - // Pin 0 is used for the stepper. - // But Pin 0 is not a correct Pin for the Mega. - if (pinList.Find(x => x.Pin == nBefore)!=null) - pinList.Find(x => x.Pin == nBefore).Used = false; - if (pinList.Find(x => x.Pin == nAfter)!=null) - pinList.Find(x => x.Pin == nAfter).Used = true; + MobiFlightPin p; + p = pinList.Find(x => x.Pin == nBefore); + if (p != null) p.Used = false; + } + catch (Exception ex) { + Log.Instance.log($"Release of pin {currentPin} went wrong: {ex.Message}", LogSeverity.Error); + } + } + static public void assignPin(List pinList, ref string newPin) + { + // This function tries to reserve the specified pin as newly occupied. + // If it is no longer available (or ""), the first free one will be assigned. + // If no more pins are available, an empty string is returned. + try { + MobiFlightPin p = null; + if (newPin != "") { + // A desired pin is specified: seek it + byte newPinNo = byte.Parse(newPin); + p = pinList.Find(x => x.Pin == newPinNo); + if (p == null) throw new Exception("Nonexistent pin number"); + } + if (newPin == "" || p.Used) { + // Either no desired pin is specified, or desired pin is not available: + // assign first free one + p = pinList.Find(x => x.Used == false); + // If no pin free, raise error + if(p == null) throw new ArgumentOutOfRangeException(); } + p.Used = true; + newPin = p.Pin.ToString(); + } + catch (ArgumentOutOfRangeException ex) { + MessageBox.Show(i18n._tr("uiMessageNotEnoughPinsMessage"), + i18n._tr("uiMessageNotEnoughPinsHint"), + MessageBoxButtons.OK, MessageBoxIcon.Error); + newPin = ""; } catch (Exception ex) { - Log.Instance.log($"Pin reassignment from {signalPin} to {after} went wrong: {ex.Message}", LogSeverity.Error); + Log.Instance.log($"Pin assignment to {newPin} went wrong: {ex.Message}", LogSeverity.Error); } - // now confirm assignment of the new value in the configuration data - signalPin = after; - - //ComboBoxHelper.BindMobiFlightFreePins(comboBox, pinList, after); - // the function above has rebuilt its datasource, therefore the ComboBox selection must be restored: - //comboBox.SelectedValue = nAfter; } + } } diff --git a/MobiFlight/Config/Compatibility/LedModuleDeprecated.cs b/MobiFlight/Config/Compatibility/LedModuleDeprecated.cs new file mode 100644 index 000000000..44ece62c4 --- /dev/null +++ b/MobiFlight/Config/Compatibility/LedModuleDeprecated.cs @@ -0,0 +1,72 @@ +using System; +using System.Linq; +using System.Xml.Serialization; + +namespace MobiFlight.Config +{ + public class LedModuleDeprecated : BaseDevice + { + const ushort _paramCount = 6; + [XmlAttribute] + public String DinPin = "-1"; + [XmlAttribute] + public String ClsPin = "-2"; + [XmlAttribute] + public String ClkPin = "-3"; + [XmlAttribute] + public Byte Brightness = 15; + [XmlAttribute] + public String NumModules = "1"; + + public LedModuleDeprecated() { Name = "LedModule"; _type = DeviceType.LedModule; } + + override public String ToInternal() + { + return base.ToInternal() + Separator + + DinPin + Separator + + ClsPin + Separator + + ClkPin + Separator + + Brightness + Separator + + NumModules + Separator + + Name + End; + } + + override public bool FromInternal(String value) + { + if (value.Length == value.IndexOf(End) + 1) value = value.Substring(0, value.Length - 1); + String[] paramList = value.Split(Separator); + if (paramList.Count() != _paramCount + 1) + { + throw new ArgumentException("Param count does not match. " + paramList.Count() + " given, " + _paramCount + " expected"); + } + DinPin = paramList[1]; + ClsPin = paramList[2]; + ClkPin = paramList[3]; + Byte.TryParse(paramList[4], out byte brightness); + Brightness = brightness; + NumModules = paramList[5]; + Name = paramList[6]; + + return true; + } + + public override bool Equals(object obj) + { + LedModuleDeprecated other = obj as LedModuleDeprecated; + if (other == null) + { + return false; + } + + return this.Name == other.Name + && this.DinPin == other.DinPin + && this.ClsPin == other.ClsPin + && this.ClkPin == other.ClkPin; + } + + public override string ToString() + { + return Type + ":" + Name + " DinPin:" + DinPin + " ClsPin:" + ClsPin + " ClkPin:" + ClkPin; + } + } +} diff --git a/MobiFlight/Config/Config.cs b/MobiFlight/Config/Config.cs index b27aac4bd..463856622 100644 --- a/MobiFlight/Config/Config.cs +++ b/MobiFlight/Config/Config.cs @@ -1,8 +1,6 @@ using MobiFlight.Config.Compatibility; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Xml.Serialization; namespace MobiFlight.Config @@ -133,6 +131,13 @@ public Config FromInternal(String value, bool throwException = false) currentItem.FromInternal(item + BaseDevice.End); break; + // backward compatibility + case DeviceType.LedModuleDeprecated: + currentItem = new MobiFlight.Config.LedModuleDeprecated(); + currentItem.FromInternal(item + BaseDevice.End); + currentItem = new MobiFlight.Config.LedModule(currentItem as MobiFlight.Config.LedModuleDeprecated); + break; + case DeviceType.LcdDisplay: currentItem = new MobiFlight.Config.LcdDisplay(); currentItem.FromInternal(item + BaseDevice.End); diff --git a/MobiFlight/Config/LedModule.cs b/MobiFlight/Config/LedModule.cs index 7ea1e9f6d..221bce9a6 100644 --- a/MobiFlight/Config/LedModule.cs +++ b/MobiFlight/Config/LedModule.cs @@ -1,14 +1,18 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Xml.Serialization; namespace MobiFlight.Config { public class LedModule : BaseDevice { - const ushort _paramCount = 6; + public const string MODEL_TYPE_MAX72xx = "1"; + public const string MODEL_TYPE_TM1637_4DIGIT = "253"; + public const string MODEL_TYPE_TM1637_6DIGIT = "254"; + + const ushort _paramCount = 7; + [XmlAttribute] + public String ModelType = MODEL_TYPE_MAX72xx; [XmlAttribute] public String DinPin = "-1"; [XmlAttribute] @@ -22,9 +26,22 @@ public class LedModule : BaseDevice public LedModule() { Name = "LedModule"; _type = DeviceType.LedModule; } + public LedModule(LedModuleDeprecated module) + { + Name = module.Name; + _type = DeviceType.LedModule; + ModelType = MODEL_TYPE_MAX72xx; + DinPin = module.DinPin; + ClsPin = module.ClsPin; + ClkPin = module.ClkPin; + Brightness = module.Brightness; + NumModules = module.NumModules; + } + override public String ToInternal() { return base.ToInternal() + Separator + + ModelType + Separator + DinPin + Separator + ClsPin + Separator + ClkPin + Separator @@ -41,15 +58,14 @@ override public bool FromInternal(String value) { throw new ArgumentException("Param count does not match. " + paramList.Count() + " given, " + _paramCount + " expected"); } - - DinPin = paramList[1]; - ClsPin = paramList[2]; - ClkPin = paramList[3]; - byte brightness = 15; - Byte.TryParse(paramList[4], out brightness); + ModelType = paramList[1]; + DinPin = paramList[2]; + ClsPin = paramList[3]; + ClkPin = paramList[4]; + Byte.TryParse(paramList[5], out byte brightness); Brightness = brightness; - NumModules = paramList[5]; - Name = paramList[6]; + NumModules = paramList[6]; + Name = paramList[7]; return true; } @@ -63,14 +79,24 @@ public override bool Equals(object obj) } return this.Name == other.Name + && this.ModelType == other.ModelType && this.DinPin == other.DinPin && this.ClsPin == other.ClsPin - && this.ClkPin == other.ClkPin; + && this.ClkPin == other.ClkPin + && this.NumModules == other.NumModules + && this.Brightness == other.Brightness; } public override string ToString() { - return Type + ":" + Name + " DinPin:" + DinPin + " ClsPin:" + ClsPin + " ClkPin:" + ClkPin; + return Type + ":" + Name + + " TypeId:" + ModelType + + " DinPin:" + DinPin + + " ClsPin:" + ClsPin + + " ClkPin:" + ClkPin + + " Brightness:" + Brightness + + " NumModules:" + NumModules; + } } } diff --git a/MobiFlight/MobiFlightLedModule.cs b/MobiFlight/MobiFlightLedModule.cs index c29018565..0c2178839 100644 --- a/MobiFlight/MobiFlightLedModule.cs +++ b/MobiFlight/MobiFlightLedModule.cs @@ -1,15 +1,10 @@ -using System; +using CommandMessenger; +using MobiFlight.Base; +using MobiFlight.Config; +using System; using System.Collections.Generic; -using System.Data.SqlTypes; -using System.Drawing; using System.Linq; -using System.Text; using System.Text.RegularExpressions; -using System.Windows.Forms.Design; -using CommandMessenger; -using MobiFlight.Base; -using Newtonsoft.Json.Linq; -using SharpDX.DirectInput; namespace MobiFlight { @@ -31,6 +26,7 @@ public int SubModules ClearState(); } } + public string ModelType { get; set; } List _state = new List(); @@ -55,6 +51,7 @@ public MobiFlightLedModule() { Brightness = 15; SubModules = 1; + ModelType = LedModule.MODEL_TYPE_MAX72xx; } protected void Initialize() @@ -67,6 +64,8 @@ public void Display(int subModule, String value, byte points, byte mask, bool re { if (!_initialized) Initialize(); + if (subModule > 1 && ModelType != LedModule.MODEL_TYPE_MAX72xx) return; + var command = new SendCommand((int)MobiFlightModule.Command.SetModule); if (value.IndexOf(".") >=0 ) diff --git a/MobiFlight/MobiFlightModule.cs b/MobiFlight/MobiFlightModule.cs index a3d3ba183..7ce0be9e9 100644 --- a/MobiFlight/MobiFlightModule.cs +++ b/MobiFlight/MobiFlightModule.cs @@ -28,6 +28,7 @@ public class FirmwareFeature { public const string GenerateSerial = "1.3.0"; public const string SetName = "1.6.0"; + public const string LedModuleTypeTM1637 = "2.5.0"; } // This is the list of recognized commands. These can be commands that can either be sent or received. @@ -38,7 +39,7 @@ public enum DeviceType Button, // 1 EncoderSingleDetent, // 2 (retained for backwards compatibility, use Encoder for new configs) Output, // 3 - LedModule, // 4 + LedModuleDeprecated, // 4 StepperDeprecatedV1, // 5 Servo, // 6 LcdDisplay, // 7 @@ -49,7 +50,8 @@ public enum DeviceType InputShiftRegister, // 12 MultiplexerDriver, // 13 Not a proper device, but index required for update events InputMultiplexer, // 14 - Stepper // 15 + Stepper, // 15 + LedModule } public class MobiFlightModule : IModule, IOutputModule @@ -249,9 +251,9 @@ public MobiFlightModule(String port, Board board) public MobiFlightModule(MobiFlightModuleInfo moduleInfo) { - Name = "Default"; - Version = null; // this is simply unknown, in case of an unflashed Arduino - Serial = null; // this is simply unknown, in case of an unflashed Arduino + Name = moduleInfo.Name ?? "Default"; + Version = moduleInfo.Version; + Serial = moduleInfo.Serial; _comPort = moduleInfo.Port; Board = moduleInfo.Board; HardwareId = moduleInfo.HardwareId; @@ -343,11 +345,14 @@ public void LoadConfig() } device.Name = GenerateUniqueDeviceName(ledModules.Keys.ToArray(), device.Name); + var dev = device as Config.LedModule; + ledModules.Add(device.Name, new MobiFlightLedModule() { CmdMessenger = _cmdMessenger, Name = device.Name, ModuleNumber = ledModules.Count, + ModelType = dev.ModelType, SubModules = ledSubmodules, Brightness = (device as Config.LedModule).Brightness }); @@ -1255,7 +1260,11 @@ public List GetPins(bool FreeOnly = false, bool ExcludeI2CDevices { case DeviceType.LedModule: usedPins.Add(Convert.ToByte((device as LedModule).ClkPin)); - usedPins.Add(Convert.ToByte((device as LedModule).ClsPin)); + if ((device as LedModule).ModelType == LedModule.MODEL_TYPE_MAX72xx) + { + if ((device as LedModule).ClsPin != "") + usedPins.Add(Convert.ToByte((device as LedModule).ClsPin)); + } usedPins.Add(Convert.ToByte((device as LedModule).DinPin)); break; @@ -1340,7 +1349,10 @@ public List GetPins(bool FreeOnly = false, bool ExcludeI2CDevices } // Mark all the used pins as used in the result list. - usedPins.ForEach(pin => ResultPins.Find(resultPin => resultPin.Pin == pin).Used = true); + foreach (byte pinNo in usedPins) { + MobiFlightPin pin = ResultPins.Find(resultPin => resultPin.Pin == pinNo); + if (pin != null) pin.Used = true; + } if (FreeOnly) ResultPins = ResultPins.FindAll(x => x.Used == false); diff --git a/MobiFlightConnector.csproj b/MobiFlightConnector.csproj index 5f5e1d3dc..66c61d10b 100644 --- a/MobiFlightConnector.csproj +++ b/MobiFlightConnector.csproj @@ -246,6 +246,7 @@ + diff --git a/MobiFlightUnitTests/MobiFlight/Config/ConfigTests.cs b/MobiFlightUnitTests/MobiFlight/Config/ConfigTests.cs index a4347a33b..b651f9560 100644 --- a/MobiFlightUnitTests/MobiFlight/Config/ConfigTests.cs +++ b/MobiFlightUnitTests/MobiFlight/Config/ConfigTests.cs @@ -76,7 +76,7 @@ public void ledModuleDeserializeTest() { Config o = new Config(); - Assert.AreEqual(1, o.FromInternal("4.0.1.2.3.4.Device:").Items.Count); + Assert.AreEqual(1, o.FromInternal("16.1.0.1.2.3.4.Device:").Items.Count); LedModule expected = new LedModule(); expected.Name = "Device"; @@ -202,6 +202,7 @@ public void combinedDeserializeTest() expected3.Pin = "0"; LedModule expected4 = new LedModule(); + expected4.ModelType = LedModule.MODEL_TYPE_MAX72xx; expected4.Name = "Device4"; expected4.DinPin = "0"; expected4.ClsPin = "1"; @@ -324,7 +325,7 @@ public void ledModuleSerializeTest() List actual = o.ToInternal(100); Assert.AreEqual(1, actual.Count); - Assert.AreEqual("4.0.1.2.3.4.Device:", actual.ElementAt(0)); + Assert.AreEqual("16.1.0.1.2.3.4.Device:", actual.ElementAt(0)); } [TestMethod()] @@ -437,6 +438,7 @@ public void combinedSerializeTest() LedModule device4 = new LedModule(); device4.Name = "Device4"; + device4.ModelType = LedModule.MODEL_TYPE_MAX72xx; device4.DinPin = "0"; device4.ClsPin = "1"; device4.ClkPin = "2"; @@ -486,7 +488,7 @@ public void combinedSerializeTest() "1.0.Device1:" + "8.0.1.0.Device2:" + "3.0.Device3:" - + "4.0.1.2.3.4.Device4:" + + $"{(int)DeviceType.LedModule}.1.0.1.2.3.4.Device4:" + "15.0.1.2.3.0.0.0.0.0.Device5:" + "6.0.Device6:" + "7.0.1.2.Device7:" @@ -565,7 +567,7 @@ public void combinedSmallSerializeTest() Assert.AreEqual("1.0.Device1:", actual.ElementAt(0)); Assert.AreEqual("8.0.1.0.Device2:", actual.ElementAt(1)); Assert.AreEqual("3.0.Device3:", actual.ElementAt(2)); - Assert.AreEqual("4.0.1.2.3.4.Device4:", actual.ElementAt(3)); + Assert.AreEqual($"{(int)DeviceType.LedModule}.1.0.1.2.3.4.Device4:", actual.ElementAt(3)); Assert.AreEqual("15.0.1.2.3.0.0.0.0.0.Device5:", actual.ElementAt(4)); Assert.AreEqual("6.0.Device6:", actual.ElementAt(5)); Assert.AreEqual("7.0.1.2.Device7:", actual.ElementAt(6)); diff --git a/UI/Panels/Device/MFEncoderPanel.cs b/UI/Panels/Device/MFEncoderPanel.cs index be6df911b..8619a4053 100644 --- a/UI/Panels/Device/MFEncoderPanel.cs +++ b/UI/Panels/Device/MFEncoderPanel.cs @@ -61,8 +61,12 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) // First update the one that is changed // Here, the config data (encoder.XXXPin) is updated with the new value read from the changed ComboBox; - if (comboBox == mfLeftPinComboBox) { ComboBoxHelper.reassignPin(mfLeftPinComboBox, pinList, ref encoder.PinLeft); } else - if (comboBox == mfRightPinComboBox) { ComboBoxHelper.reassignPin(mfRightPinComboBox, pinList, ref encoder.PinRight); } + if (comboBox == mfLeftPinComboBox) { + ComboBoxHelper.reassignPin(mfLeftPinComboBox.SelectedItem.ToString(), pinList, ref encoder.PinLeft); + } else + if (comboBox == mfRightPinComboBox) { + ComboBoxHelper.reassignPin(mfRightPinComboBox.SelectedItem.ToString(), pinList, ref encoder.PinRight); + } // then the others are updated too UpdateFreePinsInDropDowns(); diff --git a/UI/Panels/Device/MFInputMultiplexerPanel.cs b/UI/Panels/Device/MFInputMultiplexerPanel.cs index 430b833d9..9cacab6cd 100644 --- a/UI/Panels/Device/MFInputMultiplexerPanel.cs +++ b/UI/Panels/Device/MFInputMultiplexerPanel.cs @@ -105,7 +105,9 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) // First update the one that is changed // Here, the config data (inputMultiplexer.DataPin) is updated with the new value read from the changed ComboBox; - if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(mfPin1ComboBox, pinList, ref inputMultiplexer.DataPin); } + if (comboBox == mfPin1ComboBox) { + ComboBoxHelper.reassignPin(mfPin1ComboBox.SelectedItem.ToString(), pinList, ref inputMultiplexer.DataPin); + } UpdateFreePinsInDropDowns(); initialized = exInitialized; diff --git a/UI/Panels/Device/MFInputShiftRegisterPanel.cs b/UI/Panels/Device/MFInputShiftRegisterPanel.cs index e1e963af8..404acc07d 100644 --- a/UI/Panels/Device/MFInputShiftRegisterPanel.cs +++ b/UI/Panels/Device/MFInputShiftRegisterPanel.cs @@ -68,9 +68,10 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) // First update the one that is changed // Here, the config data (shiftRegister.XXXPin) is updated with the new value read from the changed ComboBox; - if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(mfPin1ComboBox, pinList, ref inputShiftRegister.LatchPin); } else - if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(mfPin2ComboBox, pinList, ref inputShiftRegister.ClockPin); } else - if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(mfPin3ComboBox, pinList, ref inputShiftRegister.DataPin); } + var newPin = comboBox.SelectedItem.ToString(); + if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref inputShiftRegister.LatchPin); } else + if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref inputShiftRegister.ClockPin); } else + if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref inputShiftRegister.DataPin); } // then the others are updated too UpdateFreePinsInDropDowns(); diff --git a/UI/Panels/Device/MFLedSegmentPanel.Designer.cs b/UI/Panels/Device/MFLedSegmentPanel.Designer.cs index 3810831ee..96d9787e9 100644 --- a/UI/Panels/Device/MFLedSegmentPanel.Designer.cs +++ b/UI/Panels/Device/MFLedSegmentPanel.Designer.cs @@ -45,10 +45,13 @@ private void InitializeComponent() this.mfIntensityTrackBar = new System.Windows.Forms.TrackBar(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.textBox1 = new System.Windows.Forms.TextBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.mfDisplayTypeComboBox = new System.Windows.Forms.ComboBox(); this.groupBox1.SuspendLayout(); this.mfIntensityGroupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.mfIntensityTrackBar)).BeginInit(); this.groupBox2.SuspendLayout(); + this.groupBox3.SuspendLayout(); this.SuspendLayout(); // // groupBox1 @@ -153,7 +156,6 @@ private void InitializeComponent() // // mfIntensityTrackBar // - this.mfIntensityTrackBar.BackColor = System.Drawing.SystemColors.ControlLightLight; resources.ApplyResources(this.mfIntensityTrackBar, "mfIntensityTrackBar"); this.mfIntensityTrackBar.Maximum = 15; this.mfIntensityTrackBar.Minimum = 1; @@ -174,6 +176,21 @@ private void InitializeComponent() this.textBox1.Name = "textBox1"; this.textBox1.TextChanged += new System.EventHandler(this.value_Changed); // + // groupBox3 + // + this.groupBox3.Controls.Add(this.mfDisplayTypeComboBox); + resources.ApplyResources(this.groupBox3, "groupBox3"); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.TabStop = false; + // + // mfDisplayTypeComboBox + // + this.mfDisplayTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.mfDisplayTypeComboBox.FormattingEnabled = true; + resources.ApplyResources(this.mfDisplayTypeComboBox, "mfDisplayTypeComboBox"); + this.mfDisplayTypeComboBox.Name = "mfDisplayTypeComboBox"; + this.mfDisplayTypeComboBox.SelectedValueChanged += new System.EventHandler(this.mfDisplayTypeComboBox_SelectedValueChanged); + // // MFLedSegmentPanel // resources.ApplyResources(this, "$this"); @@ -181,6 +198,7 @@ private void InitializeComponent() this.Controls.Add(this.groupBox2); this.Controls.Add(this.mfIntensityGroupBox); this.Controls.Add(this.groupBox1); + this.Controls.Add(this.groupBox3); this.Name = "MFLedSegmentPanel"; this.groupBox1.ResumeLayout(false); this.mfIntensityGroupBox.ResumeLayout(false); @@ -188,28 +206,30 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.mfIntensityTrackBar)).EndInit(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); + this.groupBox3.ResumeLayout(false); this.ResumeLayout(false); } #endregion + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.GroupBox mfIntensityGroupBox; private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Label mfPin1Label; private System.Windows.Forms.ComboBox mfPin1ComboBox; private System.Windows.Forms.Label mfPin2Label; private System.Windows.Forms.ComboBox mfPin2ComboBox; - private System.Windows.Forms.GroupBox mfIntensityGroupBox; private System.Windows.Forms.TrackBar mfIntensityTrackBar; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label mfPin3Label; private System.Windows.Forms.ComboBox mfPin3ComboBox; - private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label numberOfModulesLabel; private System.Windows.Forms.ComboBox mfNumModulesComboBox; - + private System.Windows.Forms.ComboBox mfDisplayTypeComboBox; } } diff --git a/UI/Panels/Device/MFLedSegmentPanel.cs b/UI/Panels/Device/MFLedSegmentPanel.cs index 676dfa52c..d0ff8b1fe 100644 --- a/UI/Panels/Device/MFLedSegmentPanel.cs +++ b/UI/Panels/Device/MFLedSegmentPanel.cs @@ -1,32 +1,32 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Data; -using System.Linq; -using System.Text; using System.Windows.Forms; +using MobiFlight.Config; namespace MobiFlight.UI.Panels.Settings.Device { public partial class MFLedSegmentPanel : UserControl { - private MobiFlight.Config.LedModule ledModule; + private LedModule ledModule; private List pinList; // COMPLETE list of pins (includes status) private bool initialized = false; - + string currentMode; + private string OldMaxClsPin = ""; + public bool SupportsTM1637 { get; set; } = false; + public event EventHandler Changed; public MFLedSegmentPanel() { InitializeComponent(); + UpdateTrackBarBackgroundColor(); + InitializeDisplayTypeComboBox(); mfPin1ComboBox.Items.Clear(); mfPin2ComboBox.Items.Clear(); mfPin3ComboBox.Items.Clear(); - if (Parent != null) mfIntensityTrackBar.BackColor = Parent.BackColor; } - public MFLedSegmentPanel(MobiFlight.Config.LedModule ledModule, List Pins) : this() + public MFLedSegmentPanel(LedModule ledModule, List Pins, bool supportsTM1637) : this() { pinList = Pins; // Keep pin list stored // Since the panel is synced whenever a new device is selected, the free/used list won't change @@ -34,27 +34,88 @@ public MFLedSegmentPanel(MobiFlight.Config.LedModule ledModule, List languageOptions = new List + { + new ListItem() { Value = LedModule.MODEL_TYPE_MAX72xx, Label = "MAX7219 / MAX7221" }, + new ListItem() { Value = LedModule.MODEL_TYPE_TM1637_4DIGIT, Label = "TM1637 - 4 digits" }, + new ListItem() { Value = LedModule.MODEL_TYPE_TM1637_6DIGIT, Label = "TM1637 - 6 digits" } + }; + mfDisplayTypeComboBox.DataSource = languageOptions; + mfDisplayTypeComboBox.DisplayMember = "Label"; + mfDisplayTypeComboBox.ValueMember = "Value"; + mfDisplayTypeComboBox.SelectedIndex = 0; + } + + public void UpdateTrackBarBackgroundColor() + { + mfIntensityTrackBar.BackColor = System.Drawing.Color.FromArgb(255,249,249,249); + } + + private bool isMax() + { + return mfDisplayTypeComboBox.SelectedValue.ToString() == LedModule.MODEL_TYPE_MAX72xx; } private void setNonPinValues() { ledModule.Name = textBox1.Text; ledModule.Brightness = (byte)(mfIntensityTrackBar.Value); - ledModule.NumModules = mfNumModulesComboBox.Text; + ledModule.NumModules = isMax()? mfNumModulesComboBox.Text : "1"; + } + private void setMAXMode(String mode) // bool MAXmode) + { + ledModule.ModelType = mode; + + var MAXmode = (mode == LedModule.MODEL_TYPE_MAX72xx); + + mfPin2ComboBox.Visible = MAXmode; + mfNumModulesComboBox.Visible = MAXmode; + mfPin2Label.Visible = MAXmode; + numberOfModulesLabel.Visible = MAXmode; + label3.Visible = MAXmode; + } + private void changeMAXMode(String mode) + { + setMAXMode(mode); + if (mode == LedModule.MODEL_TYPE_MAX72xx) { + // First try and see if the "old" pin is still available, otherwise assign the first free one + ledModule.ClsPin = OldMaxClsPin; + ComboBoxHelper.assignPin(pinList, ref ledModule.ClsPin); + UpdateFreePinsInDropDowns(); + } else { + if(currentMode == LedModule.MODEL_TYPE_MAX72xx) OldMaxClsPin = ledModule.ClsPin; + // "freePin()" is the first half part only of "ReassignFreePinsInDropDowns()" + if (ledModule.ClsPin != "") { + ComboBoxHelper.freePin(pinList, ledModule.ClsPin); + } + // Make sure to use a neutral value + ledModule.ClsPin = "0"; + UpdateFreePinsInDropDowns(); + } + currentMode = mode; + if (Changed != null) + Changed(ledModule, new EventArgs()); } private void UpdateFreePinsInDropDowns() { bool exInitialized = initialized; initialized = false; // inhibit value_Changed events ComboBoxHelper.BindMobiFlightFreePins(mfPin1ComboBox, pinList, ledModule.DinPin); - ComboBoxHelper.BindMobiFlightFreePins(mfPin2ComboBox, pinList, ledModule.ClsPin); + if(isMax()) ComboBoxHelper.BindMobiFlightFreePins(mfPin2ComboBox, pinList, ledModule.ClsPin); ComboBoxHelper.BindMobiFlightFreePins(mfPin3ComboBox, pinList, ledModule.ClkPin); initialized = exInitialized; } @@ -66,9 +127,10 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) // First update the one that is changed // Here, the config data (ledModule.XXXPin) is updated with the new value read from the changed ComboBox; - if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(mfPin1ComboBox, pinList, ref ledModule.DinPin); } else - if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(mfPin2ComboBox, pinList, ref ledModule.ClsPin); } else - if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(mfPin3ComboBox, pinList, ref ledModule.ClkPin); } + var newPin = comboBox.SelectedItem.ToString(); + if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref ledModule.DinPin); } else + if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref ledModule.ClsPin); } else + if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref ledModule.ClkPin); } // then the others are updated too UpdateFreePinsInDropDowns(); @@ -78,10 +140,30 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) private void value_Changed(object sender, EventArgs e) { if (!initialized) return; - ReassignFreePinsInDropDowns(sender as ComboBox); + if(sender == mfPin1ComboBox || sender == mfPin2ComboBox || sender == mfPin3ComboBox) { + ReassignFreePinsInDropDowns(sender as ComboBox); + } setNonPinValues(); if (Changed != null) Changed(ledModule, new EventArgs()); } + + private void mfDisplayTypeComboBox_SelectedValueChanged(object sender, EventArgs e) + { + if (!initialized) return; + + string newMode = (sender as ComboBox).SelectedValue.ToString(); + + if (newMode != LedModule.MODEL_TYPE_MAX72xx && !SupportsTM1637) + { + MessageBox.Show(i18n._tr("uiMessageSettingsDialogFirmwareVersionTooLowException"), i18n._tr("Hint")); + mfDisplayTypeComboBox.SelectedValue = LedModule.MODEL_TYPE_MAX72xx; + return; + } + + changeMAXMode(newMode); + + Changed?.Invoke(ledModule, new EventArgs()); + } } } diff --git a/UI/Panels/Device/MFLedSegmentPanel.resx b/UI/Panels/Device/MFLedSegmentPanel.resx index 3dbaa64cd..8f79c0bef 100644 --- a/UI/Panels/Device/MFLedSegmentPanel.resx +++ b/UI/Panels/Device/MFLedSegmentPanel.resx @@ -117,6 +117,144 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + mfNumModulesComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 0 + + + label3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 1 + + + numberOfModulesLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 2 + + + mfPin1Label + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 3 + + + mfPin1ComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 4 + + + mfPin3Label + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 5 + + + mfPin3ComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 6 + + + mfPin2Label + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 7 + + + mfPin2ComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 8 + + + + Top + + + + 0, 50 + + + 236, 75 + + + + 2 + + + Pin settings and number of modules + + + groupBox1 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + 1 @@ -141,14 +279,12 @@ 8 - - 168, 38 + 176, 38 38, 21 - 21 @@ -165,7 +301,7 @@ 0 - 156, 41 + 164, 41 11, 11 @@ -189,7 +325,7 @@ 1 - 167, 21 + 175, 21 32, 11 @@ -213,7 +349,7 @@ 2 - 8, 21 + 16, 21 32, 11 @@ -237,7 +373,7 @@ 3 - 9, 38 + 17, 38 45, 21 @@ -258,7 +394,7 @@ 4 - 110, 21 + 118, 21 32, 11 @@ -282,7 +418,7 @@ 5 - 111, 38 + 119, 38 45, 21 @@ -303,7 +439,7 @@ 6 - 59, 21 + 67, 21 41, 11 @@ -327,7 +463,7 @@ 7 - 60, 38 + 68, 38 45, 21 @@ -347,34 +483,6 @@ 8 - - - Top - - - 0, 0 - - - 212, 68 - - - 1 - - - Pin settings and number of modules - - - groupBox1 - - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 2 - label2 @@ -415,13 +523,16 @@ Top - 0, 68 + 0, 125 + + + 17, 3, 17, 3 - 212, 66 + 236, 66 - 2 + 3 Global intensity @@ -442,10 +553,10 @@ Top, Right - 140, 42 + 167, 42 - 63, 18 + 66, 18 20 @@ -493,13 +604,13 @@ 1 - Fill + Top - 3, 16 + 17, 16 - 206, 47 + 202, 45 0 @@ -532,13 +643,13 @@ Top - 0, 134 + 0, 191 - 212, 48 + 236, 53 - 6 + 4 Name @@ -576,6 +687,54 @@ 0 + + 18, 19 + + + 151, 21 + + + 3 + + + mfDisplayTypeComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox3 + + + 0 + + + Top + + + 0, 0 + + + 236, 50 + + + 1 + + + Type + + + groupBox3 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + True @@ -586,7 +745,7 @@ True - 212, 214 + 236, 284 MFLedSegmentPanel diff --git a/UI/Panels/Device/MFMultiplexerDriverSubPanel.cs b/UI/Panels/Device/MFMultiplexerDriverSubPanel.cs index 67b05f29a..f00054c1c 100644 --- a/UI/Panels/Device/MFMultiplexerDriverSubPanel.cs +++ b/UI/Panels/Device/MFMultiplexerDriverSubPanel.cs @@ -84,13 +84,11 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) // First update the one that is changed // Here, the config data (multiplexerDriver.PinSx[]) is updated with the new value read from the changed ComboBox; - if (comboBox == mfPinS0ComboBox) { ComboBoxHelper.reassignPin(mfPinS0ComboBox, pinList, ref this.multiplexerDriver.PinSx[0]); } - else - if (comboBox == mfPinS1ComboBox) { ComboBoxHelper.reassignPin(mfPinS1ComboBox, pinList, ref this.multiplexerDriver.PinSx[1]); } - else - if (comboBox == mfPinS2ComboBox) { ComboBoxHelper.reassignPin(mfPinS2ComboBox, pinList, ref this.multiplexerDriver.PinSx[2]); } - else - if (comboBox == mfPinS3ComboBox) { ComboBoxHelper.reassignPin(mfPinS3ComboBox, pinList, ref this.multiplexerDriver.PinSx[3]); } + var newPin = comboBox.SelectedItem.ToString(); + if (comboBox == mfPinS0ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref this.multiplexerDriver.PinSx[0]); } else + if (comboBox == mfPinS1ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref this.multiplexerDriver.PinSx[1]); } else + if (comboBox == mfPinS2ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref this.multiplexerDriver.PinSx[2]); } else + if (comboBox == mfPinS3ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref this.multiplexerDriver.PinSx[3]); } // then the others are updated too UpdateFreePinsInDropDowns(); diff --git a/UI/Panels/Device/MFShiftRegisterPanel.cs b/UI/Panels/Device/MFShiftRegisterPanel.cs index 936569aec..b1418796a 100644 --- a/UI/Panels/Device/MFShiftRegisterPanel.cs +++ b/UI/Panels/Device/MFShiftRegisterPanel.cs @@ -62,9 +62,10 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) // First update the one that is changed // Here, the config data (shiftRegister.XXXPin) is updated with the new value read from the changed ComboBox; - if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(mfPin1ComboBox, pinList, ref shiftRegister.LatchPin); } else - if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(mfPin2ComboBox, pinList, ref shiftRegister.ClockPin); } else - if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(mfPin3ComboBox, pinList, ref shiftRegister.DataPin); } + var newPin = comboBox.SelectedItem.ToString(); + if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref shiftRegister.LatchPin); } else + if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref shiftRegister.ClockPin); } else + if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref shiftRegister.DataPin); } // then the others are updated too UpdateFreePinsInDropDowns(); diff --git a/UI/Panels/Device/MFStepperPanel.cs b/UI/Panels/Device/MFStepperPanel.cs index 96bf8ab9e..390303315 100644 --- a/UI/Panels/Device/MFStepperPanel.cs +++ b/UI/Panels/Device/MFStepperPanel.cs @@ -120,8 +120,8 @@ private void ModeComboBox_SelectedValueChanged(object sender, EventArgs e) { // with this mode Pin1 and Pin3 are the same // with this mode Pin2 and Pin4 are the same - ComboBoxHelper.reassignPin(mfPin1ComboBox, pinList, ref stepper.Pin3); - ComboBoxHelper.reassignPin(mfPin2ComboBox, pinList, ref stepper.Pin4); + ComboBoxHelper.reassignPin(mfPin1ComboBox.SelectedItem.ToString(), pinList, ref stepper.Pin3); + ComboBoxHelper.reassignPin(mfPin2ComboBox.SelectedItem.ToString(), pinList, ref stepper.Pin4); } else if (stepper.Pin3 == stepper.Pin1 && stepper.Pin4 == stepper.Pin2) { // we are switching back from an Easy Driver config // so we have to assign two available pins @@ -237,18 +237,19 @@ private void ReassignFreePinsInDropDowns(ComboBox comboBox) bool exInitialized = initialized; initialized = false; // inhibit value_Changed events + var newPin = comboBox.SelectedItem.ToString(); // First update the one that is changed // Here, the config data (stepper.XXXPin) is updated with the new value read from the changed ComboBox; - if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(mfPin1ComboBox, pinList, ref stepper.Pin1); } - if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(mfPin2ComboBox, pinList, ref stepper.Pin2); } + if (comboBox == mfPin1ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref stepper.Pin1); } else + if (comboBox == mfPin2ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref stepper.Pin2); } if ((StepperMode)ModeComboBox.SelectedValue != StepperMode.DRIVER) { - if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(mfPin3ComboBox, pinList, ref stepper.Pin3); } - if (comboBox == mfPin4ComboBox) { ComboBoxHelper.reassignPin(mfPin4ComboBox, pinList, ref stepper.Pin4); } + if (comboBox == mfPin3ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref stepper.Pin3); } else + if (comboBox == mfPin4ComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref stepper.Pin4); } } - if (comboBox == mfBtnPinComboBox) { ComboBoxHelper.reassignPin(mfBtnPinComboBox, pinList, ref stepper.BtnPin); } + if (comboBox == mfBtnPinComboBox) { ComboBoxHelper.reassignPin(newPin, pinList, ref stepper.BtnPin); } // then the others are updated too UpdateFreePinsInDropDowns(); diff --git a/UI/Panels/Output/DisplayLedDisplayPanel.Designer.cs b/UI/Panels/Output/DisplayLedDisplayPanel.Designer.cs index 8bee61c13..eb55e5085 100644 --- a/UI/Panels/Output/DisplayLedDisplayPanel.Designer.cs +++ b/UI/Panels/Output/DisplayLedDisplayPanel.Designer.cs @@ -144,7 +144,6 @@ private void InitializeComponent() // // displayLedDecimalPointFlowLayoutPanel // - resources.ApplyResources(this.displayLedDecimalPointFlowLayoutPanel, "displayLedDecimalPointFlowLayoutPanel"); this.displayLedDecimalPointFlowLayoutPanel.Controls.Add(this.displayLedDecimalPoint7CheckBox); this.displayLedDecimalPointFlowLayoutPanel.Controls.Add(this.displayLedDecimalPoint6CheckBox); this.displayLedDecimalPointFlowLayoutPanel.Controls.Add(this.displayLedDecimalPoint5CheckBox); @@ -153,6 +152,7 @@ private void InitializeComponent() this.displayLedDecimalPointFlowLayoutPanel.Controls.Add(this.displayLedDecimalPoint2CheckBox); this.displayLedDecimalPointFlowLayoutPanel.Controls.Add(this.displayLedDecimalPoint1CheckBox); this.displayLedDecimalPointFlowLayoutPanel.Controls.Add(this.displayLedDecimalPoint0CheckBox); + resources.ApplyResources(this.displayLedDecimalPointFlowLayoutPanel, "displayLedDecimalPointFlowLayoutPanel"); this.displayLedDecimalPointFlowLayoutPanel.Name = "displayLedDecimalPointFlowLayoutPanel"; // // displayLedDecimalPoint4CheckBox @@ -199,7 +199,6 @@ private void InitializeComponent() // // displayLedDigitFlowLayoutPanel // - resources.ApplyResources(this.displayLedDigitFlowLayoutPanel, "displayLedDigitFlowLayoutPanel"); this.displayLedDigitFlowLayoutPanel.Controls.Add(this.displayLedDigit7CheckBox); this.displayLedDigitFlowLayoutPanel.Controls.Add(this.displayLedDigit6CheckBox); this.displayLedDigitFlowLayoutPanel.Controls.Add(this.displayLedDigit5CheckBox); @@ -208,11 +207,11 @@ private void InitializeComponent() this.displayLedDigitFlowLayoutPanel.Controls.Add(this.displayLedDigit2CheckBox); this.displayLedDigitFlowLayoutPanel.Controls.Add(this.displayLedDigit1CheckBox); this.displayLedDigitFlowLayoutPanel.Controls.Add(this.displayLedDigit0CheckBox); + resources.ApplyResources(this.displayLedDigitFlowLayoutPanel, "displayLedDigitFlowLayoutPanel"); this.displayLedDigitFlowLayoutPanel.Name = "displayLedDigitFlowLayoutPanel"; // // displayLedModuleSizeComboBox // - resources.ApplyResources(this.displayLedModuleSizeComboBox, "displayLedModuleSizeComboBox"); this.displayLedModuleSizeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.displayLedModuleSizeComboBox.FormattingEnabled = true; this.displayLedModuleSizeComboBox.Items.AddRange(new object[] { @@ -222,6 +221,7 @@ private void InitializeComponent() resources.GetString("displayLedModuleSizeComboBox.Items3"), resources.GetString("displayLedModuleSizeComboBox.Items4"), resources.GetString("displayLedModuleSizeComboBox.Items5")}); + resources.ApplyResources(this.displayLedModuleSizeComboBox, "displayLedModuleSizeComboBox"); this.displayLedModuleSizeComboBox.Name = "displayLedModuleSizeComboBox"; this.displayLedModuleSizeComboBox.SelectedIndexChanged += new System.EventHandler(this.DisplayLedModuleSize_SelectedIndexChanged); // @@ -288,15 +288,14 @@ private void InitializeComponent() // // flowLayoutPanel1 // - resources.ApplyResources(this.flowLayoutPanel1, "flowLayoutPanel1"); this.flowLayoutPanel1.Controls.Add(this.displayLedAddressComboBox); this.flowLayoutPanel1.Controls.Add(this.label9); this.flowLayoutPanel1.Controls.Add(this.displayLedConnectorComboBox); + resources.ApplyResources(this.flowLayoutPanel1, "flowLayoutPanel1"); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; // // displayLedAddressComboBox // - resources.ApplyResources(this.displayLedAddressComboBox, "displayLedAddressComboBox"); this.displayLedAddressComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.displayLedAddressComboBox.FormattingEnabled = true; this.displayLedAddressComboBox.Items.AddRange(new object[] { @@ -316,6 +315,7 @@ private void InitializeComponent() resources.GetString("displayLedAddressComboBox.Items13"), resources.GetString("displayLedAddressComboBox.Items14"), resources.GetString("displayLedAddressComboBox.Items15")}); + resources.ApplyResources(this.displayLedAddressComboBox, "displayLedAddressComboBox"); this.displayLedAddressComboBox.Name = "displayLedAddressComboBox"; // // label9 @@ -325,22 +325,22 @@ private void InitializeComponent() // // displayLedConnectorComboBox // - resources.ApplyResources(this.displayLedConnectorComboBox, "displayLedConnectorComboBox"); this.displayLedConnectorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.displayLedConnectorComboBox.FormattingEnabled = true; this.displayLedConnectorComboBox.Items.AddRange(new object[] { resources.GetString("displayLedConnectorComboBox.Items"), resources.GetString("displayLedConnectorComboBox.Items1")}); + resources.ApplyResources(this.displayLedConnectorComboBox, "displayLedConnectorComboBox"); this.displayLedConnectorComboBox.Name = "displayLedConnectorComboBox"; // // PaddingCharComboBox // - resources.ApplyResources(this.PaddingCharComboBox, "PaddingCharComboBox"); this.PaddingCharComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.PaddingCharComboBox.FormattingEnabled = true; this.PaddingCharComboBox.Items.AddRange(new object[] { resources.GetString("PaddingCharComboBox.Items"), resources.GetString("PaddingCharComboBox.Items1")}); + resources.ApplyResources(this.PaddingCharComboBox, "PaddingCharComboBox"); this.PaddingCharComboBox.Name = "PaddingCharComboBox"; // // displayLedReverseDigitsCheckBox @@ -351,7 +351,6 @@ private void InitializeComponent() // // displayLedGroupFlowLayoutPanel // - resources.ApplyResources(this.displayLedGroupFlowLayoutPanel, "displayLedGroupFlowLayoutPanel"); this.displayLedGroupFlowLayoutPanel.Controls.Add(this.displayLedDigitFlowLayoutPanel); this.displayLedGroupFlowLayoutPanel.Controls.Add(this.label5); this.displayLedGroupFlowLayoutPanel.Controls.Add(this.displayLedDecimalPointLabel); @@ -368,6 +367,7 @@ private void InitializeComponent() this.displayLedGroupFlowLayoutPanel.Controls.Add(this.displayLedDisplayLabel1); this.displayLedGroupFlowLayoutPanel.Controls.Add(this.displayLedDisplayLabel0); this.displayLedGroupFlowLayoutPanel.Controls.Add(this.displayLedPaddingCheckBox); + resources.ApplyResources(this.displayLedGroupFlowLayoutPanel, "displayLedGroupFlowLayoutPanel"); this.displayLedGroupFlowLayoutPanel.Name = "displayLedGroupFlowLayoutPanel"; this.displayLedGroupFlowLayoutPanel.TabStop = false; // @@ -391,13 +391,13 @@ private void InitializeComponent() // // groupBox1 // - resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Controls.Add(this.ReverseDigitHintLabel); this.groupBox1.Controls.Add(this.BrightnessReferenceHintLabel); this.groupBox1.Controls.Add(this.ReverseDigitsLabel); this.groupBox1.Controls.Add(this.displayLedReverseDigitsCheckBox); this.groupBox1.Controls.Add(this.brightnessDropDown); this.groupBox1.Controls.Add(this.BrigthnessReferenceLabel); + resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; // @@ -418,9 +418,9 @@ private void InitializeComponent() // // panel1 // - resources.ApplyResources(this.panel1, "panel1"); this.panel1.Controls.Add(this.flowLayoutPanel1); this.panel1.Controls.Add(this.ledDisplayComboBoxLabel); + resources.ApplyResources(this.panel1, "panel1"); this.panel1.Name = "panel1"; // // DisplayLedDisplayPanel diff --git a/UI/Panels/Output/DisplayLedDisplayPanel.cs b/UI/Panels/Output/DisplayLedDisplayPanel.cs index 22920de02..37fc69048 100644 --- a/UI/Panels/Output/DisplayLedDisplayPanel.cs +++ b/UI/Panels/Output/DisplayLedDisplayPanel.cs @@ -15,12 +15,12 @@ public partial class DisplayLedDisplayPanel : UserControl public bool WideStyle = false; private string filterReferenceGuid; public event EventHandler OnLedAddressChanged; - + public DisplayLedDisplayPanel() { InitializeComponent(); InitPanelWithDefaultSettings(); - displayLedAddressComboBox.SelectedIndexChanged += (sender, e) => + displayLedAddressComboBox.SelectedIndexChanged += (sender, e) => { OnLedAddressChanged?.Invoke(displayLedAddressComboBox, new EventArgs()); }; @@ -34,28 +34,28 @@ private void InitPanelWithDefaultSettings() internal void syncFromConfig(OutputConfigItem config) { // preselect display stuff - if (config.LedModule.DisplayLedAddress != null) + if (config.LedModule.DisplayLedAddress != null) { - if (!ComboBoxHelper.SetSelectedItem(displayLedAddressComboBox, config.LedModule.DisplayLedAddress.ToString())) + if (!ComboBoxHelper.SetSelectedItem(displayLedAddressComboBox, config.LedModule.DisplayLedAddress.ToString())) { // TODO: provide error message Log.Instance.log("Exception on selecting item in LED address ComboBox.", LogSeverity.Error); - } else + } else { OnLedAddressChanged?.Invoke(displayLedAddressComboBox, new EventArgs()); } } - if (config.LedModule.DisplayLedAddress != null) + if (config.LedModule.DisplayLedAddress != null) { - if (!ComboBoxHelper.SetSelectedItem(displayLedConnectorComboBox, config.LedModule.DisplayLedConnector.ToString())) + if (!ComboBoxHelper.SetSelectedItem(displayLedConnectorComboBox, config.LedModule.DisplayLedConnector.ToString())) { // TODO: provide error message Log.Instance.log("Exception on selecting item in LED connector ComboBox.", LogSeverity.Error); } } - if (!ComboBoxHelper.SetSelectedItem(displayLedModuleSizeComboBox, config.LedModule.DisplayLedModuleSize.ToString())) + if (!ComboBoxHelper.SetSelectedItem(displayLedModuleSizeComboBox, config.LedModule.DisplayLedModuleSize.ToString())) { // TODO: provide error message Log.Instance.log("Exception on selecting item in LED module size ComboBox.", LogSeverity.Error); @@ -65,17 +65,17 @@ internal void syncFromConfig(OutputConfigItem config) displayLedReverseDigitsCheckBox.Checked = config.LedModule.DisplayLedReverseDigits; SetPaddingChar(config.LedModule.DisplayLedPaddingChar); - foreach (string digit in config.LedModule.DisplayLedDigits) + foreach (string digit in config.LedModule.DisplayLedDigits) { (displayLedDigitFlowLayoutPanel.Controls["displayLedDigit" + digit + "Checkbox"] as CheckBox).Checked = true; } - foreach (string digit in config.LedModule.DisplayLedDecimalPoints) + foreach (string digit in config.LedModule.DisplayLedDecimalPoints) { (displayLedDecimalPointFlowLayoutPanel.Controls["displayLedDecimalPoint" + digit + "Checkbox"] as CheckBox).Checked = true; } - if (!string.IsNullOrEmpty(config.LedModule.DisplayLedBrightnessReference)) + if (!string.IsNullOrEmpty(config.LedModule.DisplayLedBrightnessReference)) { brightnessDropDown.SelectedValue = config.LedModule.DisplayLedBrightnessReference; } @@ -101,27 +101,37 @@ public void SetAddresses(List ports) public void SetConnectors(List pins) { - displayLedConnectorComboBox.DataSource = new List(pins); - displayLedConnectorComboBox.DisplayMember = "Label"; - displayLedConnectorComboBox.ValueMember = "Value"; - + ComboBox cb = displayLedConnectorComboBox; + cb.DataSource = new List(pins); + cb.DisplayMember = "Label"; + cb.ValueMember = "Value"; if (pins.Count > 0) - displayLedConnectorComboBox.SelectedIndex = 0; + cb.SelectedIndex = 0; + cb.Enabled = pins.Count > 1; + } - displayLedConnectorComboBox.Enabled = pins.Count > 0; + public void SetSizeDigits(List entries) + { + ComboBox cb = displayLedModuleSizeComboBox; + cb.DataSource = new List(entries); + cb.DisplayMember = "Label"; + cb.ValueMember = "Value"; + if (entries.Count > 0) + cb.SelectedIndex = entries.Count-1; + cb.Enabled = entries.Count > 1; } private void DisplayLedModuleSize_SelectedIndexChanged(object sender, EventArgs e) { int value = Int16.Parse((sender as ComboBox).Text); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { displayLedDigitFlowLayoutPanel.Controls["displayLedDigit" + i + "CheckBox"].Visible = i < value; displayLedDecimalPointFlowLayoutPanel.Controls["displayLedDecimalPoint" + i + "CheckBox"].Visible = i < value; displayLedGroupFlowLayoutPanel.Controls["displayLedDisplayLabel" + i].Visible = i < value; // uncheck all invisible checkboxes to ensure correct mask - if (i >= value) + if (i >= value) { (displayLedDigitFlowLayoutPanel.Controls["displayLedDigit" + i + "CheckBox"] as CheckBox).Checked = false; (displayLedDecimalPointFlowLayoutPanel.Controls["displayLedDecimalPoint" + i + "CheckBox"] as CheckBox).Checked = false; @@ -133,7 +143,7 @@ public string GetPaddingChar() { String result = "0"; - switch (PaddingCharComboBox.SelectedIndex) + switch (PaddingCharComboBox.SelectedIndex) { case 1: result = " "; @@ -154,35 +164,35 @@ internal OutputConfigItem syncToConfig(OutputConfigItem config) config.LedModule.DisplayLedPadding = displayLedPaddingCheckBox.Checked; config.LedModule.DisplayLedReverseDigits = displayLedReverseDigitsCheckBox.Checked; config.LedModule.DisplayLedPaddingChar = GetPaddingChar(); - try + try { config.LedModule.DisplayLedConnector = byte.Parse(displayLedConnectorComboBox.Text); config.LedModule.DisplayLedModuleSize = byte.Parse(displayLedModuleSizeComboBox.Text); } - catch (FormatException ex) + catch (FormatException ex) { Log.Instance.log($"Exception parsing values: {ex.Message}", LogSeverity.Error); } config.LedModule.DisplayLedDigits.Clear(); config.LedModule.DisplayLedDecimalPoints.Clear(); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { CheckBox cb = (displayLedDigitFlowLayoutPanel.Controls["displayLedDigit" + i + "Checkbox"] as CheckBox); - if (cb.Checked) + if (cb.Checked) { config.LedModule.DisplayLedDigits.Add(i.ToString()); } //if cb = (displayLedDecimalPointFlowLayoutPanel.Controls["displayLedDecimalPoint" + i + "Checkbox"] as CheckBox); - if (cb.Checked) + if (cb.Checked) { config.LedModule.DisplayLedDecimalPoints.Add(i.ToString()); } //if } - if (brightnessDropDown.SelectedIndex <= 0) + if (brightnessDropDown.SelectedIndex <= 0) { config.LedModule.DisplayLedBrightnessReference = string.Empty; - } else + } else { config.LedModule.DisplayLedBrightnessReference = brightnessDropDown.SelectedValue.ToString(); } @@ -190,15 +200,15 @@ internal OutputConfigItem syncToConfig(OutputConfigItem config) } internal void SetConfigRefsDataView(DataView dv, string filterGuid) - { + { this.filterReferenceGuid = filterGuid==null?string.Empty:filterGuid; List configRefs = new List(); configRefs.Add(new ListItem { Value = string.Empty, Label = "" }); - foreach (DataRow refRow in dv.Table.Rows) + foreach (DataRow refRow in dv.Table.Rows) { - if (!filterReferenceGuid.Equals(refRow["guid"].ToString())) + if (!filterReferenceGuid.Equals(refRow["guid"].ToString())) { configRefs.Add(new ListItem { Value = ((Guid)refRow["guid"]).ToString(), Label = refRow["description"] as string }); } diff --git a/UI/Panels/Output/DisplayLedDisplayPanel.resx b/UI/Panels/Output/DisplayLedDisplayPanel.resx index abd8cf9b9..f98f20c2a 100644 --- a/UI/Panels/Output/DisplayLedDisplayPanel.resx +++ b/UI/Panels/Output/DisplayLedDisplayPanel.resx @@ -117,599 +117,542 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - use display + + + True - - - 41, 21 + + + NoControl - - 143, 0 + + + 3, 3 - + 15, 14 - - displayLedGroupFlowLayoutPanel + + 18 - - label9 + + displayLedDigit7CheckBox - - 339, 104 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 234, 63 + + displayLedDigitFlowLayoutPanel - - 108, 17 + + 0 - - - 74 + + True + + + NoControl + + + 5, 9 + + + 83, 13 53 - - 59 - - - 3 + + Name / Number - - 47 + + ledDisplayComboBoxLabel - - $this + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 66, 3 + + panel1 1 - - displayLedDecimalPoint2CheckBox - - - displayLedPaddingCheckBox - - - displayLedDigitFlowLayoutPanel + + True - - displayLedGroupFlowLayoutPanel + + NoControl - - 108, 3 + + 24, 3 - - 68 + + 15, 14 - - - NoControl + + 19 - - NoControl + + displayLedDigit6CheckBox - - 200, 22 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - groupBox1 + + displayLedDigitFlowLayoutPanel - - 94, 13 + + 1 - - MiddleLeft + + True - + NoControl - - NumberOfDigitsLabel + + 45, 3 - - 3, 3 + + 15, 14 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 20 - - 54 + + displayLedDigit5CheckBox - + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 94, 13 + + displayLedDigitFlowLayoutPanel - - 13, 13 + + 2 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True - + NoControl - - 2, 2, 2, 2 + + 66, 3 - - ReverseDigitHintLabel + + 15, 14 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 21 - - displayLedReverseDigitsCheckBox + + displayLedDigit4CheckBox - - 150, 63 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 94, 13 + + displayLedDigitFlowLayoutPanel - - 13, 13 + + 3 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True - - 1 + + Left - - True + + NoControl - - 4 + + 3, 3 - - displayLedDigitFlowLayoutPanel + + 15, 14 - - 5 + + 44 - - Left + + displayLedDecimalPoint7CheckBox - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 49 + + displayLedDecimalPointFlowLayoutPanel - + + 0 + + True - - MiddleRight + + NoControl - - 1 + + 87, 3 15, 14 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 22 - - NoControl + + displayLedDigit3CheckBox - - 171, 63 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 3 + + displayLedDigitFlowLayoutPanel - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 4 - - 192, 63 + + True - - 3, 3, 0, 3 + + NoControl - - 150, 3 + + 108, 3 - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 15, 14 - - 134, 21 + + 23 - - 62 + + displayLedDigit2CheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + displayLedDigitFlowLayoutPanel + + + 5 + + + True + + + Left + + + NoControl + + + 24, 3 + + + 15, 14 + + + 45 displayLedDecimalPoint6CheckBox - - groupBox1 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - MiddleRight + + displayLedDecimalPointFlowLayoutPanel - - NoControl + + 1 - + True - - 6 - - - 3 + + Left NoControl - - displayLedDigitFlowLayoutPanel + + 45, 3 - + 15, 14 - - displayLedGroupFlowLayoutPanel + + 46 - - 2 + + displayLedDecimalPoint5CheckBox - - 7 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + displayLedDecimalPointFlowLayoutPanel - - 105, 20 + + 2 - - displayLedDigitFlowLayoutPanel + + True - + Left - - True + + NoControl - + + 66, 3 + + 15, 14 - - 12, 28 + + 47 - - panel1 + + displayLedDecimalPoint4CheckBox - + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 6 - - - displayLedDisplayLabel2 + + displayLedDecimalPointFlowLayoutPanel - - flowLayoutPanel1 + + 3 - + True - - 18 - - - 5 + + Left - + NoControl - - displayLedDigit3CheckBox + + 87, 3 - - 13, 13 + + 15, 14 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 48 - - 8 + + displayLedDecimalPoint3CheckBox - - 46 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 60 + + displayLedDecimalPointFlowLayoutPanel - + + 4 + + + True + + + Left + + NoControl - - False + + 108, 3 - - 45, 3 + + 15, 14 - - 21 + + 49 - - 1 + + displayLedDecimalPoint2CheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 displayLedDecimalPointFlowLayoutPanel - - 73 + + 5 - - 65 + + True - - Fill + + Left - - groupBox1 + + NoControl - - 15 + + 129, 3 - - Number of digits + + 15, 14 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 50 - - displayLedDigit0CheckBox + + displayLedDecimalPoint1CheckBox - + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + displayLedDecimalPointFlowLayoutPanel - - displayLedDecimalPoint7CheckBox + + 6 - - 222, 60 + + True - - 44 + + Left - - 6 + + NoControl - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 150, 3 - - NoControl + + 15, 14 51 - - displayLedConnectorComboBox + + displayLedDecimalPoint0CheckBox - - Bottom, Left, Right - - - 3 - - - True - - - displayLedDigit7CheckBox - - - 75 - - - displayLedDisplayLabel7 - - - 2 - - - True - - - displayLedDecimalPointFlowLayoutPanel - - - Reverse digits - - - 66 - - - displayLedAddressComboBox - - - NoControl - - - 87, 3 - - + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - NoControl - - - 12 - - - Top + + displayLedDecimalPointFlowLayoutPanel - - groupBox1 + + 7 - - displayLedDigit4CheckBox + + 104, 78 - - 13, 13 + + 200, 22 - - 15, 14 + + 65 - - 2 + + False - + displayLedDecimalPointFlowLayoutPanel - - 96, 21 - - - 5, 48 - - - / + + System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - NoControl + + displayLedGroupFlowLayoutPanel - - 104, 74 + + 5 - - 7 + + True - - displayLedModuleSizeComboBox + + NoControl 129, 3 - - displayLedGroupFlowLayoutPanel - - - displayLedDecimalPointFlowLayoutPanel + + 15, 14 - - 22 + + 24 - - 3 + + displayLedDigit1CheckBox - - displayLedGroupFlowLayoutPanel + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 107, 24 + + displayLedDigitFlowLayoutPanel - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 6 - + True - - 65 + + NoControl - - 255, 63 + + 150, 3 - - True + + 15, 14 25 - - displayLedGroupFlowLayoutPanel - - - NoControl - - - 15, 14 - - - NoControl - - - 339, 148 + + displayLedDigit0CheckBox - - 57 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + displayLedDigitFlowLayoutPanel - - 213, 63 + + 7 - - 5 + + 104, 45 - - 6 + + 200, 18 - - ReverseDigitsLabel + + 68 - + displayLedDigitFlowLayoutPanel - - set decimal point - - - 6 - - - 10 - - - displayLedDecimalPointLabel - - - True - - - NoControl - - - NoControl - - - 15, 14 - - - PaddingCharComboBox + + System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - MiddleRight + + displayLedGroupFlowLayoutPanel - - 150, 3 + + 0 - - 8 + + 3 4 @@ -726,801 +669,858 @@ 8 - - label5 + + 105, 20 - - 161, 3 + + 35, 21 - - True + + 67 - - 0, 0 + + displayLedModuleSizeComboBox - - 1 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - NoControl + + displayLedGroupFlowLayoutPanel - - True + + 8 - - Space + + NoControl - - 0 + + 5, 24 - - 45, 3 - - - NoControl - - - Brightness ref. + + 94, 13 - - displayLedDecimalPointFlowLayoutPanel + + 66 - - brightnessDropDown + + Number of digits - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + MiddleRight - - 50 + + NumberOfDigitsLabel - - displayLedDisplayLabel4 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + displayLedGroupFlowLayoutPanel - - 5 - - - 4 - - - flowLayoutPanel1 - - - 51 + + 10 - + NoControl - - 8 + + 158, 23 - - DisplayLedDisplayPanel + + 108, 17 - - 69 + + 51 - - 199, 14 + + Use Left Padding - - 13, 13 + + displayLedPaddingCheckBox - - displayLedDisplayLabel5 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 2, 2, 2, 2 + + displayLedGroupFlowLayoutPanel - - Top, Left, Right + + 15 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True - - groupBox1 + + NoControl 106, 63 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 13, 13 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 56 - + 1 - - 75 + + displayLedDisplayLabel0 - - 66, 3 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + displayLedGroupFlowLayoutPanel - - 48 + + 14 - - Top + + True - - 104, 45 + + NoControl - + + 128, 63 + + 13, 13 - - displayLedDecimalPoint4CheckBox + + 52 - - 0 + + 2 - - System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + displayLedDisplayLabel1 - - 222, 21 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 2 + + displayLedGroupFlowLayoutPanel - - 0 + + 13 - - 6 + + True - - MiddleRight + + NoControl - - displayLedGroupFlowLayoutPanel + + 150, 63 - - displayLedDigit1CheckBox + + 13, 13 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 57 - - groupBox1 + + 3 - - 339, 35 + + displayLedDisplayLabel2 - - 2, 2, 2, 2 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + displayLedGroupFlowLayoutPanel - - 0, 139 + + 11 - - 52 + + True - - 38, 21 + + NoControl - - 0 + + 171, 63 - - NoControl + + 13, 13 - - 70 + + 58 - - 72 + + 4 - + + displayLedDisplayLabel3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + displayLedGroupFlowLayoutPanel - - 104, 47 + + 9 - - 5 + + True - + NoControl - - 0, 3, 0, 3 - - - 24, 3 + + 192, 63 - - 104, 3 + + 13, 13 - - 55 + + 59 - + 5 - - NoControl + + displayLedDisplayLabel4 - - 15, 14 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 134, 0 + + displayLedGroupFlowLayoutPanel - - displayLedDisplayLabel0 + + 7 - + + True + + NoControl - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 213, 63 - - 67 + + 13, 13 - - 14 + + 60 - - 13, 13 + + 6 - - 3, 3 + + displayLedDisplayLabel5 - - True + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 15, 14 + + displayLedGroupFlowLayoutPanel - - 2 + + 6 - + True - - Left - - - 339, 287 + + NoControl - - 3, 47 + + 234, 63 - - flowLayoutPanel1 + + 13, 13 61 - - 0, 35 + + 7 - - 13 + + displayLedDisplayLabel6 - - Top, Left, Right + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 15, 14 + + displayLedGroupFlowLayoutPanel - - displayLedDigit2CheckBox + + 4 - - 35, 21 + + True - - 20 + + NoControl - - 3 + + 255, 63 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 13, 13 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 62 - - MiddleCenter + + 8 - - System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + displayLedDisplayLabel7 - - True + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this + + displayLedGroupFlowLayoutPanel - + + 3 + + NoControl - - displayLedDecimalPoint5CheckBox + + 5, 79 - - 5 + + 94, 13 - - 5, 9 + + 55 - - 4 + + set decimal point - - displayLedDigitFlowLayoutPanel + + MiddleRight - - 200, 18 + + displayLedDecimalPointLabel - - 7 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 11 + + displayLedGroupFlowLayoutPanel - - displayLedDecimalPoint3CheckBox + + 2 - - 1 + + NoControl - - True + + 5, 48 - - 3, 3 + + 94, 13 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 54 - - BrigthnessReferenceLabel + + use display - - NoControl + + MiddleRight - - 67 + + label5 - - 1 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this + + displayLedGroupFlowLayoutPanel - - 35, 0 + + 1 - - NoControl + + 0 - - NoControl + + 1 - - Left + + 2 - - 5, 79 + + 3 - - displayLedDigit6CheckBox + + 4 - - 15, 14 + + 5 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 6 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 7 - - True + + 8 - - displayLedDecimalPoint0CheckBox + + 9 - - 71 + + A - - displayLedGroupFlowLayoutPanel + + B - - Left + + C - - System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + D - - 15, 14 - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + E - - groupBox1 + + F - - panel1 + + 3, 3 - - displayLedDecimalPointFlowLayoutPanel + + 134, 0 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 35, 0 - - 8 + + 134, 21 - - Left + + 65 - - displayLedDisplayLabel6 + + displayLedAddressComboBox - + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 83, 13 - - - True + + flowLayoutPanel1 - - 128, 63 + + 0 - + NoControl - - 66 + + 143, 0 - - displayLedDisplayLabel3 + + 12, 28 - - 127, 23 + + 67 - - displayLedGroupFlowLayoutPanel + + / - - displayLedGroupFlowLayoutPanel + + MiddleCenter - - 13, 13 + + label9 - - 9 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 24 + + flowLayoutPanel1 - - 223, 28 + + 1 - - displayLedGroupFlowLayoutPanel + + 1 - - 0 + + 2 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 161, 3 - - 15, 14 + + 3, 3, 0, 3 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 38, 21 - - 4 + + 66 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + displayLedConnectorComboBox - - displayLedGroupFlowLayoutPanel + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + flowLayoutPanel1 + + 2 - - 0 + + 104, 3 - - 74 + + 0, 3, 0, 3 - - 2 + + 223, 28 - - True + + 69 - - Use Left Padding + + flowLayoutPanel1 - - 19 + + System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Left + + panel1 - - 74 + + 0 - - ledDisplayComboBoxLabel + + 0 - - 87, 3 + + Space - - 93, 14 + + 265, 20 - - NoControl + + 41, 21 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 70 - - True + + PaddingCharComboBox - - 104, 78 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 7 + + displayLedGroupFlowLayoutPanel - - displayLedDecimalPointFlowLayoutPanel + + 12 - - 6, 23 + + True - - MiddleRight + + 107, 24 - - displayLedDecimalPointFlowLayoutPanel + + 2, 2, 2, 2 - - NoControl + + 15, 14 - - 2, 2, 2, 2 + + 71 - - True + + displayLedReverseDigitsCheckBox - + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + groupBox1 + + 3 - - displayLedDecimalPoint1CheckBox + + Top - - 0 + + 0, 35 - - 24, 3 + + 2, 2, 2, 2 - - Left + + 2, 2, 2, 2 + + + 339, 108 + + + 74 Values - - 158, 23 - - - True + + displayLedGroupFlowLayoutPanel - - 2 + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - D + + $this - - 15, 14 - - - 9 + + 1 - - displayLedGroupFlowLayoutPanel + + Top, Left, Right - - 45 + + 3 - - 15, 14 + + 4 - - 3 + + 5 - - 0 + + 6 - - 6, 13 + + 8 - - True + + 104, 47 - - 56 + + 222, 21 - - 5, 24 + + 73 - - Extended + + brightnessDropDown - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - E + + groupBox1 - - F + + 4 - - C + + NoControl - - 7 + + 3, 47 - - A + + 96, 21 - - B + + 72 - - 58 + + Brightness ref. - - True + + MiddleRight - - displayLedDigit5CheckBox + + BrigthnessReferenceLabel - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - displayLedDigitFlowLayoutPanel + + groupBox1 - - Name / Number + + 5 - - 15, 14 + + Top, Left, Right - + NoControl - - displayLedGroupFlowLayoutPanel + + 127, 23 - - 0 + + 199, 14 - - displayLedDisplayLabel1 + + 76 - - 2 + + (only needed for custom PCBs) - - 108, 3 + + MiddleLeft - - 129, 3 + + ReverseDigitHintLabel - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - displayLedDigitFlowLayoutPanel + + groupBox1 - - (only needed for custom PCBs) + + 0 - - panel1 + + Bottom, Left, Right - - 23 + + 104, 94 + + + 222, 60 + + + 75 + + + Brightness range is from 0-15. + +Zero (0) turns the display off, e.g. cold && dark without power. 15 is full bright. BrightnessReferenceHintLabel - - 76 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - displayLedGroupFlowLayoutPanel + + groupBox1 - + + 1 + + NoControl - - 4 + + 6, 23 - - 4 + + 93, 14 - - flowLayoutPanel1 + + 74 - - True + + Reverse digits - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + MiddleRight - - 15, 14 + + ReverseDigitsLabel - - Brightness range is from 0-15. - -Zero (0) turns the display off, e.g. cold && dark without power. 15 is full bright. + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 1 + + groupBox1 - - System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 2 - - 4 + + Fill - - 265, 20 + + 0, 143 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 339, 159 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 74 - - 1 + + Extended + + + groupBox1 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + Top + + + 0, 0 + + + 2, 2, 2, 2 + + + 339, 35 + + + 75 + + + panel1 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 True + + 6, 13 + + + 339, 302 + + + DisplayLedDisplayPanel + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/UI/Panels/OutputWizard/DisplayPanel.cs b/UI/Panels/OutputWizard/DisplayPanel.cs index 774024fb2..f88f8f2c2 100644 --- a/UI/Panels/OutputWizard/DisplayPanel.cs +++ b/UI/Panels/OutputWizard/DisplayPanel.cs @@ -1,4 +1,5 @@ using MobiFlight.Base; +using MobiFlight.Config; using MobiFlight.InputConfig; using MobiFlight.UI.Panels.Settings.Device; using System; @@ -6,7 +7,6 @@ using System.ComponentModel; using System.Data; using System.Windows.Forms; -using System.Windows.Forms.DataVisualization.Charting; namespace MobiFlight.UI.Panels.OutputWizard { @@ -681,22 +681,36 @@ void displayLedAddressComboBox_SelectedIndexChanged(object sender, EventArgs e) String serial = SerialNumber.ExtractSerial(cb.SelectedItem.ToString()); MobiFlightModule module = _execManager.getMobiFlightModuleCache().GetModuleBySerial(serial); - List connectors = new List(); + // Build list of chained modules and list of selectable sizes + var chained = new List(); + var entries = new List(); if (module != null) { foreach (IConnectedDevice device in module.GetConnectedDevices()) { if (device.Type != DeviceType.LedModule) continue; if (device.Name != ((sender as ComboBox).SelectedItem as ListItem).Value) continue; - for (int i = 0; i < (device as MobiFlightLedModule).SubModules; i++) + // Found the device we sought + MobiFlightLedModule dev = device as MobiFlightLedModule; + for (int i = 0; i < dev.SubModules; i++) { - connectors.Add(new ListItem() { Label = (i + 1).ToString(), Value = (i + 1).ToString() }); + chained.Add(new ListItem() { Label = (i + 1).ToString(), Value = (i + 1).ToString() }); + } + var maxdigits = 8; + + if (dev.ModelType == LedModule.MODEL_TYPE_TM1637_4DIGIT) { maxdigits = 4; } + else + if (dev.ModelType == LedModule.MODEL_TYPE_TM1637_6DIGIT) { maxdigits = 6; } + + for (int i = 2; i < maxdigits; i++) + { + entries.Add(new ListItem() { Label = (i + 1).ToString(), Value = (i + 1).ToString() }); } } } - - displayLedDisplayPanel.SetConnectors(connectors); + displayLedDisplayPanel.SetConnectors(chained); + displayLedDisplayPanel.SetSizeDigits(entries); } #region Stepper related functions diff --git a/UI/Panels/Settings/MobiFlightPanel.cs b/UI/Panels/Settings/MobiFlightPanel.cs index 45bdff820..a1ca4ceba 100644 --- a/UI/Panels/Settings/MobiFlightPanel.cs +++ b/UI/Panels/Settings/MobiFlightPanel.cs @@ -382,7 +382,7 @@ private void syncPanelWithSelectedDevice(TreeNode selectedNode) switch (dev.Type) { case DeviceType.LedModule: - panel = new MFLedSegmentPanel(dev as MobiFlight.Config.LedModule, module.GetPins()); + panel = new MFLedSegmentPanel(dev as MobiFlight.Config.LedModule, module.GetPins(), module.HasFirmwareFeature(FirmwareFeature.LedModuleTypeTM1637)); (panel as MFLedSegmentPanel).Changed += new EventHandler(mfConfigDeviceObject_changed); break; @@ -1003,7 +1003,6 @@ private MobiFlightModule getVirtualModuleFromTree() if (moduleNode == null) return null; MobiFlightModule module = new MobiFlightModule((moduleNode.Tag as MobiFlightModule).ToMobiFlightModuleInfo()); - // Generate config MobiFlight.Config.Config newConfig = new MobiFlight.Config.Config(); foreach (TreeNode node in moduleNode.Nodes) @@ -1277,6 +1276,7 @@ protected void OnAfterFirmwareUpdateOrReset(MobiFlightModule module, bool IsUpda { module.Version = null; module.Name = module.Board.Info.FriendlyName; + module.Serial = null; newInfo = module.ToMobiFlightModuleInfo(); } @@ -1291,7 +1291,7 @@ protected void OnAfterFirmwareUpdateOrReset(MobiFlightModule module, bool IsUpda // If the board definition file is correct but the firmware failed to flash and the result is // a bare module with no MobiFlight firmware on it then the serial number will be null // and the module should not be refreshed. - if (String.IsNullOrEmpty(newInfo.Serial)) + if (IsUpdate && String.IsNullOrEmpty(newInfo.Serial)) { return; }