蓝牙断开重连相关逻辑优化
This commit is contained in:
1 parent
87a0e7fb6d
commit
f25d0b7b8c
11 files changed
+455
-27
No files matched your search
@@ -27,7 +27,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
_isEnabled = value;
|
||||
if (EnableChanged != null)
|
||||
{
|
||||
EnableChanged(_isEnabled, new EventArgs());
|
||||
EnableChanged(_isEnabled, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
_pullValue = value;
|
||||
if (this.PullChanged != null)
|
||||
{
|
||||
this.PullChanged(this, new EventArgs());
|
||||
this.PullChanged(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,15 +68,15 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
else if (data[0] == 0x3d)
|
||||
{
|
||||
//老款表头不支持
|
||||
List<ushort> r = new List<ushort>();
|
||||
//List<ushort> r = new List<ushort>();
|
||||
for (int i = 3; i < data.Length; i += 2)
|
||||
{
|
||||
ushort pull = data[i] < 5 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i], true)));
|
||||
r.Add(pull);
|
||||
//r.Add(pull);
|
||||
PullValue = pull;
|
||||
}
|
||||
|
||||
Debug.Log("拉力曲线:" + string.Join(",", r));
|
||||
// Debug.Log("拉力曲线:" + string.Join(",", r));
|
||||
}
|
||||
else if (data[0] == 0x31)
|
||||
{
|
||||
@@ -102,11 +102,12 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
var time = ((data[3] << 16) + (data[2] << 8) + data[1]) / 100;
|
||||
Debug.Log("划船时间" + time);
|
||||
isReadyStatus = data[9] == 0;
|
||||
if (RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(data[19], new EventArgs());
|
||||
}
|
||||
var hasChanged = data[19] != ResistanceLevel;
|
||||
ResistanceLevel = data[19];
|
||||
if (RowerResChanged != null && hasChanged)
|
||||
{
|
||||
RowerResChanged.Invoke(this, null);
|
||||
}
|
||||
//isReadyStatus = data[2] == 1 || data[2] == 129;
|
||||
}
|
||||
else if (data[0] == 0x32)
|
||||
@@ -163,7 +164,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
{
|
||||
if (_totalDistance == 0 && value != 0 && StartEvent != null)
|
||||
{
|
||||
StartEvent.Invoke(null, new EventArgs());
|
||||
StartEvent.Invoke(this, null);
|
||||
}
|
||||
_totalDistance = value;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
{
|
||||
if (_instantaneousPace == 0 && value != 0 && StartEvent != null)
|
||||
{
|
||||
StartEvent.Invoke(null, new EventArgs());
|
||||
StartEvent.Invoke(this, null);
|
||||
}
|
||||
_instantaneousPace = value;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
_pullValue = value;
|
||||
if (this.PullChanged != null)
|
||||
{
|
||||
this.PullChanged(this, new EventArgs());
|
||||
this.PullChanged(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
|
||||
if (resChanged && device != null && deviceNamePool.FirstOrDefault(x => device.Name.ToLower().Contains(x.ToLower())) == null && RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(this.commonRes, null);
|
||||
RowerResChanged.Invoke(this, null);
|
||||
}
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.ResistanceLevel);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
|
||||
if (thinkResChanged && device != null && deviceNamePool.FirstOrDefault(x=>device.Name.ToLower().Contains(x.ToLower()))!=null && RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(this.thinkRes, null);
|
||||
RowerResChanged.Invoke(this, null);
|
||||
}
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.ThinkDragFactor);
|
||||
}
|
||||
@@ -254,6 +254,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
tempPullList.Add(val);
|
||||
PullValue = val;
|
||||
}
|
||||
Debug.Log("拉力列表:" + string.Join(",", tempPullList));
|
||||
|
||||
if (pullList == null) pullList = new List<ushort>();
|
||||
foreach (var pull in tempPullList)
|
||||
{
|
||||
@@ -269,7 +271,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
pullList.Add(pull);
|
||||
}
|
||||
tempPullList.Clear();
|
||||
//Debug.Log("拉力:" + string.Join(",",list));
|
||||
|
||||
}
|
||||
}
|
||||
List<ushort> pullList { get; set; }
|
||||
|
||||
@@ -116,6 +116,10 @@ namespace Assets.Scripts.Ble
|
||||
private void ManagerStatusChanged(BleMobileThread sender, WclBleManagerStatus status)
|
||||
{
|
||||
this.BleState = BleMobileInterface.StateFromNativeState(status);
|
||||
if (this.BleState == BleState.Off)
|
||||
{
|
||||
ClearAllCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
private void WatcherScanInfoReceived(BleMobileThread sender, string address, string name, int rssi,string[] uuids)
|
||||
@@ -348,6 +352,7 @@ namespace Assets.Scripts.Ble
|
||||
BluetoothLEHardwareInterface.DisconnectPeripheral(peripheral.Address, (address) =>
|
||||
{
|
||||
Debug.Log("断开回调"+ address);
|
||||
PeripheralDisconnected(address,peripheral);
|
||||
peripheralDisconnectedEvent(this, peripheral, null, true);
|
||||
callback?.Invoke();
|
||||
});
|
||||
@@ -374,6 +379,17 @@ namespace Assets.Scripts.Ble
|
||||
{
|
||||
bleMobileThread?.Stop();
|
||||
}
|
||||
|
||||
public void ClearAllCallbacks()
|
||||
{
|
||||
callbacks?.Clear();
|
||||
servicesCallbacks?.Clear();
|
||||
characteristicNotificationCallbacks?.Clear();
|
||||
characteristicReadCallbacks?.Clear();
|
||||
characteristicsDiscoveredCallbacks?.Clear();
|
||||
_discoveredCallback = null;
|
||||
_pCache?.Clear();
|
||||
}
|
||||
|
||||
//发现服务列表
|
||||
public void DiscoverServices(BlePeripheralInfo peripheral, Action<IBleWinHwInterface, BlePeripheralInfo, BleResponse<List<BleServiceInfo>>> callback)
|
||||
|
||||
Reference in new issue
Block a user