ソースを参照

1.添加区分名字匹配和mac匹配

slambb 10 ヶ月 前
コミット
773c3ebf29
3 ファイル変更78 行追加29 行削除
  1. 18 18
      SmartBowSDK.csproj
  2. 33 8
      SmartBowSDK/BluetoothAim_SDK.cs
  3. 27 3
      SmartBowSDK/SmartBowHelper.cs

+ 18 - 18
SmartBowSDK.csproj

@@ -27,58 +27,58 @@
 			<HintPath>D:\DeveloperSoftware\2021.3.22f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.UnityWebRequestTextureModule.dll</HintPath>
 		</Reference>
 		<Reference Include="Fractions">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/Fractions.dll</HintPath>
+			<HintPath>D:\Unity\SmartBowSDK/Assets/SmartBowSDK/o0Lib/Fractions.dll</HintPath>
 		</Reference>
 		<Reference Include="BouncyCastle.Crypto">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/BouncyCastle.Crypto.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/BouncyCastle.Crypto.dll</HintPath>
 		</Reference>
 		<Reference Include="MathNet.Numerics">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/MathNet.Numerics.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/MathNet.Numerics.dll</HintPath>
 		</Reference>
 		<Reference Include="System.Memory">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/System.Memory.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/System.Memory.dll</HintPath>
 		</Reference>
 		<Reference Include="o0MagnetometerCalibrater">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/o0MagnetometerCalibrater.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/o0MagnetometerCalibrater.dll</HintPath>
 		</Reference>
 		<Reference Include="System.Text.Encoding.CodePages">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/System.Text.Encoding.CodePages.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/System.Text.Encoding.CodePages.dll</HintPath>
 		</Reference>
 		<Reference Include="o0NetLib">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/o0NetLib.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/o0NetLib.dll</HintPath>
 		</Reference>
 		<Reference Include="SixLabors.ImageSharp">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/SixLabors.ImageSharp.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/SixLabors.ImageSharp.dll</HintPath>
 		</Reference>
 		<Reference Include="System.Buffers">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/System.Buffers.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/System.Buffers.dll</HintPath>
 		</Reference>
 		<Reference Include="System.Reflection.Emit.Lightweight">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/System.Reflection.Emit.Lightweight.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/System.Reflection.Emit.Lightweight.dll</HintPath>
 		</Reference>
 		<Reference Include="System.Runtime.CompilerServices.Unsafe">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/System.Runtime.CompilerServices.Unsafe.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/System.Runtime.CompilerServices.Unsafe.dll</HintPath>
 		</Reference>
 		<Reference Include="System.Reflection.Emit.ILGeneration">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/System.Reflection.Emit.ILGeneration.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/System.Reflection.Emit.ILGeneration.dll</HintPath>
 		</Reference>
 		<Reference Include="o0NetIMU">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/o0NetIMU.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/o0NetIMU.dll</HintPath>
 		</Reference>
 		<Reference Include="zlib.net">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/zlib.net.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/zlib.net.dll</HintPath>
 		</Reference>
 		<Reference Include="System.Numerics.Vectors">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/System.Numerics.Vectors.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/System.Numerics.Vectors.dll</HintPath>
 		</Reference>
 		<Reference Include="Mono.Data.Sqlite">
-			<HintPath>../Assets/SmartBowSDK/o0Lib/Mono.Data.Sqlite.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/SmartBowSDK/o0Lib/Mono.Data.Sqlite.dll</HintPath>
 		</Reference>
 		<Reference Include="ArduinoBluetoothAPI">
-			<HintPath>../Assets/Plugins/ArduinoBluetoothAPI.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/Plugins/ArduinoBluetoothAPI.dll</HintPath>
 		</Reference>
 		<Reference Include="Newtonsoft.Json">
-			<HintPath>../Assets/Packages/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll</HintPath>
+			<HintPath>D:/Unity/SmartBowSDK/Assets/Packages/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll</HintPath>
 		</Reference>
 	</ItemGroup>
 </Project>

+ 33 - 8
SmartBowSDK/BluetoothAim_SDK.cs

@@ -33,6 +33,16 @@ namespace SmartBowSDK
         /// </summary>
         public string filters { get; set; } = "";
 
+        /// <summary>
+        /// 是否使用mac过滤
+        /// </summary>
+        public bool isConnectName { get; set; } = true;//默认用名字连接
+
+        /// <summary>
+        /// 传入的mac
+        /// </summary>
+        public string connectMacStr { get; set; } = "";
+
 
         /// <summary>
         /// 当前的传感器类型
@@ -350,15 +360,30 @@ namespace SmartBowSDK
             foreach (BluetoothDevice device in nearbyDevices)
             {
                 SmartBowLogger.Log(this, $"发现设备{device.DeviceName},is fileters empty:{ string.IsNullOrEmpty(filters)},name:{filters}");
-                //if (device.DeviceName == deviceConfig.deviceName)
-                //后续匹配名字 可以是多个设备
-                string _filters = string.IsNullOrEmpty(filters) ? deviceConfig.deviceName : filters;
-                if (_filters.Contains(device.DeviceName))
+                if (isConnectName)
                 {
-                    _bluetoothHelper.setDeviceName(device.DeviceName);
-                    _bluetoothHelper.Connect();
-                    SmartBowLogger.Log(this, $"匹配设备{device.DeviceName}");
-                    return;
+                    //if (device.DeviceName == deviceConfig.deviceName)
+                    //后续匹配名字 可以是多个设备
+                    string _filters = string.IsNullOrEmpty(filters) ? deviceConfig.deviceName : filters;
+                    if (_filters.Contains(device.DeviceName))
+                    {
+                        _bluetoothHelper.setDeviceName(device.DeviceName);
+                        _bluetoothHelper.Connect();
+                        SmartBowLogger.Log(this, $"Name匹配设备{device.DeviceName}");
+                        return;
+                    }
+                }
+                else
+                {
+                    //按mac地址匹配
+                    if (device.DeviceAddress == connectMacStr)
+                    {
+                        _bluetoothHelper.setDeviceName(device.DeviceName);
+                        _bluetoothHelper.setDeviceAddress(connectMacStr);
+                        _bluetoothHelper.Connect();
+                        SmartBowLogger.Log(this, $"Mac匹配设备{device.DeviceAddress}");
+                        return;
+                    }
                 }
             }
             SetStatus(BluetoothStatusEnum.None);

+ 27 - 3
SmartBowSDK/SmartBowHelper.cs

@@ -104,12 +104,36 @@ namespace SmartBowSDK
         /// <summary>
         /// 设置蓝牙过滤名称
         /// </summary>
-        /// <param name="name"></param>
-        public void SetFilters(string name) { 
-           if (!string.IsNullOrWhiteSpace(name))
+        /// <param name="name">不传参数时候,设置值 ""</param>
+        public void SetFilters(string name = "") {
+            if (!string.IsNullOrWhiteSpace(name))
             {
                 bluetoothAim.filters = name;
             }
+            else {
+                bluetoothAim.filters = "";
+            }
+        }
+
+        /// <summary>
+        /// 设置是否使用名称连接
+        /// </summary>
+        /// <param name="useName">是否使用名称连接</param>
+        public void SetIsConnectName(bool useName)
+        {
+            bluetoothAim.isConnectName = useName;
+        }
+
+        /// <summary>
+        /// 设置连接的MAC地址
+        /// </summary>
+        /// <param name="macStr">MAC地址字符串</param>
+        public void SetConnectMacStr(string macStr)
+        {
+            if (!string.IsNullOrWhiteSpace(macStr))
+            {
+                bluetoothAim.connectMacStr = macStr;
+            }
         }
 
         /// <summary>