修复设备选择界面多设备选择bug
This commit is contained in:
1 parent
7729332f41
commit
5671b35dce
21 files changed
+111
-56
No files matched your search
@@ -23,10 +23,15 @@ namespace Assets.Scripts.Devices.Ble
|
||||
private readonly HashSet<BleServiceInfo> pendingServices = new HashSet<BleServiceInfo>();
|
||||
|
||||
public override string Name { get => peripheralInfo.Name; protected set => base.Name = value; }
|
||||
|
||||
public string Address {
|
||||
get
|
||||
{
|
||||
return peripheralInfo.Address;
|
||||
}
|
||||
}
|
||||
public List<ICharacteristic> Characteristics { get; protected set; } = new List<ICharacteristic>();
|
||||
|
||||
public BleDevice(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface, SensorType sensor) : base(NetworkType.BLE)
|
||||
public BleDevice(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface, SensorType sensor) : base(peripheralInfo.Address, NetworkType.BLE)
|
||||
{
|
||||
this.hwInterface = bleWinHwInterface;
|
||||
this.hwInterface.BluetoothStateChangedEvent += BluetoothStateChangedEvent;
|
||||
@@ -45,7 +50,23 @@ namespace Assets.Scripts.Devices.Ble
|
||||
|
||||
public void ConnectToPeripheralIfPossible()
|
||||
{
|
||||
this.hwInterface.ConnectPeripheral(this.peripheralInfo, PeripheralConnectedAction);
|
||||
if(this.peripheralInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!this.hwInterface.BleState.Equals(BleState.On) || this.State != DeviceState.Disconnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.State = DeviceState.Connecting;
|
||||
try
|
||||
{
|
||||
this.hwInterface.ConnectPeripheral(this.peripheralInfo, PeripheralConnectedAction);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.State = DeviceState.Disconnected;
|
||||
}
|
||||
}
|
||||
|
||||
private void PeripheralConnectedAction(BleWinHwInterface hwInterface, BlePeripheralInfo sender, BleResponse response)
|
||||
@@ -201,6 +222,7 @@ namespace Assets.Scripts.Devices.Ble
|
||||
{
|
||||
if (this.State != DeviceState.Disconnected)
|
||||
{
|
||||
Debug.Log("断开设备" + this.Name);
|
||||
this.hwInterface.DisconnectPeripheral(this.peripheralInfo, ()=> {
|
||||
this.State = DeviceState.Disconnected;
|
||||
});
|
||||
@@ -238,7 +260,8 @@ namespace Assets.Scripts.Devices.Ble
|
||||
public override void Disconnect(bool save = true)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
this.hwInterface.DisconnectPeripheral(this.peripheralInfo, null);
|
||||
//this.hwInterface.DisconnectPeripheral(this.peripheralInfo, null);
|
||||
this.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
return;
|
||||
this.Cadence = 0;
|
||||
}
|
||||
Debug.Log("踏频值:" + this.Cadence);
|
||||
}
|
||||
|
||||
private void HandleSpeedUpdate()
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
private CyclingPowerMeasurement cyclingPowerMeasurement;
|
||||
public CyclingPower(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Power)
|
||||
{
|
||||
|
||||
Priority = 2;
|
||||
cyclingPowerMeasurement = new CyclingPowerMeasurement(1920);
|
||||
base.Characteristics.Add(cyclingPowerMeasurement);
|
||||
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
private HeartRateMeasurement heartRateMeasurement;
|
||||
public HeartRate(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.HeartRate)
|
||||
{
|
||||
Priority = 2;
|
||||
heartRateMeasurement = new HeartRateMeasurement();
|
||||
|
||||
base.Characteristics.Add(heartRateMeasurement);
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
public SpeedCadence(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.SpeedCadence)
|
||||
{
|
||||
Debug.Log("创建速度踏频设备");
|
||||
Priority = 1;
|
||||
_cyclingSpeedCadenceMeasurement = new CyclingSpeedCadenceMeasurement(this._wheelCircumference);
|
||||
base.Characteristics.Add(_cyclingSpeedCadenceMeasurement);
|
||||
|
||||
|
||||
@@ -266,9 +266,19 @@ namespace Assets.Scripts.Ble
|
||||
private void GattConnected(WclBleGattThread gattClient, BleResponse response)
|
||||
{
|
||||
Debug.Log($"gatt connected { response.ToString() }");
|
||||
if (!response.IsSuccess)
|
||||
{
|
||||
gattClient.Stop();
|
||||
return;
|
||||
}
|
||||
this.callbacks[gattClient.Peripheral].Invoke(this, gattClient.Peripheral, response);
|
||||
}
|
||||
|
||||
private void CleanUpPeripheral(BlePeripheralInfo peripheralInfo)
|
||||
{
|
||||
//this.callbacks.Clear()
|
||||
}
|
||||
|
||||
private void GattDisconnected(WclBleGattThread gattClient, BleResponse response)
|
||||
{
|
||||
Debug.Log("gatt disconnected");
|
||||
@@ -326,7 +336,7 @@ namespace Assets.Scripts.Ble
|
||||
}
|
||||
private void GattCharacteristicChanged(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
|
||||
{
|
||||
Debug.Log("characteristic changed");
|
||||
//Debug.Log("characteristic changed");
|
||||
if(this.wclBleMainThread.GetGattThread(characteristic.Peripheral) != null)
|
||||
{
|
||||
this.characteristicReadEvent.Invoke(this, characteristic, response);
|
||||
@@ -418,7 +428,7 @@ namespace Assets.Scripts.Ble
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.wclBleMainThread.Dispose();
|
||||
this.wclBleMainThread.Stop();
|
||||
this.wclBleMainThread = null;
|
||||
hwInterface = null;
|
||||
pCache.Clear();
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace Assets.Scripts.Devices.Ble.Win
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Stop()
|
||||
{
|
||||
Debug.Log("停止thread");
|
||||
foreach (var item in this.gattClients.Values)
|
||||
|
||||
Reference in new issue
Block a user