2012-04-19 21:05:33 -03:00
|
|
|
|
using System;
|
2012-07-22 04:51:05 -03:00
|
|
|
|
using System.Reflection;
|
2012-04-19 21:05:33 -03:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using ArdupilotMega.Controls.BackstageView;
|
2012-07-22 04:51:05 -03:00
|
|
|
|
using log4net;
|
|
|
|
|
using Transitions;
|
2012-04-19 21:05:33 -03:00
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega.GCSViews.ConfigurationView
|
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
public partial class ConfigAccelerometerCalibrationQuad : UserControl, IActivate, IDeactivate
|
2012-04-19 21:05:33 -03:00
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
private const float DisabledOpacity = 0.2F;
|
|
|
|
|
private const float EnabledOpacity = 1.0F;
|
|
|
|
|
|
2012-04-19 21:05:33 -03:00
|
|
|
|
public ConfigAccelerometerCalibrationQuad()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BUT_levelac2_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#if MAVLINK10
|
2012-07-22 04:51:05 -03:00
|
|
|
|
Log.Info("Sending level command (mavlink 1.0)");
|
2012-04-19 21:05:33 -03:00
|
|
|
|
int fixme; // needs to be accel only
|
|
|
|
|
MainV2.comPort.doCommand(MAVLink.MAV_CMD.PREFLIGHT_CALIBRATION,1,1,1,1,1,1,1);
|
|
|
|
|
#else
|
2012-07-25 10:44:24 -03:00
|
|
|
|
Log.Info("Sending level command (mavlink 0.9)");
|
2012-04-19 21:05:33 -03:00
|
|
|
|
MainV2.comPort.doAction(MAVLink.MAV_ACTION.MAV_ACTION_CALIBRATE_ACC);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
BUT_levelac2.Text = "Complete";
|
|
|
|
|
}
|
2012-07-22 04:51:05 -03:00
|
|
|
|
catch(Exception ex)
|
2012-04-19 21:05:33 -03:00
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
Log.Error("Exception on level", ex);
|
2012-04-19 21:05:33 -03:00
|
|
|
|
CustomMessageBox.Show("Failed to level : ac2 2.0.37+ is required");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-22 04:51:05 -03:00
|
|
|
|
private void pictureBox_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (sender == pictureBoxPlus)
|
|
|
|
|
radioButton_Plus.Checked = true;
|
|
|
|
|
else
|
|
|
|
|
radioButton_X.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetPlus()
|
|
|
|
|
{
|
|
|
|
|
FadePicBoxes(DisabledOpacity, EnabledOpacity);
|
|
|
|
|
SetFrameParam(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetX()
|
|
|
|
|
{
|
|
|
|
|
FadePicBoxes(EnabledOpacity, DisabledOpacity);
|
|
|
|
|
SetFrameParam(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetFrameParam(bool isPlus)
|
2012-04-19 21:05:33 -03:00
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
var f = isPlus ? 0f : 1f;
|
|
|
|
|
|
2012-04-19 21:05:33 -03:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
MainV2.comPort.setParam("FRAME", f);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
CustomMessageBox.Show("Set frame failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
2012-04-19 21:05:33 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-22 04:51:05 -03:00
|
|
|
|
private void FadePicBoxes(float xOpacity, float plusOpacity)
|
2012-04-19 21:05:33 -03:00
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
var fade = new Transition(new TransitionType_Linear(400));
|
|
|
|
|
fade.add(pictureBoxX, "Opacity", xOpacity);
|
|
|
|
|
fade.add(pictureBoxPlus, "Opacity", plusOpacity);
|
|
|
|
|
fade.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Activate()
|
|
|
|
|
{
|
|
|
|
|
if ((float)MainV2.comPort.param["FRAME"] == 0)
|
2012-04-19 21:05:33 -03:00
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
this.radioButton_Plus.Checked = true;
|
|
|
|
|
pictureBoxX.Opacity = DisabledOpacity;
|
|
|
|
|
pictureBoxPlus.Opacity = EnabledOpacity;
|
2012-04-19 21:05:33 -03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-07-22 04:51:05 -03:00
|
|
|
|
this.radioButton_X.Checked = true;
|
|
|
|
|
pictureBoxX.Opacity = EnabledOpacity;
|
|
|
|
|
pictureBoxPlus.Opacity = DisabledOpacity;
|
2012-04-19 21:05:33 -03:00
|
|
|
|
}
|
2012-04-30 07:48:52 -03:00
|
|
|
|
|
2012-07-22 04:51:05 -03:00
|
|
|
|
radioButton_Plus.CheckedChanged += RadioButtonPlusCheckedChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deactivate()
|
|
|
|
|
{
|
|
|
|
|
radioButton_Plus.CheckedChanged -= RadioButtonPlusCheckedChanged;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RadioButtonPlusCheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (radioButton_X.Checked)
|
|
|
|
|
SetX();
|
|
|
|
|
else
|
|
|
|
|
SetPlus();
|
2012-04-19 21:05:33 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|