Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Outputs via DeviceID #1950

Merged
merged 3 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MobiFlight/FirmwareFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
31 changes: 24 additions & 7 deletions MobiFlight/MobiFlightModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,38 @@ 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}]." +
$"Pin: {(device as Config.Output).Pin}, skipping device.",
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);
Expand Down
26 changes: 21 additions & 5 deletions MobiFlight/MobiFlightOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}
}