移动端蓝牙优化

This commit is contained in:
lishuo authored and CaiYanPeng committed 2022-06-09 14:52:50 +08:00
1 parent 72f254af2a
commit 2f64aa494f
10 files changed
+84 -16

No files matched your search

@@ -166,12 +166,12 @@ namespace Assets.Scripts.Devices.Ant
// base.reset();
//}
public override void Connect()
public override void Connect(Action<string> callback = null)
{
if (State == DeviceState.Connected || State == DeviceState.Connecting)
return;
Debug.Log("连接" + this.DeviceNumber);
AntConnector.Instance().ConnectDevice(this);
AntConnector.Instance().ConnectDevice(this, callback);
}
public override void Disconnect(bool save = true)
+13 -2
View File
@@ -294,6 +294,14 @@ namespace Assets.Scripts.Devices.Ant
void antChannel_channelResponse_FeSearch(ANT_Response response)
{
//删除扫描不到的设备
var now = DateTime.Now;
var needRemoveList = discoveredDevices.Where(c => (now - c.LastActiveTime).TotalSeconds > 5 && c.State == DeviceState.Disconnected).ToList();
foreach (var item in needRemoveList)
{
discoveredDevices.Remove(item);
}
if (IsBackgroundScanning == false)
{
searchChannel.closeChannel();
@@ -318,6 +326,7 @@ namespace Assets.Scripts.Devices.Ant
var device2 = discoveredDevices.FirstOrDefault(d => d.searchProfile.deviceNumber == deviceNumber && d.searchProfile.deviceType == deviceTypeId);
if (device2 != null)
{
device2.LastActiveTime = DateTime.Now;
//ReSearch();
_action?.Invoke(device2);
if (device2.State == DeviceState.Connected)
@@ -371,6 +380,7 @@ namespace Assets.Scripts.Devices.Ant
if (device != null)
{
//device.searchProfile.deviceNumber = (ushort)deviceNumber;
device.LastActiveTime = DateTime.Now;
device.DeviceNumber = (ushort)deviceNumber;
discoveredDevices.Add(device);
@@ -412,9 +422,10 @@ namespace Assets.Scripts.Devices.Ant
searchChannel.setChannelSearchTimeout(0);
searchChannel.openChannel(500);
}
public void ConnectDevice(AbstractAntDevice device)
Action<string> connectCallBack;
public void ConnectDevice(AbstractAntDevice device,Action<string> callBack = null)
{
this.connectCallBack = callBack;
if (usedChannels.Any(u => u.DeviceNumber == device.searchProfile.deviceNumber.ToString() &&
u.DeviceTypeId == device.searchProfile.deviceType.ToString()))
return;