修复设备选择界面多设备选择bug
This commit is contained in:
parent
7729332f41
commit
5671b35dce
@ -1718,7 +1718,7 @@ PrefabInstance:
|
|||||||
- target: {fileID: 2947521786256289149, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
- target: {fileID: 2947521786256289149, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: mType
|
propertyPath: mType
|
||||||
value: 1
|
value: 5
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 4634260803276928508, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
- target: {fileID: 4634260803276928508, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
||||||
type: 3}
|
type: 3}
|
||||||
@ -2274,7 +2274,7 @@ PrefabInstance:
|
|||||||
- target: {fileID: 2947521786256289149, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
- target: {fileID: 2947521786256289149, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: mType
|
propertyPath: mType
|
||||||
value: 5
|
value: 4
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 4634260803276928508, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
- target: {fileID: 4634260803276928508, guid: 95d5b69c6ebb5f34bb864b2c0756d442,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
|||||||
@ -13,6 +13,11 @@ namespace Assets.Scripts.Devices
|
|||||||
|
|
||||||
public SensorType Sensor { get; protected set; }
|
public SensorType Sensor { get; protected set; }
|
||||||
|
|
||||||
|
public string Id
|
||||||
|
{
|
||||||
|
get; protected set;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual string Name
|
public virtual string Name
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@ -34,8 +39,9 @@ namespace Assets.Scripts.Devices
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int SignalStrength { get; internal set; }
|
public int SignalStrength { get; internal set; }
|
||||||
|
|
||||||
protected AbstractDevice(NetworkType networkType)
|
protected AbstractDevice(string id, NetworkType networkType)
|
||||||
{
|
{
|
||||||
|
this.Id = id;
|
||||||
this.Network = networkType;
|
this.Network = networkType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -93,8 +93,8 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
//private readonly DeviceDetailService _deviceDetailService;
|
//private readonly DeviceDetailService _deviceDetailService;
|
||||||
//private readonly AntManufacturerService antManufacturerService;
|
//private readonly AntManufacturerService antManufacturerService;
|
||||||
protected List<IPageHandler> pageHandlers = new List<IPageHandler>();
|
protected List<IPageHandler> pageHandlers = new List<IPageHandler>();
|
||||||
public AbstractAntDevice(String defaultSourceName, racerSportType sportType, SensorType sensor)
|
public AbstractAntDevice(string id, String defaultSourceName, racerSportType sportType, SensorType sensor)
|
||||||
: base(sportType, true)
|
: base(id, sportType, true)
|
||||||
{
|
{
|
||||||
State = DeviceState.Disconnected;
|
State = DeviceState.Disconnected;
|
||||||
this.Name = defaultSourceName;
|
this.Name = defaultSourceName;
|
||||||
|
|||||||
@ -81,11 +81,11 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
}
|
}
|
||||||
//CheckStatus();
|
//CheckStatus();
|
||||||
|
|
||||||
deviceList.Add(new FitDevice());
|
deviceList.Add(new FitDevice(""));
|
||||||
deviceList.Add(new PowerDevice());
|
deviceList.Add(new PowerDevice(""));
|
||||||
deviceList.Add(new CadenceDevice());
|
deviceList.Add(new CadenceDevice(""));
|
||||||
deviceList.Add(new HeartRateDevice());
|
deviceList.Add(new HeartRateDevice(""));
|
||||||
deviceList.Add(new BikeSpdCadDevice());
|
deviceList.Add(new BikeSpdCadDevice(""));
|
||||||
|
|
||||||
var timer = new System.Timers.Timer(1000);
|
var timer = new System.Timers.Timer(1000);
|
||||||
timer.AutoReset = true;
|
timer.AutoReset = true;
|
||||||
@ -336,27 +336,28 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
var device1 = deviceList.SingleOrDefault(d => d.searchProfile.deviceType == deviceTypeId);
|
var device1 = deviceList.SingleOrDefault(d => d.searchProfile.deviceType == deviceTypeId);
|
||||||
if (device1 != null)
|
if (device1 != null)
|
||||||
{
|
{
|
||||||
|
var id = $"{ deviceNumber }:{ deviceTypeId}:{ transmissionTypeId }";
|
||||||
AbstractAntDevice device = null;
|
AbstractAntDevice device = null;
|
||||||
switch (device1.Sensor)
|
switch (device1.Sensor)
|
||||||
{
|
{
|
||||||
case SensorType.None:
|
case SensorType.None:
|
||||||
break;
|
break;
|
||||||
case SensorType.Cadence:
|
case SensorType.Cadence:
|
||||||
device = new CadenceDevice();
|
device = new CadenceDevice(id);
|
||||||
break;
|
break;
|
||||||
case SensorType.HeartRate:
|
case SensorType.HeartRate:
|
||||||
device = new HeartRateDevice();
|
device = new HeartRateDevice(id);
|
||||||
break;
|
break;
|
||||||
case SensorType.Power:
|
case SensorType.Power:
|
||||||
device = new PowerDevice();
|
device = new PowerDevice(id);
|
||||||
break;
|
break;
|
||||||
case SensorType.Speed:
|
case SensorType.Speed:
|
||||||
break;
|
break;
|
||||||
case SensorType.SpeedCadence:
|
case SensorType.SpeedCadence:
|
||||||
device = new BikeSpdCadDevice();
|
device = new BikeSpdCadDevice(id);
|
||||||
break;
|
break;
|
||||||
case SensorType.Trainer:
|
case SensorType.Trainer:
|
||||||
device = new FitDevice();
|
device = new FitDevice(id);
|
||||||
break;
|
break;
|
||||||
case SensorType.VirtualPower:
|
case SensorType.VirtualPower:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -18,8 +18,8 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
private RotationData _speedData = new RotationData();
|
private RotationData _speedData = new RotationData();
|
||||||
private RotationData _cadenceData = new RotationData();
|
private RotationData _cadenceData = new RotationData();
|
||||||
|
|
||||||
public BikeSpdCadDevice(double wheelCircumfrence_m = DEFAULT_WHEEL_CIRCUMFERENCE_m)
|
public BikeSpdCadDevice(string id, double wheelCircumfrence_m = DEFAULT_WHEEL_CIRCUMFERENCE_m)
|
||||||
: base("Ant+ Speed&Cadence", racerSportType.Biking, SensorType.SpeedCadence)
|
: base(id, "Ant+ Speed&Cadence", racerSportType.Biking, SensorType.SpeedCadence)
|
||||||
{
|
{
|
||||||
Priority = 1;
|
Priority = 1;
|
||||||
this.wheelCircumfrence_m = wheelCircumfrence_m;
|
this.wheelCircumfrence_m = wheelCircumfrence_m;
|
||||||
|
|||||||
@ -28,8 +28,8 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
private DateTime _now = DateTime.Now;
|
private DateTime _now = DateTime.Now;
|
||||||
private RotationData _rotationData = new RotationData();
|
private RotationData _rotationData = new RotationData();
|
||||||
|
|
||||||
public CadenceDevice()
|
public CadenceDevice(string id)
|
||||||
: base("Ant+ Cadence", racerSportType.Biking, SensorType.Cadence)
|
: base(id, "Ant+ Cadence", racerSportType.Biking, SensorType.Cadence)
|
||||||
{
|
{
|
||||||
Priority = 2;
|
Priority = 2;
|
||||||
//if (speedSensor.isInUse)
|
//if (speedSensor.isInUse)
|
||||||
|
|||||||
@ -26,7 +26,7 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
public readonly byte uid;
|
public readonly byte uid;
|
||||||
|
|
||||||
|
|
||||||
public DataSourceBase(racerSportType sportType, bool isHuman):base(NetworkType.ANT)
|
public DataSourceBase(string id, racerSportType sportType, bool isHuman):base(id, NetworkType.ANT)
|
||||||
{
|
{
|
||||||
this.sportType = sportType;
|
this.sportType = sportType;
|
||||||
this.isHuman = isHuman;
|
this.isHuman = isHuman;
|
||||||
|
|||||||
@ -25,8 +25,8 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private double _grade = 0;
|
private double _grade = 0;
|
||||||
private bool IsCalibrating { get; set; }
|
private bool IsCalibrating { get; set; }
|
||||||
public FitDevice()
|
public FitDevice(string id)
|
||||||
: base("Ant+ Trainer", racerSportType.Unknown, SensorType.Trainer)
|
: base(id, "Ant+ Trainer", racerSportType.Unknown, SensorType.Trainer)
|
||||||
{
|
{
|
||||||
Priority = 0;
|
Priority = 0;
|
||||||
this.StateChange = (state) =>
|
this.StateChange = (state) =>
|
||||||
|
|||||||
@ -26,8 +26,8 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
|
|
||||||
//ds_AntPlus_BikeSpd speedSensor;
|
//ds_AntPlus_BikeSpd speedSensor;
|
||||||
|
|
||||||
public HeartRateDevice()
|
public HeartRateDevice(string id)
|
||||||
: base("Ant+ HeartRate", racerSportType.Unknown, SensorType.HeartRate)
|
: base(id, "Ant+ HeartRate", racerSportType.Unknown, SensorType.HeartRate)
|
||||||
{
|
{
|
||||||
Priority = 2;
|
Priority = 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,8 +23,8 @@ namespace Assets.Scripts.Devices.Ant
|
|||||||
|
|
||||||
//List<IPageHandler> pageHandlers;
|
//List<IPageHandler> pageHandlers;
|
||||||
|
|
||||||
public PowerDevice()
|
public PowerDevice(string id)
|
||||||
: base("Ant+ Power", racerSportType.Biking, SensorType.Power)
|
: base(id, "Ant+ Power", racerSportType.Biking, SensorType.Power)
|
||||||
{
|
{
|
||||||
Priority = 2;
|
Priority = 2;
|
||||||
//pageHandlers = new List<IPageHandler>();
|
//pageHandlers = new List<IPageHandler>();
|
||||||
|
|||||||
@ -23,10 +23,15 @@ namespace Assets.Scripts.Devices.Ble
|
|||||||
private readonly HashSet<BleServiceInfo> pendingServices = new HashSet<BleServiceInfo>();
|
private readonly HashSet<BleServiceInfo> pendingServices = new HashSet<BleServiceInfo>();
|
||||||
|
|
||||||
public override string Name { get => peripheralInfo.Name; protected set => base.Name = value; }
|
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 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 = bleWinHwInterface;
|
||||||
this.hwInterface.BluetoothStateChangedEvent += BluetoothStateChangedEvent;
|
this.hwInterface.BluetoothStateChangedEvent += BluetoothStateChangedEvent;
|
||||||
@ -45,7 +50,23 @@ namespace Assets.Scripts.Devices.Ble
|
|||||||
|
|
||||||
public void ConnectToPeripheralIfPossible()
|
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)
|
private void PeripheralConnectedAction(BleWinHwInterface hwInterface, BlePeripheralInfo sender, BleResponse response)
|
||||||
@ -201,6 +222,7 @@ namespace Assets.Scripts.Devices.Ble
|
|||||||
{
|
{
|
||||||
if (this.State != DeviceState.Disconnected)
|
if (this.State != DeviceState.Disconnected)
|
||||||
{
|
{
|
||||||
|
Debug.Log("断开设备" + this.Name);
|
||||||
this.hwInterface.DisconnectPeripheral(this.peripheralInfo, ()=> {
|
this.hwInterface.DisconnectPeripheral(this.peripheralInfo, ()=> {
|
||||||
this.State = DeviceState.Disconnected;
|
this.State = DeviceState.Disconnected;
|
||||||
});
|
});
|
||||||
@ -238,7 +260,8 @@ namespace Assets.Scripts.Devices.Ble
|
|||||||
public override void Disconnect(bool save = true)
|
public override void Disconnect(bool save = true)
|
||||||
{
|
{
|
||||||
//throw new NotImplementedException();
|
//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;
|
return;
|
||||||
this.Cadence = 0;
|
this.Cadence = 0;
|
||||||
}
|
}
|
||||||
|
Debug.Log("踏频值:" + this.Cadence);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleSpeedUpdate()
|
private void HandleSpeedUpdate()
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
|||||||
private CyclingPowerMeasurement cyclingPowerMeasurement;
|
private CyclingPowerMeasurement cyclingPowerMeasurement;
|
||||||
public CyclingPower(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Power)
|
public CyclingPower(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Power)
|
||||||
{
|
{
|
||||||
|
Priority = 2;
|
||||||
cyclingPowerMeasurement = new CyclingPowerMeasurement(1920);
|
cyclingPowerMeasurement = new CyclingPowerMeasurement(1920);
|
||||||
base.Characteristics.Add(cyclingPowerMeasurement);
|
base.Characteristics.Add(cyclingPowerMeasurement);
|
||||||
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
|
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
|
||||||
|
|||||||
@ -18,6 +18,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
|||||||
private HeartRateMeasurement heartRateMeasurement;
|
private HeartRateMeasurement heartRateMeasurement;
|
||||||
public HeartRate(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.HeartRate)
|
public HeartRate(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.HeartRate)
|
||||||
{
|
{
|
||||||
|
Priority = 2;
|
||||||
heartRateMeasurement = new HeartRateMeasurement();
|
heartRateMeasurement = new HeartRateMeasurement();
|
||||||
|
|
||||||
base.Characteristics.Add(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)
|
public SpeedCadence(BlePeripheralInfo peripheralInfo, BleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.SpeedCadence)
|
||||||
{
|
{
|
||||||
Debug.Log("创建速度踏频设备");
|
Debug.Log("创建速度踏频设备");
|
||||||
|
Priority = 1;
|
||||||
_cyclingSpeedCadenceMeasurement = new CyclingSpeedCadenceMeasurement(this._wheelCircumference);
|
_cyclingSpeedCadenceMeasurement = new CyclingSpeedCadenceMeasurement(this._wheelCircumference);
|
||||||
base.Characteristics.Add(_cyclingSpeedCadenceMeasurement);
|
base.Characteristics.Add(_cyclingSpeedCadenceMeasurement);
|
||||||
|
|
||||||
|
|||||||
@ -266,9 +266,19 @@ namespace Assets.Scripts.Ble
|
|||||||
private void GattConnected(WclBleGattThread gattClient, BleResponse response)
|
private void GattConnected(WclBleGattThread gattClient, BleResponse response)
|
||||||
{
|
{
|
||||||
Debug.Log($"gatt connected { response.ToString() }");
|
Debug.Log($"gatt connected { response.ToString() }");
|
||||||
|
if (!response.IsSuccess)
|
||||||
|
{
|
||||||
|
gattClient.Stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.callbacks[gattClient.Peripheral].Invoke(this, gattClient.Peripheral, response);
|
this.callbacks[gattClient.Peripheral].Invoke(this, gattClient.Peripheral, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CleanUpPeripheral(BlePeripheralInfo peripheralInfo)
|
||||||
|
{
|
||||||
|
//this.callbacks.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
private void GattDisconnected(WclBleGattThread gattClient, BleResponse response)
|
private void GattDisconnected(WclBleGattThread gattClient, BleResponse response)
|
||||||
{
|
{
|
||||||
Debug.Log("gatt disconnected");
|
Debug.Log("gatt disconnected");
|
||||||
@ -326,7 +336,7 @@ namespace Assets.Scripts.Ble
|
|||||||
}
|
}
|
||||||
private void GattCharacteristicChanged(WclBleGattThread gattClient, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
|
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)
|
if(this.wclBleMainThread.GetGattThread(characteristic.Peripheral) != null)
|
||||||
{
|
{
|
||||||
this.characteristicReadEvent.Invoke(this, characteristic, response);
|
this.characteristicReadEvent.Invoke(this, characteristic, response);
|
||||||
@ -418,7 +428,7 @@ namespace Assets.Scripts.Ble
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
this.wclBleMainThread.Dispose();
|
this.wclBleMainThread.Stop();
|
||||||
this.wclBleMainThread = null;
|
this.wclBleMainThread = null;
|
||||||
hwInterface = null;
|
hwInterface = null;
|
||||||
pCache.Clear();
|
pCache.Clear();
|
||||||
|
|||||||
@ -98,7 +98,7 @@ namespace Assets.Scripts.Devices.Ble.Win
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Stop()
|
||||||
{
|
{
|
||||||
Debug.Log("停止thread");
|
Debug.Log("停止thread");
|
||||||
foreach (var item in this.gattClients.Values)
|
foreach (var item in this.gattClients.Values)
|
||||||
|
|||||||
@ -46,7 +46,7 @@ namespace Assets.Scripts.Devices
|
|||||||
var adapter = adapters.FirstOrDefault(a => a.Interface == connectionInterface);
|
var adapter = adapters.FirstOrDefault(a => a.Interface == connectionInterface);
|
||||||
if(adapter != null)
|
if(adapter != null)
|
||||||
{
|
{
|
||||||
Debug.Log("bbbbbb " + (adapter.GetState().ToString()));
|
//Debug.Log("bbbbbb " + (adapter.GetState().ToString()));
|
||||||
return adapter.GetState();
|
return adapter.GetState();
|
||||||
}
|
}
|
||||||
return DeviceAdapterState.Unavailable;
|
return DeviceAdapterState.Unavailable;
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
private UnityEngine.Object deviceItem;
|
private UnityEngine.Object deviceItem;
|
||||||
private VerticalLayoutGroup content;
|
private VerticalLayoutGroup content;
|
||||||
private PfUIButton connectBtn;
|
private PfUIButton connectBtn;
|
||||||
private Dictionary<ushort, DeviceItem> deviceList;
|
private Dictionary<string, DeviceItem> deviceList;
|
||||||
private Text noDevice,Title;
|
private Text noDevice,Title;
|
||||||
private RectTransform searchIconRect;
|
private RectTransform searchIconRect;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
{
|
{
|
||||||
base.Awake();
|
base.Awake();
|
||||||
|
|
||||||
deviceList = new Dictionary<ushort, DeviceItem>();
|
deviceList = new Dictionary<string, DeviceItem>();
|
||||||
|
|
||||||
var container = this.transform.Find("GameObject");
|
var container = this.transform.Find("GameObject");
|
||||||
var closeBtn = container.Find("CloseBtn");
|
var closeBtn = container.Find("CloseBtn");
|
||||||
@ -82,7 +82,16 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
{
|
{
|
||||||
if (item.Value.GetStatus() == false)
|
if (item.Value.GetStatus() == false)
|
||||||
{
|
{
|
||||||
if (item.Value.DeviceInfo.Sensor == SensorType)
|
if (SensorType == SensorType.SpeedCadence)
|
||||||
|
{
|
||||||
|
if (item.Value.DeviceInfo.Sensor == SensorType.SpeedCadence || item.Value.DeviceInfo.Sensor == SensorType.Cadence)
|
||||||
|
{
|
||||||
|
//Debug.Log("断开设备" + item.Value.DeviceInfo.Name);
|
||||||
|
item.Value.DeviceInfo.Disconnect();
|
||||||
|
DeviceCache.Remove(item.Value.DeviceInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (item.Value.DeviceInfo.Sensor == SensorType)
|
||||||
{
|
{
|
||||||
item.Value.DeviceInfo.Disconnect();
|
item.Value.DeviceInfo.Disconnect();
|
||||||
DeviceCache.Remove(item.Value.DeviceInfo);
|
DeviceCache.Remove(item.Value.DeviceInfo);
|
||||||
@ -90,7 +99,7 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var dd = deviceList.Select(d => d.Value).Where(d => d.GetStatus()).FirstOrDefault();
|
var dd = deviceList.Select(d => d.Value).Where(d => d.GetStatus()).FirstOrDefault();
|
||||||
if(dd != null)
|
if (dd != null)
|
||||||
{
|
{
|
||||||
dd.DeviceInfo.Connect();
|
dd.DeviceInfo.Connect();
|
||||||
DeviceCache.Add(dd.DeviceInfo);
|
DeviceCache.Add(dd.DeviceInfo);
|
||||||
@ -131,6 +140,7 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
//var a = AntConnector.Instance().discoveredDevices;
|
//var a = AntConnector.Instance().discoveredDevices;
|
||||||
switch (SensorType)
|
switch (SensorType)
|
||||||
{
|
{
|
||||||
|
case SensorType.SpeedCadence:
|
||||||
case SensorType.Cadence:
|
case SensorType.Cadence:
|
||||||
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is ICadenceDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList();
|
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is ICadenceDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList();
|
||||||
break;
|
break;
|
||||||
@ -141,8 +151,6 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is IPowerDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList();
|
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is IPowerDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList();
|
||||||
break;
|
break;
|
||||||
case SensorType.Speed:
|
case SensorType.Speed:
|
||||||
break;
|
|
||||||
case SensorType.SpeedCadence:
|
|
||||||
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is ISpeedDevice && d.State == DeviceState.Connected)).OrderBy(d => d.Priority).ToList();
|
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is ISpeedDevice && d.State == DeviceState.Connected)).OrderBy(d => d.Priority).ToList();
|
||||||
break;
|
break;
|
||||||
case SensorType.Trainer:
|
case SensorType.Trainer:
|
||||||
@ -154,7 +162,7 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
|
|
||||||
foreach (var device in devices)
|
foreach (var device in devices)
|
||||||
{
|
{
|
||||||
if (deviceList.ContainsKey(device.DeviceNumber))
|
if (deviceList.ContainsKey(device.Id))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -170,7 +178,7 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
deviceItemObj.Set(true);
|
deviceItemObj.Set(true);
|
||||||
foreach (var item in deviceList)
|
foreach (var item in deviceList)
|
||||||
{
|
{
|
||||||
if (item.Key != deviceItemObj.DeviceInfo.DeviceNumber)
|
if (item.Key != deviceItemObj.DeviceInfo.Id)
|
||||||
{
|
{
|
||||||
item.Value.Set(false);
|
item.Value.Set(false);
|
||||||
}
|
}
|
||||||
@ -186,7 +194,7 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
// }
|
// }
|
||||||
//}));
|
//}));
|
||||||
|
|
||||||
deviceList.Add(device.DeviceNumber, deviceItemObj);
|
deviceList.Add(device.Id, deviceItemObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceList.All(d=>d.Value.GetStatus() == false))
|
if(deviceList.All(d=>d.Value.GetStatus() == false))
|
||||||
@ -199,6 +207,12 @@ public class ConnectDeviceModal : PFUIPanel
|
|||||||
//connectBtn.text.text = "DISCOUNECT";
|
//connectBtn.text.text = "DISCOUNECT";
|
||||||
noDevice.text = firstDevice.DeviceInfo.Name;
|
noDevice.text = firstDevice.DeviceInfo.Name;
|
||||||
}
|
}
|
||||||
|
//DeviceItem firstDevice;
|
||||||
|
//var devicesTemp = deviceList.Select(d => d.Value).Where(d => d.DeviceInfo.State == DeviceState.Connected);
|
||||||
|
//if(SensorType == SensorType.Cadence || SensorType == SensorType.SpeedCadence)
|
||||||
|
//{
|
||||||
|
// firstDevice = devicesTemp.FirstOrDefault(d=>d)
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
|
|||||||
public override void OnDeselect(BaseEventData eventData)
|
public override void OnDeselect(BaseEventData eventData)
|
||||||
{
|
{
|
||||||
//base.OnDeselect(eventData);
|
//base.OnDeselect(eventData);
|
||||||
Debug.Log("deselect");
|
//Debug.Log("deselect");
|
||||||
|
|
||||||
|
|
||||||
//DeviceInfo.Disconnect();
|
//DeviceInfo.Disconnect();
|
||||||
|
|||||||
@ -158,7 +158,7 @@ public class DeviceView : MonoBehaviour
|
|||||||
|
|
||||||
powerUnit.text = "W";
|
powerUnit.text = "W";
|
||||||
}
|
}
|
||||||
else if (SensorType == SensorType.SpeedCadence)
|
else if (SensorType == SensorType.Speed)
|
||||||
{
|
{
|
||||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_0");
|
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_0");
|
||||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Speed_1");
|
sprite1 = Resources.Load<Sprite>("Images/Devices/Speed_1");
|
||||||
@ -166,7 +166,7 @@ public class DeviceView : MonoBehaviour
|
|||||||
|
|
||||||
powerUnit.text = "KPH";
|
powerUnit.text = "KPH";
|
||||||
}
|
}
|
||||||
else if (SensorType == SensorType.Cadence)
|
else if (SensorType == SensorType.Cadence || SensorType == SensorType.SpeedCadence)
|
||||||
{
|
{
|
||||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_0");
|
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_0");
|
||||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
|
sprite1 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
|
||||||
@ -289,6 +289,7 @@ public class DeviceView : MonoBehaviour
|
|||||||
{
|
{
|
||||||
case SensorType.None:
|
case SensorType.None:
|
||||||
break;
|
break;
|
||||||
|
case SensorType.SpeedCadence:
|
||||||
case SensorType.Cadence:
|
case SensorType.Cadence:
|
||||||
return "Cadence Sensor";
|
return "Cadence Sensor";
|
||||||
case SensorType.HeartRate:
|
case SensorType.HeartRate:
|
||||||
@ -296,8 +297,6 @@ public class DeviceView : MonoBehaviour
|
|||||||
case SensorType.Power:
|
case SensorType.Power:
|
||||||
return "Power Meter";
|
return "Power Meter";
|
||||||
case SensorType.Speed:
|
case SensorType.Speed:
|
||||||
break;
|
|
||||||
case SensorType.SpeedCadence:
|
|
||||||
return "Speed Meter";
|
return "Speed Meter";
|
||||||
case SensorType.Trainer:
|
case SensorType.Trainer:
|
||||||
return "Smart Trainer";
|
return "Smart Trainer";
|
||||||
@ -316,6 +315,7 @@ public class DeviceView : MonoBehaviour
|
|||||||
{
|
{
|
||||||
case SensorType.None:
|
case SensorType.None:
|
||||||
break;
|
break;
|
||||||
|
case SensorType.SpeedCadence:
|
||||||
case SensorType.Cadence:
|
case SensorType.Cadence:
|
||||||
//cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
//cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||||
return (connectedDevice as ICadenceDevice).Cadence.ToString();
|
return (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||||
@ -324,8 +324,6 @@ public class DeviceView : MonoBehaviour
|
|||||||
case SensorType.Power:
|
case SensorType.Power:
|
||||||
return (connectedDevice as IPowerDevice).Power.ToString();
|
return (connectedDevice as IPowerDevice).Power.ToString();
|
||||||
case SensorType.Speed:
|
case SensorType.Speed:
|
||||||
break;
|
|
||||||
case SensorType.SpeedCadence:
|
|
||||||
return (connectedDevice as ISpeedDevice).Speed.ToString();
|
return (connectedDevice as ISpeedDevice).Speed.ToString();
|
||||||
case SensorType.Trainer:
|
case SensorType.Trainer:
|
||||||
//powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
|
//powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
|
||||||
@ -357,6 +355,7 @@ public class DeviceView : MonoBehaviour
|
|||||||
{
|
{
|
||||||
case SensorType.None:
|
case SensorType.None:
|
||||||
break;
|
break;
|
||||||
|
case SensorType.SpeedCadence:
|
||||||
case SensorType.Cadence:
|
case SensorType.Cadence:
|
||||||
return devices.FirstOrDefault(d => d is ICadenceDevice);
|
return devices.FirstOrDefault(d => d is ICadenceDevice);
|
||||||
case SensorType.HeartRate:
|
case SensorType.HeartRate:
|
||||||
@ -369,7 +368,6 @@ public class DeviceView : MonoBehaviour
|
|||||||
//}
|
//}
|
||||||
return item;
|
return item;
|
||||||
case SensorType.Speed:
|
case SensorType.Speed:
|
||||||
case SensorType.SpeedCadence:
|
|
||||||
return devices.FirstOrDefault(d => d is ISpeedDevice);
|
return devices.FirstOrDefault(d => d is ISpeedDevice);
|
||||||
case SensorType.Trainer:
|
case SensorType.Trainer:
|
||||||
var item3 = devices.FirstOrDefault(d => d.Sensor == SensorType.Trainer);
|
var item3 = devices.FirstOrDefault(d => d.Sensor == SensorType.Trainer);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user