Skip to content

Commit

Permalink
Check FW capabilities against CoreVersion (#1870)
Browse files Browse the repository at this point in the history
* Firmware features are now checked against CoreVersion
* add object clone()
  • Loading branch information
elral authored Dec 2, 2024
1 parent 0a3df96 commit fa27040
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions MobiFlight/MobiFlightModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ public MobiFlightModule(MobiFlightModuleInfo moduleInfo)
HardwareId = moduleInfo.HardwareId;
}

public object Clone()
{
var clone = new MobiFlightModule(this.ToMobiFlightModuleInfo());
clone.CoreVersion = this.CoreVersion;
return clone;
}

public void Connect()
{
if (this.Connected)
Expand Down Expand Up @@ -957,7 +964,7 @@ private static string FallbackCoreVersion(string version, Board board)

// Official partner boards were only built with > 2.5.0
if (board?.PartnerLevel == BoardPartnerLevel.Partner) return "2.5.0";
return null;
return version;
}

public bool SaveName()
Expand Down Expand Up @@ -1281,7 +1288,7 @@ public void SetPowerSaveMode(bool mode)
public bool GenerateNewSerial()
{
System.Version minVersion = new System.Version("1.3.0");
System.Version currentVersion = new System.Version(Version != null ? Version : "0.0.0");
System.Version currentVersion = new System.Version(CoreVersion != null ? CoreVersion : "0.0.0");
if (currentVersion.CompareTo(minVersion) < 0)
{
throw new FirmwareVersionTooLowException(minVersion, currentVersion);
Expand All @@ -1297,7 +1304,7 @@ public bool HasFirmwareFeature(String FirmwareFeature)
if (IsPullRequestBuild) return true;

System.Version minVersion = new System.Version(FirmwareFeature);
System.Version currentVersion = new System.Version(Version != null ? Version : "0.0.0");
System.Version currentVersion = new System.Version(CoreVersion != null ? CoreVersion : "0.0.0");

return (currentVersion.CompareTo(minVersion) >= 0);
}
Expand Down
3 changes: 2 additions & 1 deletion UI/Panels/Settings/MobiFlightPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,8 @@ private MobiFlightModule getVirtualModuleFromTree()
TreeNode moduleNode = getModuleNode();
if (moduleNode == null) return null;

MobiFlightModule module = new MobiFlightModule((moduleNode.Tag as MobiFlightModule).ToMobiFlightModuleInfo());
var module = (moduleNode.Tag as MobiFlightModule).Clone() as MobiFlightModule;

// Generate config
MobiFlight.Config.Config newConfig = new MobiFlight.Config.Config();
foreach (TreeNode node in moduleNode.Nodes)
Expand Down

0 comments on commit fa27040

Please sign in to comment.