diff --git a/MobiFlight/FirmwareFeature.cs b/MobiFlight/FirmwareFeature.cs index 401be2150..346b55322 100644 --- a/MobiFlight/FirmwareFeature.cs +++ b/MobiFlight/FirmwareFeature.cs @@ -6,5 +6,6 @@ public class FirmwareFeature public const string SetName = "1.6.0"; public const string LedModuleTypeTM1637 = "2.4.2"; public const string CustomDevices = "2.4.2"; + public const string AccessOutputByDeviceIndex = "3.0.0"; } } diff --git a/MobiFlight/MobiFlightModule.cs b/MobiFlight/MobiFlightModule.cs index dd06f5fb3..9188ada06 100644 --- a/MobiFlight/MobiFlightModule.cs +++ b/MobiFlight/MobiFlightModule.cs @@ -382,8 +382,8 @@ public void LoadConfig() break; case DeviceType.Output: device.Name = GenerateUniqueDeviceName(outputs.Keys.ToArray(), device.Name); - Int16 pin; - if (!Int16.TryParse((device as Config.Output).Pin, out pin)) + + if (!Int16.TryParse((device as Config.Output).Pin, out short pin)) { Log.Instance.log( $"Can't parse {Board.Info.FriendlyName} ({Port}) > [{(device as Config.Output).Name}]." + @@ -391,12 +391,29 @@ public void LoadConfig() LogSeverity.Error); break; } - outputs.Add(device.Name, new MobiFlightOutput() + if (HasFirmwareFeature(FirmwareFeature.AccessOutputByDeviceIndex)) { - CmdMessenger = _cmdMessenger, - Name = device.Name, - Pin = pin - }); + outputs.Add(device.Name, new MobiFlightOutputV3() + { + CmdMessenger = _cmdMessenger, + Name = device.Name, + DeviceIndex = outputs.Count, + // Required for UI so that we can check + // whether pin supports PWM or not. + // Not required for the messages to Arduino anymore + Pin = pin + + }); + } + else + { + outputs.Add(device.Name, new MobiFlightOutput() + { + CmdMessenger = _cmdMessenger, + Name = device.Name, + Pin = pin, + }); + } break; case DeviceType.LcdDisplay: device.Name = GenerateUniqueDeviceName(lcdDisplays.Keys.ToArray(), device.Name); diff --git a/MobiFlight/MobiFlightOutput.cs b/MobiFlight/MobiFlightOutput.cs index 054a73945..872cd90a2 100644 --- a/MobiFlight/MobiFlightOutput.cs +++ b/MobiFlight/MobiFlightOutput.cs @@ -27,17 +27,16 @@ public DeviceType Type public CmdMessenger CmdMessenger { get; set; } public int Pin { get; set; } - - public MobiFlightOutput() { } - public void Set(int value) + public virtual void Set(int value) { var command = new SendCommand((int)MobiFlightModule.Command.SetPin); + + Log.Instance.log($"Command: SetPin <{(int)MobiFlightModule.Command.SetPin},{Pin},{value};>.", LogSeverity.Debug); + command.AddArgument(Pin); command.AddArgument(value); // Send command - Log.Instance.log($"Command: SetPin <{(int)MobiFlightModule.Command.SetPin},{Pin},{value};>.", LogSeverity.Debug); - CmdMessenger.SendCommand(command); } @@ -46,4 +45,21 @@ public void Stop() Set(0); } } + + public class MobiFlightOutputV3 : MobiFlightOutput + { + public int DeviceIndex { get; set; } + + public override void Set(int value) + { + var command = new SendCommand((int)MobiFlightModule.Command.SetPin); + + Log.Instance.log($"Command: SetPin <{(int)MobiFlightModule.Command.SetPin},{DeviceIndex},{value};>.", LogSeverity.Debug); + + command.AddArgument(DeviceIndex); + command.AddArgument(value); + // Send command + CmdMessenger.SendCommand(command); + } + } }