Skip to content

Commit

Permalink
Setting an existing input device to "none" is now possible (#1086)
Browse files Browse the repository at this point in the history
Setting an existing input device to "none" is now possible
  • Loading branch information
Pitj3 authored Jan 21, 2023
1 parent d18bbf2 commit ea7534f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion MobiFlight/InputConfigItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions MobiFlight/OutputConfigItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
4 changes: 4 additions & 0 deletions MobiFlightUnitTests/MobiFlight/OutputConfigItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
<config guid="8d4c174f-74d7-4f65-85e4-b2dc164877b6">
<active>false</active>
<description>Radio On</description>
<settings msdata:InstanceType="MobiFlight.InputConfigItem, MFConnector, Version=9.4.0.3, Culture=neutral, PublicKeyToken=null" serial="" name="" type="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<settings msdata:InstanceType="MobiFlight.InputConfigItem, MFConnector, Version=9.4.0.3, Culture=neutral, PublicKeyToken=null" serial="" name="" type="-" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<preconditions />
<configrefs />
</settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
<config guid="8d4c174f-74d7-4f65-85e4-b2dc164877b6">
<active>false</active>
<description>Radio On</description>
<settings msdata:InstanceType="MobiFlight.InputConfigItem, MFConnector, Version=9.4.0.3, Culture=neutral, PublicKeyToken=null" serial="" name="" type="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<settings msdata:InstanceType="MobiFlight.InputConfigItem, MFConnector, Version=9.4.0.3, Culture=neutral, PublicKeyToken=null" serial="" name="" type="-" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<preconditions />
<configrefs />
</settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
<config guid="8d4c174f-74d7-4f65-85e4-b2dc164877b6">
<active>false</active>
<description>Radio On</description>
<settings msdata:InstanceType="MobiFlight.InputConfigItem, MFConnector, Version=8.0.2.1, Culture=neutral, PublicKeyToken=null" serial="" name="" type="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<settings msdata:InstanceType="MobiFlight.InputConfigItem, MFConnector, Version=8.0.2.1, Culture=neutral, PublicKeyToken=null" serial="" name="" type="-" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<preconditions />
<configrefs />
</settings>
Expand Down
45 changes: 27 additions & 18 deletions UI/Dialogs/InputConfigWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseDevice>).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<BaseDevice>).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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>() { 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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion UI/Panels/OutputWizard/DisplayPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit ea7534f

Please sign in to comment.