OK, let’s try a different aproach. Make sure that you use the latest MP beta. Create a filename.cs file with the code below and put it in the MissionPlanner/Plugins directory. It will be compiled in runtime. It adds a line to the context menu (right click) on Flight Planner…
The important part is in the but_click function…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MissionPlanner.Utilities;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using MissionPlanner;
using System.Drawing;
namespace Shortcuts
{
public class Plugin : MissionPlanner.Plugin.Plugin
{
ToolStripMenuItem but;
public override string Name
{
get { return "Small stuff"; }
}
public override string Version
{
get { return "0.10"; }
}
public override string Author
{
get { return "EOSBandi"; }
}
public override bool Init()
{
return true;
}
public override bool Loaded()
{
but = new ToolStripMenuItem("Fix mission top/bottom");
but.Click += but_Click;
ToolStripItemCollection col = Host.FPMenuMap.Items;
col.Insert(0, but);
return true;
}
public override bool Loop()
{
return true;
}
public override bool Exit()
{
return true;
}
//This for the Money
void but_Click(object sender, EventArgs e)
{
string angle = "0";
InputQuery("Enter Angle", "This will be the heading", ref angle);
int angle_in_number = Int32.Parse(angle);
Host.InsertWP(0, MAVLink.MAV_CMD.DO_SET_SERVO, 9, angle_in_number, 0, 0, 0, 0, 0);
Host.InsertWP(1, MAVLink.MAV_CMD.DO_SET_SERVO, 10, 1000, 0, 0, 0, 0, 0);
Host.AddWPtoList(MAVLink.MAV_CMD.DO_SET_SERVO, 9, 1000, 0, 0, 0, 0, 0);
Host.AddWPtoList(MAVLink.MAV_CMD.DO_SET_SERVO, 10, 1000, 0, 0, 0, 0, 0);
}
//// Utilities....
public static Boolean InputQuery(String caption, String prompt, ref String value)
{
Form form;
form = new Form();
form.AutoScaleMode = AutoScaleMode.Font;
//form.Font = MissionPlanner.Drawing.SystemFonts.IconTitleFont;
SizeF dialogUnits;
dialogUnits = form.AutoScaleDimensions;
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.Text = caption;
form.ClientSize = new Size(
MulDiv(180, (int)dialogUnits.Width, 4),
MulDiv(63, (int)dialogUnits.Height, 8));
form.StartPosition = FormStartPosition.CenterScreen;
System.Windows.Forms.Label lblPrompt;
lblPrompt = new System.Windows.Forms.Label();
lblPrompt.Parent = form;
lblPrompt.AutoSize = true;
lblPrompt.Left = MulDiv(8, (int)dialogUnits.Width, 4);
lblPrompt.Top = MulDiv(8, (int)dialogUnits.Height, 8);
lblPrompt.Text = prompt;
System.Windows.Forms.TextBox edInput;
edInput = new System.Windows.Forms.TextBox();
edInput.Parent = form;
edInput.Left = lblPrompt.Left;
edInput.Top = MulDiv(19, (int)dialogUnits.Height, 8);
edInput.Width = MulDiv(164,(int) dialogUnits.Width, 4);
edInput.Text = value;
edInput.SelectAll();
int buttonTop = MulDiv(41,(int) dialogUnits.Height, 8);
//Command buttons should be 50x14 dlus
Size buttonSize = new Size(50*(int)dialogUnits.Width/6, 14* (int)dialogUnits.Height/6);
System.Windows.Forms.Button bbOk = new System.Windows.Forms.Button();
bbOk.Parent = form;
bbOk.Text = "OK";
bbOk.DialogResult = DialogResult.OK;
form.AcceptButton = bbOk;
bbOk.Location = new Point(MulDiv(38, (int)dialogUnits.Width, 4), buttonTop);
bbOk.Size = buttonSize;
System.Windows.Forms.Button bbCancel = new System.Windows.Forms.Button();
bbCancel.Parent = form;
bbCancel.Text = "Cancel";
bbCancel.DialogResult = DialogResult.Cancel;
form.CancelButton = bbCancel;
bbCancel.Location = new Point(MulDiv(92, (int)dialogUnits.Width, 4), buttonTop);
bbCancel.Size = buttonSize;
if (form.ShowDialog() == DialogResult.OK)
{
value = edInput.Text;
return true;
}
else
{
return false;
}
}
/// <summary>
/// Multiplies two 32-bit values and then divides the 64-bit result by a
/// third 32-bit value. The final result is rounded to the nearest integer.
/// </summary>
public static int MulDiv(int nNumber, int nNumerator, int nDenominator)
{
return (int)Math.Round((float)nNumber * nNumerator / nDenominator);
}
}
}