2012-02-26 19:13:23 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega.Antenna
|
|
|
|
|
{
|
|
|
|
|
public partial class Tracker : Form
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread t12;
|
|
|
|
|
static bool threadrun = false;
|
|
|
|
|
static ITrackerOutput tracker;
|
|
|
|
|
|
|
|
|
|
public Tracker()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2012-03-03 20:42:42 -04:00
|
|
|
|
ThemeManager.ApplyThemeTo(this);
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
CMB_serialport.DataSource = SerialPort.GetPortNames();
|
|
|
|
|
|
|
|
|
|
if (threadrun)
|
|
|
|
|
{
|
|
|
|
|
BUT_connect.Text = "Disconnect";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BUT_connect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (threadrun)
|
|
|
|
|
{
|
|
|
|
|
threadrun = false;
|
|
|
|
|
BUT_connect.Text = "Connect";
|
|
|
|
|
tracker.Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
if (tracker != null && tracker.ComPort != null && tracker.ComPort.IsOpen)
|
|
|
|
|
{
|
|
|
|
|
tracker.ComPort.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-26 19:13:23 -04:00
|
|
|
|
tracker = new ArdupilotMega.Antenna.Maestro();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
tracker.ComPort = new SerialPort()
|
|
|
|
|
{
|
|
|
|
|
PortName = CMB_serialport.Text,
|
|
|
|
|
BaudRate = int.Parse(CMB_baudrate.Text)
|
|
|
|
|
};
|
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch (Exception ex) { CustomMessageBox.Show("Bad Port settings " + ex.Message); return; }
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-29 09:19:54 -04:00
|
|
|
|
tracker.PanStartRange = int.Parse(TXT_panrange.Text) / 2 * -1;
|
|
|
|
|
tracker.PanEndRange = int.Parse(TXT_panrange.Text) / 2;
|
2012-02-26 19:13:23 -04:00
|
|
|
|
tracker.TrimPan = TRK_pantrim.Value;
|
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
tracker.TiltStartRange = int.Parse(TXT_tiltrange.Text) / 2 * -1;
|
|
|
|
|
tracker.TiltEndRange = int.Parse(TXT_tiltrange.Text) / 2;
|
2012-02-26 19:13:23 -04:00
|
|
|
|
tracker.TrimTilt = TRK_tilttrim.Value;
|
|
|
|
|
|
|
|
|
|
}
|
2012-03-09 11:18:12 -04:00
|
|
|
|
catch (Exception ex) { CustomMessageBox.Show("Bad User input " + ex.Message); return; }
|
2012-02-26 19:13:23 -04:00
|
|
|
|
|
|
|
|
|
if (tracker.Init())
|
|
|
|
|
{
|
|
|
|
|
if (tracker.Setup())
|
|
|
|
|
{
|
|
|
|
|
tracker.PanAndTilt(0, 0);
|
|
|
|
|
|
|
|
|
|
t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop))
|
|
|
|
|
{
|
|
|
|
|
IsBackground = true,
|
|
|
|
|
Name = "Antenna Tracker"
|
|
|
|
|
};
|
2012-02-29 09:19:54 -04:00
|
|
|
|
t12.Start();
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mainloop()
|
|
|
|
|
{
|
|
|
|
|
threadrun = true;
|
|
|
|
|
while (threadrun)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 10 hz - position updates default to 3 hz on the stream rate
|
|
|
|
|
tracker.PanAndTilt(MainV2.cs.AZToMAV, MainV2.cs.ELToMAV);
|
|
|
|
|
System.Threading.Thread.Sleep(100);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TRK_pantrim_Scroll(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (tracker != null)
|
|
|
|
|
tracker.TrimPan = TRK_pantrim.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TRK_tilttrim_Scroll(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (tracker != null)
|
|
|
|
|
tracker.TrimTilt = TRK_tilttrim.Value;
|
|
|
|
|
}
|
2012-03-06 06:27:43 -04:00
|
|
|
|
|
|
|
|
|
private void TXT_panrange_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int range;
|
|
|
|
|
|
|
|
|
|
int.TryParse(TXT_panrange.Text, out range);
|
|
|
|
|
|
|
|
|
|
TRK_pantrim.Minimum = range / 2 * -1;
|
|
|
|
|
TRK_pantrim.Maximum = range / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TXT_tiltrange_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int range;
|
|
|
|
|
|
|
|
|
|
int.TryParse(TXT_tiltrange.Text, out range);
|
|
|
|
|
|
|
|
|
|
TRK_tilttrim.Minimum = range / 2 * -1;
|
|
|
|
|
TRK_tilttrim.Maximum = range / 2;
|
|
|
|
|
}
|
2012-02-26 19:13:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|