蓝牙停止扫描和一些bug修复

This commit is contained in:
lishuo committed 2021-08-26 19:33:43 +08:00
1 parent 0139cbc173
commit d8927ceca5
16 files changed
+137 -71

No files matched your search

+15 -11
View File
@@ -23,8 +23,9 @@ public class BluetoothDeviceScript : MonoBehaviour
public Action<string, string> RetrievedConnectedPeripheralAction;
public Action<string, byte[]> PeripheralReceivedWriteDataAction;
public Action<string> ConnectedPeripheralAction;
public Action<string> ConnectedDisconnectPeripheralAction;
public Action<string> ConnectedDisconnectPeripheralAction { get; set; }
public Action<string> DisconnectedPeripheralAction;
public Action<string> DeviceBleStatusDisconnectedAction;
public Action<string, string> DiscoveredServiceAction;
public Action<string, string, string> DiscoveredCharacteristicAction;
public Action<string> DidWriteCharacteristicAction;
@@ -80,11 +81,14 @@ public class BluetoothDeviceScript : MonoBehaviour
{
char[] delim = new char[] { '~' };
string[] parts = message.Split (delim);
if (parts[0].Equals("DeviceStateChanged"))
{
//throw new Exception("test");
}
if (parts[0].Equals(bleStatusChanged))
if (parts[0].Equals("DeviceStateChanged"))
{
if (DeviceBleStatusDisconnectedAction != null && parts[1].Equals("0"))
{
DeviceBleStatusDisconnectedAction(parts[2]);
}
}
if (parts[0].Equals(bleStatusChanged))
{
if (BleStatusChangedAction != null)
{
@@ -231,12 +235,12 @@ public class BluetoothDeviceScript : MonoBehaviour
{
if (parts.Length >= 2)
{
if (ConnectedDisconnectPeripheralAction != null)
ConnectedDisconnectPeripheralAction (parts[1]);
if (ConnectedDisconnectPeripheralAction != null)
ConnectedDisconnectPeripheralAction(parts[1]);
if (DisconnectedPeripheralAction != null)
DisconnectedPeripheralAction (parts[1]);
}
if (DisconnectedPeripheralAction != null)
DisconnectedPeripheralAction(parts[1]);
}
}
else if (message.Length >= deviceDiscoveredService.Length && message.Substring (0, deviceDiscoveredService.Length) == deviceDiscoveredService)
{