From ea7534f84505000f842c898ca57b7d12515cb88d Mon Sep 17 00:00:00 2001 From: Roderick Griffioen Date: Sat, 21 Jan 2023 17:48:55 +0100 Subject: [PATCH] Setting an existing input device to "none" is now possible (#1086) Setting an existing input device to "none" is now possible --- MobiFlight/InputConfigItem.cs | 2 +- MobiFlight/OutputConfigItem.cs | 1 + .../MobiFlight/OutputConfigItemTests.cs | 4 ++ .../Base/ConfigFile/Homecockpit_C172.mcc.exp | 2 +- .../example-default-plane-v6.1.mcc.exp | 2 +- .../Base/ConfigFile/test-only-inputs.mcc.exp | 2 +- UI/Dialogs/InputConfigWizard.cs | 45 +++++++++++-------- UI/Panels/OutputWizard/DisplayPanel.cs | 3 +- 8 files changed, 38 insertions(+), 23 deletions(-) diff --git a/MobiFlight/InputConfigItem.cs b/MobiFlight/InputConfigItem.cs index 80f781eb0..b3ff2df69 100644 --- a/MobiFlight/InputConfigItem.cs +++ b/MobiFlight/InputConfigItem.cs @@ -18,7 +18,7 @@ public class InputConfigItem : IBaseConfigItem, IXmlSerializable, ICloneable, IC // independently from current cultureInfo // @see: https://forge.simple-solutions.de/issues/275 private System.Globalization.CultureInfo serializationCulture = new System.Globalization.CultureInfo("de"); - public const String TYPE_NOTSET = ""; + public const String TYPE_NOTSET = "-"; public const String TYPE_BUTTON = MobiFlightButton.TYPE; public const String TYPE_ENCODER = MobiFlightEncoder.TYPE; public const String TYPE_INPUT_SHIFT_REGISTER = MobiFlightInputShiftRegister.TYPE; diff --git a/MobiFlight/OutputConfigItem.cs b/MobiFlight/OutputConfigItem.cs index ee8f0c110..29bd30343 100644 --- a/MobiFlight/OutputConfigItem.cs +++ b/MobiFlight/OutputConfigItem.cs @@ -92,6 +92,7 @@ public override bool Equals(object obj) { return ( obj != null && obj is OutputConfigItem && + this.DisplayType == (obj as OutputConfigItem).DisplayType && this.DisplaySerial == (obj as OutputConfigItem).DisplaySerial && this.SourceType == (obj as OutputConfigItem).SourceType && this.FSUIPC.Equals((obj as OutputConfigItem).FSUIPC) && diff --git a/MobiFlightUnitTests/MobiFlight/OutputConfigItemTests.cs b/MobiFlightUnitTests/MobiFlight/OutputConfigItemTests.cs index eb0029708..f23cdc9ff 100644 --- a/MobiFlightUnitTests/MobiFlight/OutputConfigItemTests.cs +++ b/MobiFlightUnitTests/MobiFlight/OutputConfigItemTests.cs @@ -320,6 +320,10 @@ public void EqualsTest() o2 = _generateConfigItem(); o2.Servo.MaxRotationPercent = "90"; Assert.IsFalse(o1.Equals(o2)); + + o2 = _generateConfigItem(); + o2.DisplayType = "nonsense"; + Assert.IsFalse(o1.Equals(o2)); } } } \ No newline at end of file diff --git a/MobiFlightUnitTests/assets/Base/ConfigFile/Homecockpit_C172.mcc.exp b/MobiFlightUnitTests/assets/Base/ConfigFile/Homecockpit_C172.mcc.exp index 76e05ec84..bc024b26f 100644 --- a/MobiFlightUnitTests/assets/Base/ConfigFile/Homecockpit_C172.mcc.exp +++ b/MobiFlightUnitTests/assets/Base/ConfigFile/Homecockpit_C172.mcc.exp @@ -549,7 +549,7 @@ false Radio On - + diff --git a/MobiFlightUnitTests/assets/Base/ConfigFile/example-default-plane-v6.1.mcc.exp b/MobiFlightUnitTests/assets/Base/ConfigFile/example-default-plane-v6.1.mcc.exp index abf082f26..a7cc0ff55 100644 --- a/MobiFlightUnitTests/assets/Base/ConfigFile/example-default-plane-v6.1.mcc.exp +++ b/MobiFlightUnitTests/assets/Base/ConfigFile/example-default-plane-v6.1.mcc.exp @@ -457,7 +457,7 @@ false Radio On - + diff --git a/MobiFlightUnitTests/assets/Base/ConfigFile/test-only-inputs.mcc.exp b/MobiFlightUnitTests/assets/Base/ConfigFile/test-only-inputs.mcc.exp index b69ecad9f..d9f01fb8b 100644 --- a/MobiFlightUnitTests/assets/Base/ConfigFile/test-only-inputs.mcc.exp +++ b/MobiFlightUnitTests/assets/Base/ConfigFile/test-only-inputs.mcc.exp @@ -235,7 +235,7 @@ false Radio On - + diff --git a/UI/Dialogs/InputConfigWizard.cs b/UI/Dialogs/InputConfigWizard.cs index cbc8f0b58..6527f364c 100644 --- a/UI/Dialogs/InputConfigWizard.cs +++ b/UI/Dialogs/InputConfigWizard.cs @@ -282,23 +282,26 @@ protected bool _syncFormToConfig() { config.ModuleSerial = inputModuleNameComboBox.SelectedItem.ToString(); - if (Joystick.IsJoystickSerial(SerialNumber.ExtractSerial(config.ModuleSerial))) - { - config.Name = (inputTypeComboBox.SelectedItem as ListItem).Value; - } else - { - config.Name = (inputTypeComboBox.SelectedItem as ListItem).Value.Name; - } - configRefPanel.syncToConfig(config); preconditionPanel.syncToConfig(config); if (config.ModuleSerial == "-") return true; + if (inputTypeComboBox.SelectedItem.ToString() != InputConfigItem.TYPE_NOTSET) + { + if (Joystick.IsJoystickSerial(SerialNumber.ExtractSerial(config.ModuleSerial))) + { + config.Name = (inputTypeComboBox.SelectedItem as ListItem).Value; + } + else + { + config.Name = (inputTypeComboBox.SelectedItem as ListItem).Value.Name; + } + } DeviceType currentInputType = determineCurrentDeviceType(SerialNumber.ExtractSerial(config.ModuleSerial)); - if (groupBoxInputSettings.Controls.Count == 0) return false; + //if (groupBoxInputSettings.Controls.Count == 0) return false; switch (currentInputType) { @@ -338,6 +341,11 @@ protected bool _syncFormToConfig() if (groupBoxInputSettings.Controls[0] != null) (groupBoxInputSettings.Controls[0] as AnalogPanel).ToConfig(config.analog); break; + + case DeviceType.NotSet: + config.Type = InputConfigItem.TYPE_NOTSET; + config.Name = InputConfigItem.TYPE_NOTSET; + break; } return true; @@ -369,21 +377,20 @@ private void ModuleSerialComboBox_SelectedIndexChanged(object sender, EventArgs ComboBox cb = (sender as ComboBox); try { - // disable test button - // in case that no display is selected String serial = SerialNumber.ExtractSerial(cb.SelectedItem.ToString()); inputTypeComboBox.Enabled = groupBoxInputSettings.Enabled = (serial != ""); - // serial is empty if no module is selected (on init of form) - //if (serial == "") return; - // update the available types depending on the - // type of module - inputTypeComboBox.Items.Clear(); inputTypeComboBox.ValueMember = "Value"; inputTypeComboBox.DisplayMember = "Label"; + inputTypeComboBox.Items.Add(new ListItem() { Label = InputConfigItem.TYPE_NOTSET, Value = InputConfigItem.TYPE_NOTSET}); + inputTypeComboBox.SelectedIndex = 0; + + if (string.IsNullOrEmpty(serial)) + return; + if (!Joystick.IsJoystickSerial(serial)) { MobiFlightModule module = _execManager.getMobiFlightModuleCache().GetModuleBySerial(serial); @@ -431,7 +438,6 @@ private void ModuleSerialComboBox_SelectedIndexChanged(object sender, EventArgs // third tab if (!ComboBoxHelper.SetSelectedItem(inputTypeComboBox, config.Name)) { - // TODO: provide error message Log.Instance.log($"Problem setting display type ComboBox.", LogSeverity.Error); } @@ -444,7 +450,10 @@ private void ModuleSerialComboBox_SelectedIndexChanged(object sender, EventArgs private DeviceType determineCurrentDeviceType(String serial) { - DeviceType currentInputType = DeviceType.Button; + DeviceType currentInputType = DeviceType.NotSet; + + if (string.IsNullOrEmpty(serial)) + return currentInputType; if (!Joystick.IsJoystickSerial(serial)) { MobiFlightModule module = _execManager.getMobiFlightModuleCache().GetModuleBySerial(serial); diff --git a/UI/Panels/OutputWizard/DisplayPanel.cs b/UI/Panels/OutputWizard/DisplayPanel.cs index d67cfabba..a75076a07 100644 --- a/UI/Panels/OutputWizard/DisplayPanel.cs +++ b/UI/Panels/OutputWizard/DisplayPanel.cs @@ -197,12 +197,13 @@ internal void syncToConfig() if (OutputTypeIsDisplay()) { if (displayTypeComboBox.SelectedItem == null) return; - if ((displayTypeComboBox.SelectedItem as ListItem).Value == "-") return; config.DisplayType = (displayTypeComboBox.SelectedItem as ListItem).Value; config.DisplayTrigger = "normal"; config.DisplaySerial = displayModuleNameComboBox.SelectedItem.ToString(); + if ((displayTypeComboBox.SelectedItem as ListItem).Value == "-") return; + switch (config.DisplayType) { case "Pin":