From 9b9116e3d2c25ddc6e158598381145697f052617 Mon Sep 17 00:00:00 2001 From: GioCC Date: Tue, 8 Aug 2023 17:53:11 +0200 Subject: [PATCH] Modified management of type selection combo box --- .../Device/MFLedSegmentPanel.Designer.cs | 6 +- UI/Panels/Device/MFLedSegmentPanel.cs | 65 ++++++++++--------- UI/Panels/Device/MFLedSegmentPanel.resx | 9 --- 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/UI/Panels/Device/MFLedSegmentPanel.Designer.cs b/UI/Panels/Device/MFLedSegmentPanel.Designer.cs index 7201c7c2e..9a407649d 100644 --- a/UI/Panels/Device/MFLedSegmentPanel.Designer.cs +++ b/UI/Panels/Device/MFLedSegmentPanel.Designer.cs @@ -188,13 +188,9 @@ private void InitializeComponent() // this.mfDisplayTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.mfDisplayTypeComboBox.FormattingEnabled = true; - this.mfDisplayTypeComboBox.Items.AddRange(new object[] { - resources.GetString("mfDisplayTypeComboBox.Items"), - resources.GetString("mfDisplayTypeComboBox.Items1"), - resources.GetString("mfDisplayTypeComboBox.Items2")}); resources.ApplyResources(this.mfDisplayTypeComboBox, "mfDisplayTypeComboBox"); this.mfDisplayTypeComboBox.Name = "mfDisplayTypeComboBox"; - this.mfDisplayTypeComboBox.SelectedIndexChanged += new System.EventHandler(this.mfDisplayTypeComboBox_SelectedIndexChanged); + this.mfDisplayTypeComboBox.SelectedValueChanged += new System.EventHandler(this.mfDisplayTypeComboBox_SelectedValueChanged); // // MFLedSegmentPanel // diff --git a/UI/Panels/Device/MFLedSegmentPanel.cs b/UI/Panels/Device/MFLedSegmentPanel.cs index eeb143c97..bb8d12bf6 100644 --- a/UI/Panels/Device/MFLedSegmentPanel.cs +++ b/UI/Panels/Device/MFLedSegmentPanel.cs @@ -14,13 +14,15 @@ public partial class MFLedSegmentPanel : UserControl private MobiFlight.Config.LedModule ledModule; private List pinList; // COMPLETE list of pins (includes status) private bool initialized = false; + string currentMode; private string exMAXClsPin = ""; - + public event EventHandler Changed; public MFLedSegmentPanel() { InitializeComponent(); + InitializeDisplayTypeComboBox(); mfPin1ComboBox.Items.Clear(); mfPin2ComboBox.Items.Clear(); mfPin3ComboBox.Items.Clear(); @@ -39,26 +41,41 @@ public MFLedSegmentPanel(MobiFlight.Config.LedModule ledModule, List languageOptions = new List(); + languageOptions.Add(new ListItem() { Value = MobiFlight.Config.LedModule.MODEL_MAX72xx, Label = "MAX72xx" }); + languageOptions.Add(new ListItem() { Value = MobiFlight.Config.LedModule.MODEL_TM1637_4D, Label = "TM1637 - 4Digit" }); + languageOptions.Add(new ListItem() { Value = MobiFlight.Config.LedModule.MODEL_TM1637_6D, Label = "TM1637 - 6Digit" }); + mfDisplayTypeComboBox.DataSource = languageOptions; + mfDisplayTypeComboBox.DisplayMember = "Label"; + mfDisplayTypeComboBox.ValueMember = "Value"; + mfDisplayTypeComboBox.SelectedIndex = 0; + } + private bool isMax() { - return mfDisplayTypeComboBox.SelectedIndex == 0; + //return mfDisplayTypeComboBox.SelectedIndex == 0; + return mfDisplayTypeComboBox.SelectedValue.ToString() == MobiFlight.Config.LedModule.MODEL_MAX72xx; } private void setNonPinValues() { @@ -78,14 +95,13 @@ private void setMAXMode(String mode) // bool MAXmode) private void changeMAXMode(String mode) { setMAXMode(mode); - var MAXmode = (mode == MobiFlight.Config.LedModule.MODEL_MAX72xx); - if (MAXmode) { + if (mode == MobiFlight.Config.LedModule.MODEL_MAX72xx) { // First try and see if the "old" pin is still available, otherwise assign the first free one - ledModule.ClsPin = ((exMAXClsPin != "") ? exMAXClsPin : ""); + ledModule.ClsPin = exMAXClsPin; ComboBoxHelper.assignPin(pinList, ref ledModule.ClsPin); UpdateFreePinsInDropDowns(); } else { - if(exMAXClsPin == "") exMAXClsPin = ledModule.ClsPin; + if(currentMode == MobiFlight.Config.LedModule.MODEL_MAX72xx) exMAXClsPin = ledModule.ClsPin; // "freePin()" is the first half part only of "ReassignFreePinsInDropDowns()" ComboBoxHelper.freePin(pinList, ledModule.ClsPin); // Make sure to use a neutral value @@ -94,6 +110,7 @@ private void changeMAXMode(String mode) // Now replace it with the special marker ledModule.ClsPin = mode; } + currentMode = mode; if (Changed != null) Changed(ledModule, new EventArgs()); } @@ -134,26 +151,14 @@ private void value_Changed(object sender, EventArgs e) if (Changed != null) Changed(ledModule, new EventArgs()); } - - private void mfDisplayTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) + + private void mfDisplayTypeComboBox_SelectedValueChanged(object sender, EventArgs e) { - var selection = (sender as ComboBox).SelectedIndex; - string newMode = ""; - switch (selection) { - case 0: - newMode = MobiFlight.Config.LedModule.MODEL_MAX72xx; - break; - case 1: - newMode = MobiFlight.Config.LedModule.MODEL_TM1637_4D; - break; - case 2: - newMode = MobiFlight.Config.LedModule.MODEL_TM1637_6D; - break; - - } + if (!initialized) return; + string newMode = (sender as ComboBox).SelectedValue.ToString(); if (!initialized) { setMAXMode(newMode); - } else { + } else { changeMAXMode(newMode); } } diff --git a/UI/Panels/Device/MFLedSegmentPanel.resx b/UI/Panels/Device/MFLedSegmentPanel.resx index 916a83eaa..30cb24b96 100644 --- a/UI/Panels/Device/MFLedSegmentPanel.resx +++ b/UI/Panels/Device/MFLedSegmentPanel.resx @@ -681,15 +681,6 @@ 0 - - MAX72xx - - - TM1637-4Digit - - - TM1637-6Digit - 18, 27