Skip to content

Commit

Permalink
MainV2: use new CustomPortList for BLE
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Aug 20, 2024
1 parent badf785 commit 5112be3
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions MainV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,14 @@ public static bool sitl
/// hud background image grabber from a video stream - not realy that efficent. ie no hardware overlays etc.
/// </summary>
public static WebCamService.Capture cam { get; set; }
/// <summary>
/// used for custom autoconnect for predefined endpoints
/// </summary>
public List<AutoConnect.ConnectionInfo> ExtraConnectionList { get; } = new List<AutoConnect.ConnectionInfo>();
/// <summary>
/// used for dynamic custom port types
/// </summary>
public Dictionary<Regex, Func<string, string, ICommsSerial>> CustomPortList { get; } = new Dictionary<Regex, Func<string, string, ICommsSerial>>();

/// <summary>
/// controls the main serial reader thread
Expand Down Expand Up @@ -1499,7 +1506,15 @@ public void doConnect(MAVLinkInterface comPort, string portname, string baud, bo
return;
}

comPort.BaseStream = new SerialPort();
var customport = CustomPortList.Any(a => a.Key.IsMatch(portname));
if (customport)
{
comPort.BaseStream = CustomPortList.First(a => a.Key.IsMatch(portname)).Value(portname, baud);
}
else
{
comPort.BaseStream = new SerialPort();
}
break;
}

Expand Down Expand Up @@ -3246,7 +3261,7 @@ private async void ADSBRunner()
}


protected override void OnLoad(EventArgs e)
protected override void OnLoad(EventArgs e)
{
// check if its defined, and force to show it if not known about
if (Settings.Instance["menu_autohide"] == null)
Expand Down Expand Up @@ -3738,6 +3753,16 @@ protected override void OnLoad(EventArgs e)
}
};

try
{
// prescan
MissionPlanner.Comms.CommsBLE.SerialPort_GetCustomPorts();
}
catch { }

// add the custom port creator
CustomPortList.Add(new Regex("BLE_.*"), (s1, s2) => { return new CommsBLE() { PortName = s1, BaudRate = int.Parse(s2) }; });

this.ResumeLayout();

Program.Splash?.Close();
Expand Down

0 comments on commit 5112be3

Please sign in to comment.