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

Add interface for plugins to add HW and SW config pages #3433

Merged
merged 1 commit into from
Nov 3, 2024
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
72 changes: 70 additions & 2 deletions GCSViews/InitialSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MissionPlanner.Radio;
using MissionPlanner.Utilities;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Resources;
using System.Windows.Forms;
Expand All @@ -17,6 +18,44 @@ public partial class InitialSetup : MyUserControl, IActivate
internal static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static string lastpagename = "";

[Flags]
public enum pageOptions
{
none = 0,
isConnected = 1,
isDisConnected = 2,
isTracker = 4,
isCopter = 8,
isCopter35plus = 16,
isHeli = 32,
isQuadPlane = 64,
isPlane = 128,
isRover = 256,
gotAllParams = 512
}

public class pluginPage
{
public Type page;
public string headerText;
public pageOptions options;

public pluginPage(Type page, string headerText, pageOptions options)
{
this.page = page;
this.headerText = headerText;
this.options = options;
}
}


private static List<pluginPage> pluginViewPages = new List<pluginPage>();
public static void AddPluginViewPage(Type page, string headerText, pageOptions options = pageOptions.none)
{
pluginViewPages.Add(new pluginPage(page, headerText, options));
}


public InitialSetup()
{
InitializeComponent();
Expand Down Expand Up @@ -92,7 +131,7 @@ public bool gotAllParams
}
}

private BackstageViewPage AddBackstageViewPage(Type userControl, string headerText, bool enabled = true,
public BackstageViewPage AddBackstageViewPage(Type userControl, string headerText, bool enabled = true,
BackstageViewPage Parent = null, bool advanced = false)
{
try
Expand Down Expand Up @@ -138,7 +177,7 @@ private void HardwareConfig_Load(object sender, EventArgs e)

AddBackstageViewPage(typeof(ConfigSecureAP), "Secure",
isDisConnected);


var mand = AddBackstageViewPage(typeof(ConfigMandatory), rm.GetString("backstageViewPagemand.Text"), isConnected && gotAllParams);

Expand Down Expand Up @@ -309,6 +348,35 @@ private void HardwareConfig_Load(object sender, EventArgs e)
}
}


foreach (var item in pluginViewPages)
{

// go through all options
if (item.options.HasFlag(pageOptions.isConnected) && !isConnected)
continue;
if (item.options.HasFlag(pageOptions.isDisConnected) && !isDisConnected)
continue;
if (item.options.HasFlag(pageOptions.isTracker) && !isTracker)
continue;
if (item.options.HasFlag(pageOptions.isCopter) && !isCopter)
continue;
if (item.options.HasFlag(pageOptions.isCopter35plus) && !isCopter35plus)
continue;
if (item.options.HasFlag(pageOptions.isHeli) && !isHeli)
continue;
if (item.options.HasFlag(pageOptions.isQuadPlane) && !isQuadPlane)
continue;
if (item.options.HasFlag(pageOptions.isPlane) && !isPlane)
continue;
if (item.options.HasFlag(pageOptions.isRover) && !isRover)
continue;
if (item.options.HasFlag(pageOptions.gotAllParams) && !gotAllParams)
continue;

AddBackstageViewPage(item.page, item.headerText);
}

// remeber last page accessed
foreach (BackstageViewPage page in backstageView.Pages)
{
Expand Down
122 changes: 119 additions & 3 deletions GCSViews/SoftwareConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MissionPlanner.GCSViews.ConfigurationView;
using MissionPlanner.Utilities;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;

Expand All @@ -13,7 +14,93 @@ namespace MissionPlanner.GCSViews
public partial class SoftwareConfig : MyUserControl, IActivate
{
internal static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static string lastpagename = "";
private static string lastpagename = "";
[Flags]
public enum pageOptions
{
none = 0,
isConnected = 1,
isDisConnected = 2,
isTracker = 4,
isCopter = 8,
isCopter35plus = 16,
isHeli = 32,
isQuadPlane = 64,
isPlane = 128,
isRover = 256,
gotAllParams = 512
}

public class pluginPage
{
public Type page;
public string headerText;
public pageOptions options;

public pluginPage(Type page, string headerText, pageOptions options)
{
this.page = page;
this.headerText = headerText;
this.options = options;
}
}


private static List<pluginPage> pluginViewPages = new List<pluginPage>();

public static void AddPluginViewPage(Type page, string headerText, pageOptions options = pageOptions.none)
{
pluginViewPages.Add(new pluginPage(page, headerText, options));
}
public bool isConnected
{
get { return MainV2.comPort.BaseStream.IsOpen; }
}
public bool isTracker
{
get { return isConnected && MainV2.comPort.MAV.cs.firmware == Firmwares.ArduTracker; }
}

public bool isCopter
{
get { return isConnected && MainV2.comPort.MAV.cs.firmware == Firmwares.ArduCopter2; }
}

public bool isCopter35plus
{
get { return MainV2.comPort.MAV.cs.version >= Version.Parse("3.5"); }
}

public bool isHeli
{
get { return isConnected && MainV2.comPort.MAV.aptype == MAVLink.MAV_TYPE.HELICOPTER; }
}

public bool isQuadPlane
{
get
{
return isConnected && isPlane &&
MainV2.comPort.MAV.param.ContainsKey("Q_ENABLE") &&
(MainV2.comPort.MAV.param["Q_ENABLE"].Value == 1.0);
}
}

public bool isPlane
{
get
{
return isConnected &&
(MainV2.comPort.MAV.cs.firmware == Firmwares.ArduPlane ||
MainV2.comPort.MAV.cs.firmware == Firmwares.Ateryx);
}
}

public bool isRover
{
get { return isConnected && MainV2.comPort.MAV.cs.firmware == Firmwares.ArduRover; }
}


public bool gotAllParams
{
Expand All @@ -38,7 +125,7 @@ public void Activate()
{
}

private BackstageViewPage AddBackstageViewPage(Type userControl, string headerText,
public BackstageViewPage AddBackstageViewPage(Type userControl, string headerText,
BackstageViewPage Parent = null, bool advanced = false)
{
try
Expand Down Expand Up @@ -169,7 +256,36 @@ private void SoftwareConfig_Load(object sender, EventArgs e)
{
start = AddBackstageViewPage(typeof(ConfigPlanner), Strings.Planner);
}
}
}

// Add custrom pages set up by plugins
foreach (var item in pluginViewPages)
{

// go through all options expect disconnected since there is no meaning for sw config in disconnected state
if (item.options.HasFlag(pageOptions.isConnected) && !isConnected)
continue;
if (item.options.HasFlag(pageOptions.isTracker) && !isTracker)
continue;
if (item.options.HasFlag(pageOptions.isCopter) && !isCopter)
continue;
if (item.options.HasFlag(pageOptions.isCopter35plus) && !isCopter35plus)
continue;
if (item.options.HasFlag(pageOptions.isHeli) && !isHeli)
continue;
if (item.options.HasFlag(pageOptions.isQuadPlane) && !isQuadPlane)
continue;
if (item.options.HasFlag(pageOptions.isPlane) && !isPlane)
continue;
if (item.options.HasFlag(pageOptions.isRover) && !isRover)
continue;
if (item.options.HasFlag(pageOptions.gotAllParams) && !gotAllParams)
continue;

AddBackstageViewPage(item.page, item.headerText);
}



// apply theme before trying to display it
ThemeManager.ApplyThemeTo(this);
Expand Down
Loading