2012-07-25 10:44:24 -03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega.Controls
|
|
|
|
|
{
|
|
|
|
|
public class MavlinkCheckBox : CheckBox
|
|
|
|
|
{
|
|
|
|
|
[System.ComponentModel.Browsable(true)]
|
|
|
|
|
public float OnValue { get; set; }
|
|
|
|
|
|
|
|
|
|
[System.ComponentModel.Browsable(true)]
|
|
|
|
|
public float OffValue { get; set; }
|
|
|
|
|
|
|
|
|
|
[System.ComponentModel.Browsable(true)]
|
|
|
|
|
public string ParamName { get; set; }
|
|
|
|
|
|
|
|
|
|
[System.ComponentModel.Browsable(true)]
|
|
|
|
|
public Hashtable param { get; set; }
|
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
Control _control;
|
|
|
|
|
|
2012-07-25 10:44:24 -03:00
|
|
|
|
public MavlinkCheckBox()
|
|
|
|
|
{
|
|
|
|
|
OnValue = 1;
|
|
|
|
|
OffValue = 0;
|
|
|
|
|
|
|
|
|
|
this.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public void setup(float OnValue, float OffValue, string paramname, Hashtable paramlist, Control enabledisable = null)
|
2012-07-25 10:44:24 -03:00
|
|
|
|
{
|
|
|
|
|
base.CheckedChanged -= MavlinkCheckBox_CheckedChanged;
|
|
|
|
|
|
|
|
|
|
this.OnValue = OnValue;
|
|
|
|
|
this.OffValue = OffValue;
|
|
|
|
|
this.ParamName = paramname;
|
|
|
|
|
this.param = paramlist;
|
2012-07-29 20:23:42 -03:00
|
|
|
|
this._control = enabledisable;
|
2012-07-25 10:44:24 -03:00
|
|
|
|
|
|
|
|
|
if (paramlist.ContainsKey(paramname))
|
|
|
|
|
{
|
|
|
|
|
this.Enabled = true;
|
|
|
|
|
|
|
|
|
|
if ((float)paramlist[paramname] == OnValue)
|
|
|
|
|
{
|
|
|
|
|
this.Checked = true;
|
2012-07-29 20:23:42 -03:00
|
|
|
|
enableControl(true);
|
2012-07-25 10:44:24 -03:00
|
|
|
|
}
|
|
|
|
|
else if ((float)paramlist[paramname] == OffValue)
|
|
|
|
|
{
|
|
|
|
|
this.Checked = false;
|
2012-07-29 20:23:42 -03:00
|
|
|
|
enableControl(false);
|
2012-07-25 10:44:24 -03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.CheckState = System.Windows.Forms.CheckState.Indeterminate;
|
2012-07-29 20:23:42 -03:00
|
|
|
|
enableControl(false);
|
2012-07-25 10:44:24 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-29 20:23:42 -03:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Enabled = false;
|
|
|
|
|
}
|
2012-07-25 10:44:24 -03:00
|
|
|
|
|
|
|
|
|
base.CheckedChanged += new EventHandler(MavlinkCheckBox_CheckedChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
void enableControl(bool enable)
|
|
|
|
|
{
|
|
|
|
|
if (_control != null)
|
|
|
|
|
_control.Enabled = enable;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 10:44:24 -03:00
|
|
|
|
void MavlinkCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.Checked)
|
|
|
|
|
{
|
2012-07-29 20:23:42 -03:00
|
|
|
|
enableControl(true);
|
2012-07-25 10:44:24 -03:00
|
|
|
|
if (!MainV2.comPort.setParam(ParamName, OnValue))
|
|
|
|
|
{
|
|
|
|
|
CustomMessageBox.Show("Set "+ParamName + " Failed!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-07-29 20:23:42 -03:00
|
|
|
|
enableControl(false);
|
2012-07-25 10:44:24 -03:00
|
|
|
|
if (!MainV2.comPort.setParam(ParamName, OffValue))
|
|
|
|
|
{
|
|
|
|
|
CustomMessageBox.Show("Set " + ParamName + " Failed!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|