Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigDroneCAN: Add disconnect button #3420

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions GCSViews/ConfigurationView/ConfigDroneCAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ private void SetupSLCanPort(ICommsSerial port)
private TcpListener listener;
private bool mavlinkCANRun;
private byte BusInUse;
private bool isConnected = false;

private void myDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
Expand Down Expand Up @@ -649,6 +650,12 @@ private void GetParameters(byte nodeID)
}

public void Deactivate()
{
Disconnect();
timer?.Stop();
}

public void Disconnect()
{
mavlinkCANRun = false;
try
Expand All @@ -663,7 +670,11 @@ public void Deactivate()
listener = null;
can?.Stop(chk_canonclose.Checked);
can = null;
timer?.Stop();

cmb_interfacetype.Enabled = true;
cmb_networkinterface.Enabled = true;
but_connect.Text = "Connect";
isConnected = false;
}

private void myDataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
Expand Down Expand Up @@ -1593,6 +1604,12 @@ private void StartmcastCAN(byte bus = 0, NetworkInterface inter = null)

private void but_connect_Click(object sender, EventArgs e)
{
if (isConnected)
{
Disconnect();
return;
}

mavlinkCANRun = false;

var selected = cmb_interfacetype.SelectedValue;
Expand All @@ -1603,7 +1620,13 @@ private void but_connect_Click(object sender, EventArgs e)
return;
}

but_connect.Enabled = false;
// Reset the table of nodes
myDataGridView1.Rows.Clear();

cmb_interfacetype.Enabled = false;
cmb_networkinterface.Enabled = false;
but_connect.Text = "Disconnect";
isConnected = true;

var type = (ConnectionTypes)selected;

Expand Down
Loading