接入蓝牙基本结构
This commit is contained in:
1 parent
84e8b50bbf
commit
2f84f70a5f
152 files changed
+6426
-56
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using Assets.Scripts.Ble.Commands;
|
||||
using Assets.Scripts.Ble.Service;
|
||||
using Assets.Scripts.Commands;
|
||||
using Assets.Scripts.Devices.Ble;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Ble.HeartRate
|
||||
{
|
||||
public class HeartRateService : BleService
|
||||
{
|
||||
private BleCharacteristicInfo heartRateCharacteristic;
|
||||
|
||||
public HeartRateService(BleServiceInfo serviceInfo, BleWinHwInterface bleWinHwInterface) :base(serviceInfo, bleWinHwInterface)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void CharacteristicsDiscovered(BleResponse<List<BleCharacteristicInfo>> response)
|
||||
{
|
||||
foreach (var item in response.Data)
|
||||
{
|
||||
if (item.MatchGuid(ServiceUuids.Characteristics.HrMeasurement))
|
||||
{
|
||||
this.heartRateCharacteristic = item;
|
||||
base.SubscribeCharacteristic(item, HrmCharacteristicSubscribed, HrmCharacteristicRead);
|
||||
}
|
||||
if (item.MatchGuid(ServiceUuids.Characteristics.BodySensorLocation))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HrmCharacteristicSubscribed(BleWinHwInterface winHwInterface, BleCharacteristicInfo characteristic, BleResponse response)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void HrmCharacteristicRead(BleWinHwInterface winHwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
|
||||
{
|
||||
HeartRateMeasurementValue heartRateMeasurementValue;
|
||||
if(base.CheckCharacteristicResponse<HeartRateMeasurementValue>(characteristic, response, (BleCharacteristicInfo info, BleResponse<byte[]> bleResponse) => new HeartRateMeasurementValue(bleResponse.Data), out heartRateMeasurementValue) != CommandResponseCode.Success)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Debug.Log("心率:"+heartRateMeasurementValue.BeatsPerMinute);
|
||||
}
|
||||
|
||||
protected override BleCharacteristicInfo GetCharacteristicForCommandType(CommandType type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user