蓝牙抽象成接口

This commit is contained in:
lishuo committed 2021-08-19 18:03:25 +08:00
1 parent f14a071179
commit 81a18de9f4
20 files changed
+658 -44

No files matched your search

@@ -8,6 +8,7 @@ using Assets.Scripts.Ble.Commands;
using Assets.Scripts.Commands;
using Assets.Scripts.Devices.Ble;
using Assets.Scripts.Devices.Ble.Extension;
using Assets.Scripts.Devices.Ble.Interfaces;
using UnityEngine;
namespace Assets.Scripts.Ble.Service
@@ -18,7 +19,7 @@ namespace Assets.Scripts.Ble.Service
private BleServiceInfo serviceInfo;
private List<BleCharacteristicInfo> characteristics;
private readonly Dictionary<Guid, Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse<byte[]>>> registeredCharacteristicReadEvents = new Dictionary<Guid, Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse<byte[]>>>();
private readonly Dictionary<Guid, Action<IBleWinHwInterface, BleCharacteristicInfo, BleResponse<byte[]>>> registeredCharacteristicReadEvents = new Dictionary<Guid, Action<IBleWinHwInterface, BleCharacteristicInfo, BleResponse<byte[]>>>();
public IReadOnlyList<BleCharacteristicInfo> Characteristics
{
@@ -58,7 +59,7 @@ namespace Assets.Scripts.Ble.Service
this.hwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
}
private void CharacteristicReadMainCallback(BleWinHwInterface hwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
private void CharacteristicReadMainCallback(IBleWinHwInterface hwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
{
//Debug.Log("read main callback");
if (this.registeredCharacteristicReadEvents.ContainsKey(characteristic.Id) && characteristic.Service.Equals(this.serviceInfo))
@@ -79,7 +80,7 @@ namespace Assets.Scripts.Ble.Service
this.CheckCharacteristicDiscoveredResponse(this.hwInterface, this.serviceInfo, scanCharacteristicsResponse);
}
private void CheckCharacteristicDiscoveredResponse(BleWinHwInterface hwInterface, BleServiceInfo service, BleResponse<List<BleCharacteristicInfo>> response)
private void CheckCharacteristicDiscoveredResponse(IBleWinHwInterface hwInterface, BleServiceInfo service, BleResponse<List<BleCharacteristicInfo>> response)
{
if (!service.Equals(this.serviceInfo))
{
@@ -98,8 +99,8 @@ namespace Assets.Scripts.Ble.Service
protected abstract void CharacteristicsDiscovered(BleResponse<List<BleCharacteristicInfo>> response);
protected void SubscribeCharacteristic(BleCharacteristicInfo characteristic, Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse> notificationCallback,
Action<BleWinHwInterface, BleCharacteristicInfo, BleResponse<byte[]>> readCallback)
protected void SubscribeCharacteristic(BleCharacteristicInfo characteristic, Action<IBleWinHwInterface, BleCharacteristicInfo, BleResponse> notificationCallback,
Action<IBleWinHwInterface, BleCharacteristicInfo, BleResponse<byte[]>> readCallback)
{
this.hwInterface.SubscribeCharacteristic(characteristic, (hw, info, response) =>
{