lvjincheng 3 роки тому
батько
коміт
44e54494b9
1 змінених файлів з 16 додано та 4 видалено
  1. 16 4
      Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

+ 16 - 4
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -8,10 +8,22 @@ using UnityEngine.SceneManagement;
 /* 蓝牙瞄准模块 */
 public class BluetoothAim : MonoBehaviour
 {
+    readonly string targetDeviceName = "Bbow_20210501";
+
+    //旧设备-服务和特征
+    //readonly string targetDeviceService = "0000fff0"; //字母用小写
+    //readonly string targetDeviceCharacteristicWrite = "0000fff2"; //字母用小写
+    //readonly string targetDeviceCharacteristicNotify = "0000fff1"; //字母用小写
+
+    //新设备-服务和特征
+    readonly string targetDeviceService = "6e400001"; //字母用小写
+    readonly string targetDeviceCharacteristicWrite = "6e400002"; //字母用小写
+    readonly string targetDeviceCharacteristicNotify = "6e400003"; //字母用小写
+
+
     BluetoothHelper bluetoothHelper;
     BluetoothHelperCharacteristic characteristicWrite;
     BluetoothHelperService bluetoothService;
-    string targetDeviceName = "Bbow_20210501";
     string deviceName = "";
     bool canConnect = true;
     [SerializeField] Text textUI;
@@ -137,17 +149,17 @@ public class BluetoothAim : MonoBehaviour
                 foreach (BluetoothHelperService service in helper.getGattServices())
                 {
 
-                    if (service.getName().ToLower().StartsWith("0000fff0"))
+                    if (service.getName().ToLower().StartsWith(targetDeviceService))
                     {
                         bluetoothService = service;
 
                         foreach (BluetoothHelperCharacteristic characteristic in service.getCharacteristics())
                         {
-                            if (characteristic.getName().ToLower().StartsWith("0000fff2"))
+                            if (characteristic.getName().ToLower().StartsWith(targetDeviceCharacteristicWrite))
                             {
                                 characteristicWrite = characteristic;
                             }
-                            else if (characteristic.getName().ToLower().StartsWith("0000fff1"))
+                            else if (characteristic.getName().ToLower().StartsWith(targetDeviceCharacteristicNotify))
                             {
 
                                 BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristic.getName());