From 34be739eb2990023a189adad66c6b6fffc109a8b Mon Sep 17 00:00:00 2001 From: Sebastian M Date: Wed, 7 Dec 2022 18:18:29 -0600 Subject: [PATCH] Support proper Honeycomb Button and Axis Labels (#1027) --- MobiFlight/ExecutionManager.cs | 2 +- MobiFlight/Joystick.cs | 64 +++++++--- MobiFlight/JoystickManager.cs | 9 +- MobiFlight/Joysticks/HoneycombBravo.cs | 138 +++++++++++++++------ MobiFlight/Joysticks/LabeledJoystick.cs | 52 ++++++++ MobiFlight/Joysticks/SaitekAviatorStick.cs | 30 +++++ MobiFlight/MobiFlightModule.cs | 50 +++++++- MobiFlightConnector.csproj | 2 + UI/Dialogs/InputConfigWizard.cs | 17 +-- 9 files changed, 292 insertions(+), 72 deletions(-) create mode 100644 MobiFlight/Joysticks/LabeledJoystick.cs create mode 100644 MobiFlight/Joysticks/SaitekAviatorStick.cs diff --git a/MobiFlight/ExecutionManager.cs b/MobiFlight/ExecutionManager.cs index a66e85b45..5656441ac 100644 --- a/MobiFlight/ExecutionManager.cs +++ b/MobiFlight/ExecutionManager.cs @@ -1278,7 +1278,7 @@ void mobiFlightCache_OnButtonPressed(object sender, InputEventArgs e) eventAction = MobiFlightAnalogInput.InputEventIdToString(0) + " => " +e.Value; } - var msgEventLabel = $"{e.Name} => {e.DeviceId} {(e.ExtPin.HasValue ? $":{e.ExtPin}" : "")} => {eventAction}"; + var msgEventLabel = $"{e.Name} => {e.DeviceLabel} {(e.ExtPin.HasValue ? $":{e.ExtPin}" : "")} => {eventAction}"; lock (inputCache) { diff --git a/MobiFlight/Joystick.cs b/MobiFlight/Joystick.cs index 86f00665f..663f267a1 100644 --- a/MobiFlight/Joystick.cs +++ b/MobiFlight/Joystick.cs @@ -1,12 +1,7 @@ -using System; +using SharpDX.DirectInput; +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; -using System.Web.SessionState; -using SharpDX; -using SharpDX.DirectInput; namespace MobiFlight { @@ -94,7 +89,7 @@ public Joystick(SharpDX.DirectInput.Joystick joystick) this.joystick = joystick; } - private void EnumerateDevices() + protected virtual void EnumerateDevices() { foreach (DeviceObjectInstance device in this.joystick.GetObjects()) { @@ -115,23 +110,26 @@ private void EnumerateDevices() if (IsAxis && Axes.Count < joystick.Capabilities.AxeCount) { String OffsetAxisName = "Unknown"; + var FriendlyAxisName = name; try { OffsetAxisName = GetAxisNameForUsage(usage); + FriendlyAxisName = GetFriendlyAxisName(name); + } catch (ArgumentOutOfRangeException ex) { - Log.Instance.log($"Axis can't be mapped: {joystick.Information.InstanceName} Aspect: {aspect} Offset: {offset} Usage: {usage} Axis: {name}.", LogSeverity.Error); + Log.Instance.log($"Axis can't be mapped: {joystick.Information.InstanceName} Aspect: {aspect} Offset: {offset} Usage: {usage} Axis: {name} Label: {FriendlyAxisName}.", LogSeverity.Error); continue; } - Axes.Add(new JoystickDevice() { Name = AxisPrefix + OffsetAxisName, Label = name, Type = JoystickDeviceType.Axis }); - Log.Instance.log($"Added {joystick.Information.InstanceName} Aspect {aspect} + Offset: {offset} Usage: {usage} Axis: {name}.", LogSeverity.Debug); + Axes.Add(new JoystickDevice() { Name = AxisPrefix + OffsetAxisName, Label = FriendlyAxisName, Type = JoystickDeviceType.Axis }); + Log.Instance.log($"Added {joystick.Information.InstanceName} Aspect {aspect} + Offset: {offset} Usage: {usage} Axis: {name} Label: {FriendlyAxisName}.", LogSeverity.Debug); } else if (IsButton) { - String ButtonName = CorrectButtonIndexForButtonName(name, Buttons.Count + 1); + String ButtonName = GetFriendlyButtonName(name, Buttons.Count + 1); Buttons.Add(new JoystickDevice() { Name = ButtonPrefix + (Buttons.Count + 1), Label = ButtonName, Type = JoystickDeviceType.Button }); - Log.Instance.log($"Added {joystick.Information.InstanceName} Aspect: {aspect} Offset: {offset} Usage: {usage} Button: {name}.", LogSeverity.Debug); + Log.Instance.log($"Added {joystick.Information.InstanceName} Aspect: {aspect} Offset: {offset} Usage: {usage} Button: {name} Label: {ButtonName}.", LogSeverity.Debug); } else if (IsPOV) { @@ -151,9 +149,19 @@ private void EnumerateDevices() } } - private string CorrectButtonIndexForButtonName(string name, int v) + protected string GetFriendlyAxisName(string name) + { + return MapDeviceNameToLabel(name); + } + + protected string GetFriendlyButtonName(string name, int v) { - return Regex.Replace(name, @"\d+", v.ToString()).ToString(); + return MapDeviceNameToLabel(Regex.Replace(name, @"\d+", v.ToString()).ToString()); + } + + protected virtual string MapDeviceNameToLabel(string deviceName) + { + return deviceName; } public void Connect(IntPtr handle) @@ -174,7 +182,8 @@ virtual protected void EnumerateOutputDevices() public List GetAvailableDevices() { List result = new List(); - Buttons.ForEach((item) => + + GetButtonsSorted().ForEach((item) => { result.Add(item.ToListItem()); }); @@ -189,6 +198,16 @@ public List GetAvailableDevices() return result; } + protected virtual List GetButtonsSorted() + { + return Buttons; + } + + protected virtual List GetAxisSorted() + { + return Axes; + } + public List GetAvailableOutputDevices() { List result = new List(); @@ -206,6 +225,7 @@ public void Update() try { joystick.Poll(); + JoystickState newState = joystick.GetCurrentState(); UpdateButtons(newState); UpdateAxis(newState); @@ -243,7 +263,8 @@ private void UpdatePOV(JoystickState newState) OnButtonPressed?.Invoke(this, new InputEventArgs() { Name = Name, - DeviceId = POV[index].Label, + DeviceId = POV[index].Name, + DeviceLabel = POV[index].Label, Serial = SerialPrefix + joystick.Information.InstanceGuid.ToString(), Type = DeviceType.Button, Value = (int)MobiFlightButton.InputEvent.RELEASE @@ -258,7 +279,8 @@ private void UpdatePOV(JoystickState newState) OnButtonPressed?.Invoke(this, new InputEventArgs() { Name = Name, - DeviceId = POV[index].Label, + DeviceId = POV[index].Name, + DeviceLabel = POV[index].Label, Serial = SerialPrefix + joystick.Information.InstanceGuid.ToString(), Type = DeviceType.Button, Value = (int)MobiFlightButton.InputEvent.PRESS @@ -286,7 +308,8 @@ private void UpdateAxis(JoystickState newState) OnButtonPressed?.Invoke(this, new InputEventArgs() { Name = Name, - DeviceId = Axes[CurrentAxis].Label, + DeviceId = Axes[CurrentAxis].Name, + DeviceLabel = Axes[CurrentAxis].Label, Serial = SerialPrefix + joystick.Information.InstanceGuid.ToString(), Type = DeviceType.AnalogInput, Value = newValue @@ -308,7 +331,8 @@ private void UpdateButtons(JoystickState newState) OnButtonPressed?.Invoke(this, new InputEventArgs() { Name = Name, - DeviceId = Buttons[i].Label, + DeviceId = Buttons[i].Name, + DeviceLabel = Buttons[i].Label, Serial = SerialPrefix + joystick.Information.InstanceGuid.ToString(), Type = DeviceType.Button, Value = newState.Buttons[i] ? 0 : 1 diff --git a/MobiFlight/JoystickManager.cs b/MobiFlight/JoystickManager.cs index ad974e341..a4111734a 100644 --- a/MobiFlight/JoystickManager.cs +++ b/MobiFlight/JoystickManager.cs @@ -80,8 +80,15 @@ public void Connect(IntPtr Handle) if (d.InstanceName == "Bravo Throttle Quadrant") { js = new Joysticks.HoneycombBravo(new SharpDX.DirectInput.Joystick(di, d.InstanceGuid)); - } else + } else if (d.InstanceName == "Saitek Aviator Stick") + { + js = new Joysticks.SaitekAviatorStick(new SharpDX.DirectInput.Joystick(di, d.InstanceGuid)); + } + else + { js = new Joystick(new SharpDX.DirectInput.Joystick(di, d.InstanceGuid)); + } + if (!HasAxisOrButtons(js)) continue; diff --git a/MobiFlight/Joysticks/HoneycombBravo.cs b/MobiFlight/Joysticks/HoneycombBravo.cs index 9fa31665f..cead86fd5 100644 --- a/MobiFlight/Joysticks/HoneycombBravo.cs +++ b/MobiFlight/Joysticks/HoneycombBravo.cs @@ -1,21 +1,85 @@ -using System; +using HidSharp; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HidSharp; namespace MobiFlight.Joysticks { - internal class HoneycombBravo : Joystick + internal class HoneycombBravo : LabeledJoystick { int VendorId = 0x294B; int ProductId = 0x1901; HidStream Stream { get; set; } HidDevice Device { get; set; } - public HoneycombBravo(SharpDX.DirectInput.Joystick joystick) : base(joystick) - { + public HoneycombBravo(SharpDX.DirectInput.Joystick joystick) : base(joystick) { + Labels = new Dictionary() + { + // Mode + { "Button 17", "Mode - IAS" }, + { "Button 18", "Mode - CRS" }, + { "Button 19", "Mode - HDG" }, + { "Button 20", "Mode - VS" }, + { "Button 21", "Mode - ALT" }, + // AP Buttons + { "Button 1", "AP - HDG" }, + { "Button 2", "AP - NAV" }, + { "Button 3", "AP - APR" }, + { "Button 4", "AP - REV" }, + { "Button 5", "AP - ALT" }, + { "Button 6", "AP - VS" }, + { "Button 7", "AP - IAS" }, + { "Button 8", "AP - Autopilot" }, + // Generic Encoder + { "Button 13", "Encoder - Right" }, + { "Button 14", "Encoder - Left" }, + // Gear + { "Button 31", "Gear - Up" }, + { "Button 32", "Gear - Down" }, + // Flaps + { "Button 16", "Flaps - Up" }, + { "Button 15", "Flaps - Down" }, + // Trim + { "Button 22", "Trim - Nose Down" }, + { "Button 23", "Trim - Nose Up" }, + // Levers + { "Button 24", "Lever 1 - Detent" }, + { "Button 25", "Lever 2 - Detent" }, + { "Button 26", "Lever 3 - Detent" }, + { "Button 27", "Lever 4 - Detent" }, + { "Button 28", "Lever 5 - Detent" }, + { "Button 33", "Lever 6 - Detent" }, + // + { "Button 29", "Lever 1 - Button" }, + { "Button 9", "Lever 2 - Button" }, + { "Button 10", "Lever 3 - Button" }, + { "Button 11", "Lever 4 - Button" }, + { "Button 12", "Lever 5 - Button" }, + // + { "Button 30", "Lever 3 - Reverser" }, + { "Button 48", "Lever 4 - Reverser" }, + + // + { "Button 34", "Switch 1 - Up" }, + { "Button 35", "Switch 1 - Down" }, + { "Button 36", "Switch 2 - Up" }, + { "Button 37", "Switch 2 - Down" }, + { "Button 38", "Switch 3 - Up" }, + { "Button 39", "Switch 3 - Down" }, + { "Button 40", "Switch 4 - Up" }, + { "Button 41", "Switch 4 - Down" }, + { "Button 42", "Switch 5 - Up" }, + { "Button 43", "Switch 5 - Down" }, + { "Button 44", "Switch 6 - Up" }, + { "Button 45", "Switch 6 - Down" }, + { "Button 46", "Switch 7 - Up" }, + { "Button 47", "Switch 7 - Down" }, + // Axis + { "Y Axis", "Axis - Lever 1" }, + { "X Axis", "Axis - Lever 2" }, + { "Z Rotation", "Axis - Lever 3" }, + { "Y Rotation", "Axis - Lever 4" }, + { "X Rotation", "Axis - Lever 5" }, + { "Z Axis", "Axis - Lever 6" }, + }; } public void Connect() @@ -43,39 +107,37 @@ protected override void SendData(byte[] data) protected override void EnumerateOutputDevices() { base.EnumerateOutputDevices(); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - HDG", Name = "AP.hdg", Byte = 1, Bit = 0 }); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - NAV", Name = "AP.nav", Byte = 1, Bit = 1 }); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - APR", Name = "AP.apr", Byte = 1, Bit = 2 }); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - REV", Name = "AP.rev", Byte = 1, Bit = 3 }); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - ALT", Name = "AP.alt", Byte = 1, Bit = 4 }); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - VS", Name = "AP.vs", Byte = 1, Bit = 5 }); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - IAS", Name = "AP.ias", Byte = 1, Bit = 6 }); - Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - On/Off", Name = "AP.autopilot", Byte = 1, Bit = 7 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - HDG", Name = "AP.hdg", Byte = 1, Bit = 0 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - NAV", Name = "AP.nav", Byte = 1, Bit = 1 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - APR", Name = "AP.apr", Byte = 1, Bit = 2 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - REV", Name = "AP.rev", Byte = 1, Bit = 3 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - ALT", Name = "AP.alt", Byte = 1, Bit = 4 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - VS", Name = "AP.vs", Byte = 1, Bit = 5 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - IAS", Name = "AP.ias", Byte = 1, Bit = 6 }); + Lights.Add(new JoystickOutputDevice() { Label = "AP Mode - On/Off", Name = "AP.autopilot", Byte = 1, Bit = 7 }); // -- Byte 2 - Lights.Add(new JoystickOutputDevice() { Label = "Gear - Left Green", Name = "Gear.LeftGreen", Byte = 2, Bit = 0 }); - Lights.Add(new JoystickOutputDevice() { Label = "Gear - Left Red", Name = "Gear.LeftRed", Byte = 2, Bit = 1 }); - Lights.Add(new JoystickOutputDevice() { Label = "Gear - Center Green", Name = "Gear.CenterGreen", Byte = 2, Bit = 2 }); - Lights.Add(new JoystickOutputDevice() { Label = "Gear - Center Red", Name = "Gear.CenterRed", Byte = 2, Bit = 3 }); - Lights.Add(new JoystickOutputDevice() { Label = "Gear - Right Green", Name = "Gear.RightGreen", Byte = 2, Bit = 4 }); - Lights.Add(new JoystickOutputDevice() { Label = "Gear - Right Red", Name = "Gear.RightRed", Byte = 2, Bit = 5 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Master Warning", Name = "Light.MasterWarn", Byte = 2, Bit = 6 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Engine Fire", Name = "Light.EngineFire", Byte = 2, Bit = 7 }); + Lights.Add(new JoystickOutputDevice() { Label = "Gear - Left Green", Name = "Gear.LeftGreen", Byte = 2, Bit = 0 }); + Lights.Add(new JoystickOutputDevice() { Label = "Gear - Left Red", Name = "Gear.LeftRed", Byte = 2, Bit = 1 }); + Lights.Add(new JoystickOutputDevice() { Label = "Gear - Center Green", Name = "Gear.CenterGreen", Byte = 2, Bit = 2 }); + Lights.Add(new JoystickOutputDevice() { Label = "Gear - Center Red", Name = "Gear.CenterRed", Byte = 2, Bit = 3 }); + Lights.Add(new JoystickOutputDevice() { Label = "Gear - Right Green", Name = "Gear.RightGreen", Byte = 2, Bit = 4 }); + Lights.Add(new JoystickOutputDevice() { Label = "Gear - Right Red", Name = "Gear.RightRed", Byte = 2, Bit = 5 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Master Warning", Name = "Light.MasterWarn", Byte = 2, Bit = 6 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Engine Fire", Name = "Light.EngineFire", Byte = 2, Bit = 7 }); // -- Byte 3 - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Oil Pressure", Name = "Light.LowOil", Byte = 3, Bit = 0 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Fuel Pressure", Name = "Light.LowFuel", Byte = 3, Bit = 1 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Anti Ice", Name = "Light.Antiice", Byte = 3, Bit = 2 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Starter Engaged", Name = "Light.Starter", Byte = 3, Bit = 3 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - APU", Name = "Light.APU", Byte = 3, Bit = 4 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Master Caution", Name = "Light.MasterCaution", Byte = 3, Bit = 5 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Vacuum", Name = "Light.Vacuum", Byte = 3, Bit = 6 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Hyd Pressure", Name = "Light.LowHydPressURE", Byte = 3, Bit = 7 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Oil Pressure", Name = "Light.LowOil", Byte = 3, Bit = 0 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Fuel Pressure", Name = "Light.LowFuel", Byte = 3, Bit = 1 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Anti Ice", Name = "Light.Antiice", Byte = 3, Bit = 2 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Starter Engaged", Name = "Light.Starter", Byte = 3, Bit = 3 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - APU", Name = "Light.APU", Byte = 3, Bit = 4 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Master Caution", Name = "Light.MasterCaution", Byte = 3, Bit = 5 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Vacuum", Name = "Light.Vacuum", Byte = 3, Bit = 6 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Hyd Pressure", Name = "Light.LowHydPressURE", Byte = 3, Bit = 7 }); // -- Byte 4 - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Aux Fuel Pump", Name = "Lights.AuxFuelPump", Byte = 4, Bit = 0 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Parking Brake", Name = "Lights.ParkingBrake", Byte = 4, Bit = 1 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Volts", Name = "Lights.LowVolts", Byte = 4, Bit = 2 }); - Lights.Add(new JoystickOutputDevice() { Label = "Lights - Door", Name = "Lights.door", Byte = 4, Bit = 3 }); - - + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Aux Fuel Pump", Name = "Lights.AuxFuelPump", Byte = 4, Bit = 0 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Parking Brake", Name = "Lights.ParkingBrake", Byte = 4, Bit = 1 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Low Volts", Name = "Lights.LowVolts", Byte = 4, Bit = 2 }); + Lights.Add(new JoystickOutputDevice() { Label = "Lights - Door", Name = "Lights.door", Byte = 4, Bit = 3 }); } } } diff --git a/MobiFlight/Joysticks/LabeledJoystick.cs b/MobiFlight/Joysticks/LabeledJoystick.cs new file mode 100644 index 000000000..232b9edf5 --- /dev/null +++ b/MobiFlight/Joysticks/LabeledJoystick.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MobiFlight.Joysticks +{ + public class LabeledJoystick : Joystick + { + protected Dictionary Labels = new Dictionary(); + + public LabeledJoystick(SharpDX.DirectInput.Joystick joystick) : base(joystick) { } + + protected override List GetButtonsSorted() + { + var buttons = Buttons.ToArray().ToList(); + buttons.Sort(SortByPositionInDictionary); + + return buttons; + } + + protected override string MapDeviceNameToLabel(string name) + { + var result = name; + + if (Labels.ContainsKey(name)) + result = Labels[name]; + + return result; + } + + protected override List GetAxisSorted() + { + var axes = Axes.ToArray().ToList(); + Axes.Sort(SortByPositionInDictionary); + + return axes; + } + + public int GetIndexForKey(string key) + { + int result = Array.IndexOf(Labels.Keys.ToArray(), key); + return result; + } + + int SortByPositionInDictionary(JoystickDevice b1, JoystickDevice b2) + { + if (GetIndexForKey(b1.Name) == GetIndexForKey(b2.Name)) return 0; + if (GetIndexForKey(b1.Name) > GetIndexForKey(b2.Name)) return 1; + return -1; + } + } +} diff --git a/MobiFlight/Joysticks/SaitekAviatorStick.cs b/MobiFlight/Joysticks/SaitekAviatorStick.cs new file mode 100644 index 000000000..2c7466758 --- /dev/null +++ b/MobiFlight/Joysticks/SaitekAviatorStick.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; + +namespace MobiFlight.Joysticks +{ + internal class SaitekAviatorStick : LabeledJoystick + { + int VendorId = 0x06A3; + int ProductId = 0x0461; + + public SaitekAviatorStick(SharpDX.DirectInput.Joystick joystick) : base(joystick) { + Labels = new Dictionary() + { + // Button 1-4 are not labeled + // --- + // Front switches + { "Button 5", "Button - T1" }, + { "Button 6", "Button - T2" }, + { "Button 7", "Button - T3" }, + { "Button 8", "Button - T4" }, + { "Button 9", "Button - T5" }, + { "Button 10", "Button - T6" }, + { "Button 11", "Button - T7" }, + { "Button 12", "Button - T8" }, + { "Button 13", "Mode A" }, + { "Button 14", "Mode B" } + // Throttles & Axis are not labeled + }; + } + } +} diff --git a/MobiFlight/MobiFlightModule.cs b/MobiFlight/MobiFlightModule.cs index 281e65d1b..ebd93bcc4 100644 --- a/MobiFlight/MobiFlightModule.cs +++ b/MobiFlight/MobiFlightModule.cs @@ -14,6 +14,7 @@ public class InputEventArgs : EventArgs { public string Serial { get; set; } public string DeviceId { get; set; } + public string DeviceLabel { get; set; } public string Name { get; set; } public DeviceType Type { get; set; } public int? ExtPin { get; set; } @@ -504,7 +505,14 @@ void OnEncoderChange(ReceivedCommand arguments) if (!int.TryParse(pos, out value)) return; if (OnInputDeviceAction != null) - OnInputDeviceAction(this, new InputEventArgs() { Serial = this.Serial, Name = Name, DeviceId = enc, Type = DeviceType.Encoder, Value = value }); + OnInputDeviceAction(this, new InputEventArgs() { + Serial = this.Serial, + Name = Name, + DeviceId = enc, + DeviceLabel = enc, + Type = DeviceType.Encoder, + Value = value + }); //addLog("Enc: " + enc + ":" + pos); } @@ -514,7 +522,15 @@ void OnInputShiftRegisterChange(ReceivedCommand arguments) String channel = arguments.ReadStringArg(); String state = arguments.ReadStringArg(); if (OnInputDeviceAction != null) - OnInputDeviceAction(this, new InputEventArgs() { Serial = this.Serial, Name = Name, DeviceId = deviceId, Type = DeviceType.InputShiftRegister, ExtPin = int.Parse(channel), Value = int.Parse(state) }); + OnInputDeviceAction(this, new InputEventArgs() { + Serial = this.Serial, + Name = Name, + DeviceId = deviceId, + DeviceLabel = deviceId, + Type = DeviceType.InputShiftRegister, + ExtPin = int.Parse(channel), + Value = int.Parse(state) + }); } void OnInputMultiplexerChange(ReceivedCommand arguments) @@ -523,7 +539,15 @@ void OnInputMultiplexerChange(ReceivedCommand arguments) String channel = arguments.ReadStringArg(); String state = arguments.ReadStringArg(); if (OnInputDeviceAction != null) - OnInputDeviceAction(this, new InputEventArgs() { Serial = this.Serial, Name = Name, DeviceId = deviceId, Type = DeviceType.InputMultiplexer, ExtPin = int.Parse(channel), Value = int.Parse(state) }); + OnInputDeviceAction(this, new InputEventArgs() { + Serial = this.Serial, + Name = Name, + DeviceId = deviceId, + DeviceLabel = deviceId, + Type = DeviceType.InputMultiplexer, + ExtPin = int.Parse(channel), + Value = int.Parse(state) + }); } // Callback function that prints the Arduino status to the console @@ -533,7 +557,14 @@ void OnButtonChange(ReceivedCommand arguments) String state = arguments.ReadStringArg(); //addLog("Button: " + button + ":" + state); if (OnInputDeviceAction != null) - OnInputDeviceAction(this, new InputEventArgs() { Serial = this.Serial, Name = Name, DeviceId = button, Type = DeviceType.Button, Value = int.Parse(state) }); + OnInputDeviceAction(this, new InputEventArgs() { + Serial = this.Serial, + Name = Name, + DeviceId = button, + DeviceLabel = button, + Type = DeviceType.Button, + Value = int.Parse(state) + }); } // Callback function that prints the Arduino status to the console @@ -543,7 +574,14 @@ void OnAnalogChange(ReceivedCommand arguments) String value = arguments.ReadStringArg(); //addLog("Button: " + button + ":" + state); if (OnInputDeviceAction != null) - OnInputDeviceAction(this, new InputEventArgs() { Serial = this.Serial, Name = Name, DeviceId = name, Type = DeviceType.AnalogInput, Value = int.Parse(value) }); + OnInputDeviceAction(this, new InputEventArgs() { + Serial = this.Serial, + Name = Name, + DeviceId = name, + DeviceLabel = name, + Type = DeviceType.AnalogInput, + Value = int.Parse(value) + }); } // Callback function that prints the Arduino Debug Print to the console @@ -999,6 +1037,8 @@ public IEnumerable GetConnectedInputDeviceTypes() break; } } + + result.Sort((a, b) => { return a.Name.CompareTo(b.Name); }); return result; } diff --git a/MobiFlightConnector.csproj b/MobiFlightConnector.csproj index faf8859e7..99418094f 100644 --- a/MobiFlightConnector.csproj +++ b/MobiFlightConnector.csproj @@ -252,6 +252,8 @@ + + diff --git a/UI/Dialogs/InputConfigWizard.cs b/UI/Dialogs/InputConfigWizard.cs index e3c458a6c..cbc8f0b58 100644 --- a/UI/Dialogs/InputConfigWizard.cs +++ b/UI/Dialogs/InputConfigWizard.cs @@ -2,13 +2,9 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; -using MobiFlight; using MobiFlight.Base; -using MobiFlight.UI.Panels; +using MobiFlight.Config; using MobiFlight.UI.Panels.Input; namespace MobiFlight.UI.Dialogs @@ -247,7 +243,7 @@ protected bool _syncConfigToForm(InputConfigItem config) } // second tab - if (!ComboBoxHelper.SetSelectedItem(inputTypeComboBox, config.Name)) + if (!ComboBoxHelper.SetSelectedItemByValue(inputTypeComboBox, config.Name)) { // TODO: provide error message Log.Instance.log("Exception on selecting item in display type ComboBox.", LogSeverity.Error); @@ -285,7 +281,14 @@ private void PopulateInputPinDropdown(int numModules, int? selectedPin) protected bool _syncFormToConfig() { config.ModuleSerial = inputModuleNameComboBox.SelectedItem.ToString(); - config.Name = inputTypeComboBox.Text; + + 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);