lvjincheng 4 жил өмнө
parent
commit
f056733804

+ 5 - 32
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -4,7 +4,6 @@ using UnityEngine;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine.UI;
-using o0Project;
 
 public class BluetoothAim : MonoBehaviour
 {
@@ -92,7 +91,6 @@ public class BluetoothAim : MonoBehaviour
                     }
                 }
                 Invoke("OpenReceiveData", 1);
-                Invoke("SetReceiveDataInterval20", 2);
             };
             bluetoothHelper.OnConnectionFailed += (BluetoothHelper helper) =>
             {
@@ -102,7 +100,7 @@ public class BluetoothAim : MonoBehaviour
             bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
             {
                 byte[] bytes = value;
-                aimHandler.onDataReceived(bytes);
+                aimHandler.OnDataReceived(bytes);
             };
             bluetoothHelper.OnScanEnded += (BluetoothHelper helper, LinkedList<BluetoothDevice> nearbyDevices) =>
             {
@@ -138,13 +136,7 @@ public class BluetoothAim : MonoBehaviour
         BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristicWrite.getName());
         ch.setService(bluetoothService.getName());
         bluetoothHelper.WriteCharacteristic(ch, "3");
-        Log("开始接收信息\n" + deviceName);
-    }
-
-    void SetReceiveDataInterval20()
-    {
-        bluetoothHelper.WriteCharacteristic(characteristicWrite, "b");
-        Log("修改接收频率\n" + deviceName);
+        Log("瞄准模块准备完成\n" + deviceName);
     }
 
     void Log(string text)
@@ -166,6 +158,7 @@ class AimHandler
     Vector3 Acc = default;
     Vector3 Gyr = default;
     Vector3 Mag = default;
+    long TimeGap = default;
 
     static Vector3 AccIdentity = new Vector3(0, -1, 0);
     static Vector3 MagIdentity = new Vector3(-1, 2, 0).normalized;
@@ -286,7 +279,7 @@ class AimHandler
         });
     }
 
-    public void onDataReceived(byte[] bytes)
+    public void OnDataReceived(byte[] bytes)
     {
         if (bytes.Length != 26)
         {
@@ -335,7 +328,7 @@ class AimHandler
             msOld = ms;
             return;
         }
-        var TimeGap = ms - msOld;
+        TimeGap = ms - msOld;
         msOld = ms;
 
         newRotation = o06DOFUpdate(Acc * 10, Gyr, Mag, TimeGap);
@@ -360,15 +353,6 @@ class AimHandler
         if (hasAutoIdentity)
         {
             controlObj.transform.localRotation = Quaternion.Lerp(controlObj.transform.localRotation, newRotation, Time.deltaTime * 6);
-            // newEularAngles.x = baseEularAngles.x + newRotation.eulerAngles.x;
-            // newEularAngles.y = baseEularAngles.y + newRotation.eulerAngles.y;
-            // newEularAngles.z = baseEularAngles.z + newRotation.eulerAngles.z;
-            // controlObj.transform.localRotation = Quaternion.Lerp(
-            //     controlObj.transform.localRotation, 
-            //     Quaternion.Euler(newEularAngles.x, newEularAngles.y, newEularAngles.z), 
-            //     Time.deltaTime * 8
-            // );
-            // controlObj.localEulerAngles = Vector3.Lerp(controlObj.localEulerAngles, newEularAngles, Time.deltaTime * 6);
         }
         if (doIdentity)
         {
@@ -384,15 +368,6 @@ class AimHandler
                 AccIdentity = AccOld;
                 MagIdentity = MagOld;
             }
-            // baseEularAngles.x = 0 - newRotation.eulerAngles.x;
-            // baseEularAngles.y = 0 - newRotation.eulerAngles.y;
-            // baseEularAngles.z = 0 - newRotation.eulerAngles.z;
-            // newEularAngles.x = baseEularAngles.x + newRotation.eulerAngles.x;
-            // newEularAngles.y = baseEularAngles.y + newRotation.eulerAngles.y;
-            // newEularAngles.z = baseEularAngles.z + newRotation.eulerAngles.z;
-            // controlObj.localEulerAngles = newEularAngles;
-            // doIdentity = false;
-            // hasAutoIdentity = true;
         }
     }
 
@@ -401,6 +376,4 @@ class AimHandler
     bool hasAutoIdentity = false;
     Quaternion newRotation;
     Quaternion baseRotation = new Quaternion(0, 0, 0, 1);
-    Vector3 baseEularAngles = new Vector3();
-    Vector3 newEularAngles = new Vector3();
 }

+ 0 - 13
Assets/BowArrow/Scripts/Bluetooth/BluetoothShoot.cs

@@ -74,8 +74,6 @@ public class BluetoothShoot : MonoBehaviour
                     }
                 }
                 Invoke("OpenReceiveData", 1);
-                Invoke("SetReceiveDataInterval20", 2);
-                Invoke("ShowFinish", 3);
             };
             bluetoothHelper.OnConnectionFailed += (BluetoothHelper helper) =>
             {
@@ -124,17 +122,6 @@ public class BluetoothShoot : MonoBehaviour
         BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristicWrite.getName());
         ch.setService(bluetoothService.getName());
         bluetoothHelper.WriteCharacteristic(ch, "5");
-        Log("开始接收信息\n" + deviceName);
-    }
-
-    void SetReceiveDataInterval20()
-    {
-        bluetoothHelper.WriteCharacteristic(characteristicWrite, "b");
-        Log("修改接收频率\n" + deviceName);
-    }
-
-    void ShowFinish()
-    {
         Log("射击模块准备完成\n" + deviceName);
     }
 

+ 0 - 1
Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

@@ -18,7 +18,6 @@ public class ShootCheck : MonoBehaviour
     void Start()
     {
         ins = this;
-        // BluetoothClient.onDataReceived = OnDataReceived;
     } 
 
     void OnDestroy()

+ 1 - 1
Assets/DebugShoot/BluetoothClient.cs

@@ -15,7 +15,7 @@ public class BluetoothClient : MonoBehaviour
 {
     WebSocket ws;
     bool loaded = false;
-    [SerializeField] string serverIP = "192.168.101.14";
+    [SerializeField] string serverIP = "110.43.54.43";
     [SerializeField] Text text;
     public static System.Action<byte[]> onDataReceived;
     static BluetoothClient ins;

+ 4 - 11
Assets/DebugShoot/BluetoothNew.cs

@@ -12,8 +12,8 @@ public class BluetoothNew : MonoBehaviour
     string deviceName = "";
     bool canConnect = true;
 
-    string targetDeviceName = "BGBox_202012";
-    // string targetDeviceName = "Bbow_20210501";
+    // string targetDeviceName = "BGBox_202012";
+    string targetDeviceName = "Bbow_20210501";
 
     [SerializeField] Text textUI;
 
@@ -69,7 +69,6 @@ public class BluetoothNew : MonoBehaviour
                     }
                 }
                 Invoke("OpenReceiveData", 1);
-                Invoke("SetReceiveDataInterval20", 2);
             };
             bluetoothHelper.OnConnectionFailed += (BluetoothHelper helper) =>
             {
@@ -113,17 +112,11 @@ public class BluetoothNew : MonoBehaviour
     {
         BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristicWrite.getName());
         ch.setService(bluetoothService.getName());
-        // bluetoothHelper.WriteCharacteristic(ch, "3");
-        bluetoothHelper.WriteCharacteristic(ch, "5");
+        bluetoothHelper.WriteCharacteristic(ch, "3");
+        // bluetoothHelper.WriteCharacteristic(ch, "5");
         Log("开始接收信息\n" + deviceName);
     }
 
-    void SetReceiveDataInterval20()
-    {
-        bluetoothHelper.WriteCharacteristic(characteristicWrite, "b");
-        Log("修改接收频率\n" + deviceName);
-    }
-
     void Log(string text)
     {
         if (textUI != null)