Servers by jDrones

Custom button in the Action tab in Mission planner

Hello,

I am looking to add a custom button to the actions tab that does the servo/relay tab 5 button function.

image

I have used c/c++ but not c#. To do this would I need to alter or create an cs file similar to the example-watchbutton.cs created in C:\Program Files (x86)\Mission Planner\plugins?

Any help would be appreciated!

thank you,

Hi !
You can add buttons to the action tab from a plugin like this

    MainV2.instance.BeginInvoke((MethodInvoker)(() =>
{
    TableLayoutPanel actionLayout = Host.MainForm.FlightData.Controls.Find("tableLayoutPanel1", true).FirstOrDefault() as TableLayoutPanel;

    MyButton btn1 = new MyButton();
    btn1.Text = "Button1";
    actionLayout.Controls.Add(btn1, 0, 4);

}));

There are three free spaces in the layout in Raw 4, column 0-2
Then set servo value by

_ = MainV2.comPort.doCommand((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, MAVLink.MAV_CMD.DO_SET_SERVO, servoID, servoValue, 0, 0, 0, 0, 0);

Thank you Andras for the response and the code! Sadly, I am struggling on how to implement the code(I’m new to c#) Looking at the example-watchbutton.cs below where would I add the code? I would assume that I would remove the private void MavOnOnPacketReceivedHandler() and the code in loaded() as well

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;

namespace Shortcuts
{
    public class ButtonPlugin : MissionPlanner.Plugin.Plugin
    {
        public override string Name
        {
            get { return "Button change"; }
        }

        public override string Version
        {
            get { return "0.1"; }
        }

        public override string Author
        {
            get { return "EOSBandi"; }
        }

        public override bool Init()
        {
            return true;
        }

        public override bool Loaded()
        {
            Host.comPort.OnPacketReceived += MavOnOnPacketReceivedHandler;
            return true;
        }

        public override bool Loop()
        {
            return true;
        }

        public override bool Exit()
        {
            return true;
        }

        private void MavOnOnPacketReceivedHandler(object o, MAVLink.MAVLinkMessage linkMessage)
        {
            if ((MAVLink.MAVLINK_MSG_ID) linkMessage.msgid == MAVLink.MAVLINK_MSG_ID.BUTTON_CHANGE)
            {
                //Button change message received
                //Check and display message
                Console.WriteLine("BUTTON CHANGE message received");
            }
        }
    }

thank you,

Jon Peyron

Servers by jDrones