17600099689 1 год назад
Родитель
Сommit
4e9c090c28

+ 18 - 1
Assets/BowArrow/Scripts/ArrowSerialPort.cs

@@ -42,6 +42,7 @@ public class ArrowSerialPort : MonoBehaviour
             GameObject.Instantiate(testBoard);
         }
 #endif
+        RequestDeviceIno();//应用启动 请求一次设备信息
     }
 
     private void OnDestroy()
@@ -116,7 +117,7 @@ public class ArrowSerialPort : MonoBehaviour
     /// <summary>
     /// 设备信息响应
     /// </summary>
-    private void OnDeviceInfoBack(byte[] bytes)
+    private void OnDeviceInfoBack(byte[] bytes)// 0xAA 0x80 0x07 0x01 0x01 0x89 0x5D
     {
         Debug.Log($"{PortName} 收到设备信息响应!");
         var check = bytes[1] + bytes[2] + bytes[3] + bytes[4];//校验:命令+长度+数据内容
@@ -128,10 +129,26 @@ public class ArrowSerialPort : MonoBehaviour
         //0x02 ARTEMIS Pro
         //0x03 Pistol 1
         var deviceType = bytes[3];//设备类型
+        switch (deviceType)
+        {
+            case 0x01:
+                UserSettings.ins.selectDevicesName = "HOUYI Pro";
+                break;
+            case 0x02:
+                UserSettings.ins.selectDevicesName = "ARTEMIS Pro";
+                break;
+            case 0x03:
+                UserSettings.ins.selectDevicesName = "Pistol";
+                break;
+        }
         //0x01 移动手机
         //0x02 PC电脑
         //0x03 VR设备
         var systemType = bytes[4];//系统类型
+
+        //刷新界面
+        var setting = FindAnyObjectByType<CustomUIView.BoxUserSettings>();
+        setting?.FlushDeviceSelect();
     }
     
     /// <summary>

+ 12 - 4
Assets/SmartBow/Scripts/Views/SettingsViewParts/BoxUserSettings.cs

@@ -9,7 +9,7 @@ namespace CustomUIView
     {
         [SerializeField] Transform boxSelectDevices;
         [SerializeField] GameObject[] boxDevices;
-        readonly string[] SelectDevicesStrs = { "ARTEMIS Pro", "Pistol M9", "HOUYI Pro" };
+        readonly string[] SelectDevicesStrs = { "ARTEMIS Pro", "Pistol", "HOUYI Pro" };
         int selectDevicesIndex = 0; // 用于保存当前选择的设备索引
         // Start is called before the first frame update
         void Start()
@@ -22,16 +22,24 @@ namespace CustomUIView
                 string deviceName = SelectDevicesStrs[i]; // 捕获当前的设备名称
                 button.onClick.AddListener(() =>
                 {
-                    OnClick_SelectDevice(deviceName);
+                    //OnClick_SelectDevice(deviceName);
                 });
             }
+        }
+
+        public void OnEnable()
+        {
+            FlushDeviceSelect();
+            SerialPortHelper.ins.GetPort()?.RequestDeviceIno();//每次打开拉取一次设备信息
+        }
+
+        public void FlushDeviceSelect()
+        {
             // 获取用户设置中保存的设备名称
             string selectDeviceName = UserSettings.ins.selectDevicesName;
 
             // 如果名称存在于数组中,则获取其索引,否则默认选第一个
             selectDevicesIndex = System.Array.IndexOf(SelectDevicesStrs, selectDeviceName);
-            if (selectDevicesIndex < 0) selectDevicesIndex = 0;
-
             // 渲染选择的设备
             RenderSelectDevicesIndex(selectDevicesIndex);
         }