蓝牙抽象成接口
This commit is contained in:
1 parent
f14a071179
commit
81a18de9f4
20 files changed
+658
-44
No files matched your search
@@ -2,6 +2,7 @@
|
||||
using Assets.Scripts.Ble.Win;
|
||||
using Assets.Scripts.Devices.Ant;
|
||||
using Assets.Scripts.Devices.Ble;
|
||||
using Assets.Scripts.Devices.Ble.Interfaces;
|
||||
using Assets.Scripts.Devices.Ble.Win;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,13 +13,24 @@ using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Ble
|
||||
{
|
||||
public sealed class BleWinHwInterface
|
||||
public sealed class BleWinHwInterface: IBleWinHwInterface
|
||||
{
|
||||
private static BleWinHwInterface hwInterface;
|
||||
private WclBleMainThread wclBleMainThread;
|
||||
|
||||
public readonly Dictionary<string, BleAdvertisementInfo> pCache = new Dictionary<string, BleAdvertisementInfo>();
|
||||
|
||||
private Dictionary<string, BleAdvertisementInfo> _pCache;
|
||||
public Dictionary<string, BleAdvertisementInfo> pCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_pCache == null)
|
||||
{
|
||||
_pCache = new Dictionary<string, BleAdvertisementInfo>();
|
||||
}
|
||||
return _pCache;
|
||||
}
|
||||
set { _pCache = value; }
|
||||
}
|
||||
private Action<BleAdvertisementInfo> _discoveredCallback;
|
||||
|
||||
private Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse>> callbacks = new Dictionary<BlePeripheralInfo, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse>>();
|
||||
@@ -43,6 +55,7 @@ namespace Assets.Scripts.Ble
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private BluetoothStateChangedCallback bluetoothStateChanged;
|
||||
public event BluetoothStateChangedCallback BluetoothStateChangedEvent
|
||||
{
|
||||
@@ -55,7 +68,7 @@ namespace Assets.Scripts.Ble
|
||||
this.bluetoothStateChanged -= value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private BleState nativeState;
|
||||
public BleState BleState
|
||||
{
|
||||
@@ -63,7 +76,7 @@ namespace Assets.Scripts.Ble
|
||||
{
|
||||
return this.nativeState;
|
||||
}
|
||||
private set
|
||||
set
|
||||
{
|
||||
if(this.nativeState != value)
|
||||
{
|
||||
@@ -201,7 +214,7 @@ namespace Assets.Scripts.Ble
|
||||
return wclBleGattThread;
|
||||
}
|
||||
|
||||
internal void ConnectPeripheral(BlePeripheralInfo info, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse> callback)
|
||||
public void ConnectPeripheral(BlePeripheralInfo info, Action<IBleWinHwInterface, BlePeripheralInfo, BleResponse> callback)
|
||||
{
|
||||
this.callbacks.Add(info, callback);
|
||||
WclBleGattThread wclBleGattThread = this.wclBleMainThread.GetGattThread(info);
|
||||
@@ -229,8 +242,8 @@ namespace Assets.Scripts.Ble
|
||||
|
||||
//});
|
||||
}
|
||||
|
||||
internal void DisconnectPeripheral(BlePeripheralInfo peripheral, Action callback)
|
||||
|
||||
public void DisconnectPeripheral(BlePeripheralInfo peripheral, Action callback)
|
||||
{
|
||||
var gattThread = this.wclBleMainThread.GetGattThread(peripheral);
|
||||
if(gattThread != null && gattThread.CanLoadWork)
|
||||
@@ -372,7 +385,7 @@ namespace Assets.Scripts.Ble
|
||||
}
|
||||
}
|
||||
|
||||
public void DiscoverServices(BlePeripheralInfo peripheral, Action<BleWinHwInterface, BlePeripheralInfo, BleResponse<List<BleServiceInfo>>> callback)
|
||||
public void DiscoverServices(BlePeripheralInfo peripheral, Action<IBleWinHwInterface, BlePeripheralInfo, BleResponse<List<BleServiceInfo>>> callback)
|
||||
{
|
||||
WclBleGattThread gattThread = this.wclBleMainThread.GetGattThread(peripheral);
|
||||
if(gattThread == null)
|
||||
@@ -420,7 +433,7 @@ namespace Assets.Scripts.Ble
|
||||
this.GattCharacteristicsDiscovered(gattThread, service, response);
|
||||
}
|
||||
|
||||
public void SubscribeCharacteristic(BleCharacteristicInfo characteristic, Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse> callback)
|
||||
public void SubscribeCharacteristic(BleCharacteristicInfo characteristic, Action<IBleWinHwInterface, BleCharacteristicInfo, BleResponse> callback)
|
||||
{
|
||||
WclBleGattThread gattThread = this.wclBleMainThread.GetGattThread(characteristic.Peripheral);
|
||||
|
||||
|
||||
Reference in new issue
Block a user