From 5671b35dce268ae53af8cb0da9bcb4859b8150f2 Mon Sep 17 00:00:00 2001 From: suntao Date: Fri, 4 Jun 2021 18:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E5=A4=87=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E7=95=8C=E9=9D=A2=E5=A4=9A=E8=AE=BE=E5=A4=87=E9=80=89?= =?UTF-8?q?=E6=8B=A9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Prefab/Panel/DevicePanel.prefab | 4 +- Assets/Scripts/Devices/AbstractDevice.cs | 8 +++- .../Scripts/Devices/Ant/AbstractAntDevice.cs | 4 +- Assets/Scripts/Devices/Ant/AntConnector.cs | 21 +++++----- .../Scripts/Devices/Ant/BikeSpdCadDevice.cs | 4 +- Assets/Scripts/Devices/Ant/CadenceDevice.cs | 4 +- Assets/Scripts/Devices/Ant/DataSourceBase.cs | 2 +- Assets/Scripts/Devices/Ant/FitDevice.cs | 4 +- Assets/Scripts/Devices/Ant/HeartRateDevice.cs | 4 +- Assets/Scripts/Devices/Ant/PowerDevice.cs | 4 +- Assets/Scripts/Devices/Ble/BleDevice.cs | 31 +++++++++++++-- .../CyclingSpeedCadenceMeasurement.cs | 1 + .../Devices/Ble/Devices/CyclingPower.cs | 2 +- .../Scripts/Devices/Ble/Devices/HeartRate.cs | 1 + .../Devices/Ble/Devices/SpeedCadence.cs | 1 + .../Devices/Ble/Win/BleWinHwInterface.cs | 14 ++++++- .../Devices/Ble/Win/WclBleMainThread.cs | 2 +- Assets/Scripts/Devices/MainDeviceAdapter.cs | 2 +- .../UI/Prefab/Device/ConnectDeviceModal.cs | 38 +++++++++++++------ Assets/Scripts/UI/Prefab/Device/DeviceItem.cs | 2 +- Assets/Scripts/UI/Prefab/Device/DeviceView.cs | 14 +++---- 21 files changed, 111 insertions(+), 56 deletions(-) diff --git a/Assets/Resources/UI/Prefab/Panel/DevicePanel.prefab b/Assets/Resources/UI/Prefab/Panel/DevicePanel.prefab index eab71612..7a17ff01 100644 --- a/Assets/Resources/UI/Prefab/Panel/DevicePanel.prefab +++ b/Assets/Resources/UI/Prefab/Panel/DevicePanel.prefab @@ -1718,7 +1718,7 @@ PrefabInstance: - target: {fileID: 2947521786256289149, guid: 95d5b69c6ebb5f34bb864b2c0756d442, type: 3} propertyPath: mType - value: 1 + value: 5 objectReference: {fileID: 0} - target: {fileID: 4634260803276928508, guid: 95d5b69c6ebb5f34bb864b2c0756d442, type: 3} @@ -2274,7 +2274,7 @@ PrefabInstance: - target: {fileID: 2947521786256289149, guid: 95d5b69c6ebb5f34bb864b2c0756d442, type: 3} propertyPath: mType - value: 5 + value: 4 objectReference: {fileID: 0} - target: {fileID: 4634260803276928508, guid: 95d5b69c6ebb5f34bb864b2c0756d442, type: 3} diff --git a/Assets/Scripts/Devices/AbstractDevice.cs b/Assets/Scripts/Devices/AbstractDevice.cs index 4fccfd2e..ae38c0c1 100644 --- a/Assets/Scripts/Devices/AbstractDevice.cs +++ b/Assets/Scripts/Devices/AbstractDevice.cs @@ -13,6 +13,11 @@ namespace Assets.Scripts.Devices public SensorType Sensor { get; protected set; } + public string Id + { + get; protected set; + } + public virtual string Name { get; @@ -34,8 +39,9 @@ namespace Assets.Scripts.Devices /// public int SignalStrength { get; internal set; } - protected AbstractDevice(NetworkType networkType) + protected AbstractDevice(string id, NetworkType networkType) { + this.Id = id; this.Network = networkType; } diff --git a/Assets/Scripts/Devices/Ant/AbstractAntDevice.cs b/Assets/Scripts/Devices/Ant/AbstractAntDevice.cs index 22a60158..ea5db877 100644 --- a/Assets/Scripts/Devices/Ant/AbstractAntDevice.cs +++ b/Assets/Scripts/Devices/Ant/AbstractAntDevice.cs @@ -93,8 +93,8 @@ namespace Assets.Scripts.Devices.Ant //private readonly DeviceDetailService _deviceDetailService; //private readonly AntManufacturerService antManufacturerService; protected List pageHandlers = new List(); - public AbstractAntDevice(String defaultSourceName, racerSportType sportType, SensorType sensor) - : base(sportType, true) + public AbstractAntDevice(string id, String defaultSourceName, racerSportType sportType, SensorType sensor) + : base(id, sportType, true) { State = DeviceState.Disconnected; this.Name = defaultSourceName; diff --git a/Assets/Scripts/Devices/Ant/AntConnector.cs b/Assets/Scripts/Devices/Ant/AntConnector.cs index 0e08c844..40405e70 100644 --- a/Assets/Scripts/Devices/Ant/AntConnector.cs +++ b/Assets/Scripts/Devices/Ant/AntConnector.cs @@ -81,11 +81,11 @@ namespace Assets.Scripts.Devices.Ant } //CheckStatus(); - deviceList.Add(new FitDevice()); - deviceList.Add(new PowerDevice()); - deviceList.Add(new CadenceDevice()); - deviceList.Add(new HeartRateDevice()); - deviceList.Add(new BikeSpdCadDevice()); + deviceList.Add(new FitDevice("")); + deviceList.Add(new PowerDevice("")); + deviceList.Add(new CadenceDevice("")); + deviceList.Add(new HeartRateDevice("")); + deviceList.Add(new BikeSpdCadDevice("")); var timer = new System.Timers.Timer(1000); timer.AutoReset = true; @@ -336,27 +336,28 @@ namespace Assets.Scripts.Devices.Ant var device1 = deviceList.SingleOrDefault(d => d.searchProfile.deviceType == deviceTypeId); if (device1 != null) { + var id = $"{ deviceNumber }:{ deviceTypeId}:{ transmissionTypeId }"; AbstractAntDevice device = null; switch (device1.Sensor) { case SensorType.None: break; case SensorType.Cadence: - device = new CadenceDevice(); + device = new CadenceDevice(id); break; case SensorType.HeartRate: - device = new HeartRateDevice(); + device = new HeartRateDevice(id); break; case SensorType.Power: - device = new PowerDevice(); + device = new PowerDevice(id); break; case SensorType.Speed: break; case SensorType.SpeedCadence: - device = new BikeSpdCadDevice(); + device = new BikeSpdCadDevice(id); break; case SensorType.Trainer: - device = new FitDevice(); + device = new FitDevice(id); break; case SensorType.VirtualPower: break; diff --git a/Assets/Scripts/Devices/Ant/BikeSpdCadDevice.cs b/Assets/Scripts/Devices/Ant/BikeSpdCadDevice.cs index 896947f6..8c637040 100644 --- a/Assets/Scripts/Devices/Ant/BikeSpdCadDevice.cs +++ b/Assets/Scripts/Devices/Ant/BikeSpdCadDevice.cs @@ -18,8 +18,8 @@ namespace Assets.Scripts.Devices.Ant private RotationData _speedData = new RotationData(); private RotationData _cadenceData = new RotationData(); - public BikeSpdCadDevice(double wheelCircumfrence_m = DEFAULT_WHEEL_CIRCUMFERENCE_m) - : base("Ant+ Speed&Cadence", racerSportType.Biking, SensorType.SpeedCadence) + public BikeSpdCadDevice(string id, double wheelCircumfrence_m = DEFAULT_WHEEL_CIRCUMFERENCE_m) + : base(id, "Ant+ Speed&Cadence", racerSportType.Biking, SensorType.SpeedCadence) { Priority = 1; this.wheelCircumfrence_m = wheelCircumfrence_m; diff --git a/Assets/Scripts/Devices/Ant/CadenceDevice.cs b/Assets/Scripts/Devices/Ant/CadenceDevice.cs index 37e9a75e..1d5c631a 100644 --- a/Assets/Scripts/Devices/Ant/CadenceDevice.cs +++ b/Assets/Scripts/Devices/Ant/CadenceDevice.cs @@ -28,8 +28,8 @@ namespace Assets.Scripts.Devices.Ant private DateTime _now = DateTime.Now; private RotationData _rotationData = new RotationData(); - public CadenceDevice() - : base("Ant+ Cadence", racerSportType.Biking, SensorType.Cadence) + public CadenceDevice(string id) + : base(id, "Ant+ Cadence", racerSportType.Biking, SensorType.Cadence) { Priority = 2; //if (speedSensor.isInUse) diff --git a/Assets/Scripts/Devices/Ant/DataSourceBase.cs b/Assets/Scripts/Devices/Ant/DataSourceBase.cs index 978be736..c0e8e57f 100644 --- a/Assets/Scripts/Devices/Ant/DataSourceBase.cs +++ b/Assets/Scripts/Devices/Ant/DataSourceBase.cs @@ -26,7 +26,7 @@ namespace Assets.Scripts.Devices.Ant 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.isHuman = isHuman; diff --git a/Assets/Scripts/Devices/Ant/FitDevice.cs b/Assets/Scripts/Devices/Ant/FitDevice.cs index 08382a5b..dbd72c71 100644 --- a/Assets/Scripts/Devices/Ant/FitDevice.cs +++ b/Assets/Scripts/Devices/Ant/FitDevice.cs @@ -25,8 +25,8 @@ namespace Assets.Scripts.Devices.Ant /// private double _grade = 0; private bool IsCalibrating { get; set; } - public FitDevice() - : base("Ant+ Trainer", racerSportType.Unknown, SensorType.Trainer) + public FitDevice(string id) + : base(id, "Ant+ Trainer", racerSportType.Unknown, SensorType.Trainer) { Priority = 0; this.StateChange = (state) => diff --git a/Assets/Scripts/Devices/Ant/HeartRateDevice.cs b/Assets/Scripts/Devices/Ant/HeartRateDevice.cs index b6f5dc44..7535544a 100644 --- a/Assets/Scripts/Devices/Ant/HeartRateDevice.cs +++ b/Assets/Scripts/Devices/Ant/HeartRateDevice.cs @@ -26,8 +26,8 @@ namespace Assets.Scripts.Devices.Ant //ds_AntPlus_BikeSpd speedSensor; - public HeartRateDevice() - : base("Ant+ HeartRate", racerSportType.Unknown, SensorType.HeartRate) + public HeartRateDevice(string id) + : base(id, "Ant+ HeartRate", racerSportType.Unknown, SensorType.HeartRate) { Priority = 2; } diff --git a/Assets/Scripts/Devices/Ant/PowerDevice.cs b/Assets/Scripts/Devices/Ant/PowerDevice.cs index b9cfbfab..dd7cfd43 100644 --- a/Assets/Scripts/Devices/Ant/PowerDevice.cs +++ b/Assets/Scripts/Devices/Ant/PowerDevice.cs @@ -23,8 +23,8 @@ namespace Assets.Scripts.Devices.Ant //List pageHandlers; - public PowerDevice() - : base("Ant+ Power", racerSportType.Biking, SensorType.Power) + public PowerDevice(string id) + : base(id, "Ant+ Power", racerSportType.Biking, SensorType.Power) { Priority = 2; //pageHandlers = new List(); diff --git a/Assets/Scripts/Devices/Ble/BleDevice.cs b/Assets/Scripts/Devices/Ble/BleDevice.cs index 133543d5..d06816d0 100644 --- a/Assets/Scripts/Devices/Ble/BleDevice.cs +++ b/Assets/Scripts/Devices/Ble/BleDevice.cs @@ -23,10 +23,15 @@ namespace Assets.Scripts.Devices.Ble private readonly HashSet pendingServices = new HashSet(); public override string Name { get => peripheralInfo.Name; protected set => base.Name = value; } - + public string Address { + get + { + return peripheralInfo.Address; + } + } public List Characteristics { get; protected set; } = new List(); - 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(); } } } diff --git a/Assets/Scripts/Devices/Ble/Characteristic/CyclingSpeedCadenceMeasurement.cs b/Assets/Scripts/Devices/Ble/Characteristic/CyclingSpeedCadenceMeasurement.cs index 2a9d6ee2..92d707ba 100644 --- a/Assets/Scripts/Devices/Ble/Characteristic/CyclingSpeedCadenceMeasurement.cs +++ b/Assets/Scripts/Devices/Ble/Characteristic/CyclingSpeedCadenceMeasurement.cs @@ -62,6 +62,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic return; this.Cadence = 0; } + Debug.Log("踏频值:" + this.Cadence); } private void HandleSpeedUpdate() diff --git a/Assets/Scripts/Devices/Ble/Devices/CyclingPower.cs b/Assets/Scripts/Devices/Ble/Devices/CyclingPower.cs index 3be1eb54..23bbca0b 100644 --- a/Assets/Scripts/Devices/Ble/Devices/CyclingPower.cs +++ b/Assets/Scripts/Devices/Ble/Devices/CyclingPower.cs @@ -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; diff --git a/Assets/Scripts/Devices/Ble/Devices/HeartRate.cs b/Assets/Scripts/Devices/Ble/Devices/HeartRate.cs index 3f1faf04..3f6183aa 100644 --- a/Assets/Scripts/Devices/Ble/Devices/HeartRate.cs +++ b/Assets/Scripts/Devices/Ble/Devices/HeartRate.cs @@ -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); diff --git a/Assets/Scripts/Devices/Ble/Devices/SpeedCadence.cs b/Assets/Scripts/Devices/Ble/Devices/SpeedCadence.cs index 61453909..504a4fd0 100644 --- a/Assets/Scripts/Devices/Ble/Devices/SpeedCadence.cs +++ b/Assets/Scripts/Devices/Ble/Devices/SpeedCadence.cs @@ -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); diff --git a/Assets/Scripts/Devices/Ble/Win/BleWinHwInterface.cs b/Assets/Scripts/Devices/Ble/Win/BleWinHwInterface.cs index 8f606167..89d243ff 100644 --- a/Assets/Scripts/Devices/Ble/Win/BleWinHwInterface.cs +++ b/Assets/Scripts/Devices/Ble/Win/BleWinHwInterface.cs @@ -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 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(); diff --git a/Assets/Scripts/Devices/Ble/Win/WclBleMainThread.cs b/Assets/Scripts/Devices/Ble/Win/WclBleMainThread.cs index 4eb35b05..e3ea3ab1 100644 --- a/Assets/Scripts/Devices/Ble/Win/WclBleMainThread.cs +++ b/Assets/Scripts/Devices/Ble/Win/WclBleMainThread.cs @@ -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) diff --git a/Assets/Scripts/Devices/MainDeviceAdapter.cs b/Assets/Scripts/Devices/MainDeviceAdapter.cs index fc256c4f..625cbd32 100644 --- a/Assets/Scripts/Devices/MainDeviceAdapter.cs +++ b/Assets/Scripts/Devices/MainDeviceAdapter.cs @@ -46,7 +46,7 @@ namespace Assets.Scripts.Devices var adapter = adapters.FirstOrDefault(a => a.Interface == connectionInterface); if(adapter != null) { - Debug.Log("bbbbbb " + (adapter.GetState().ToString())); + //Debug.Log("bbbbbb " + (adapter.GetState().ToString())); return adapter.GetState(); } return DeviceAdapterState.Unavailable; diff --git a/Assets/Scripts/UI/Prefab/Device/ConnectDeviceModal.cs b/Assets/Scripts/UI/Prefab/Device/ConnectDeviceModal.cs index 1175eb8d..77b822cf 100644 --- a/Assets/Scripts/UI/Prefab/Device/ConnectDeviceModal.cs +++ b/Assets/Scripts/UI/Prefab/Device/ConnectDeviceModal.cs @@ -41,7 +41,7 @@ public class ConnectDeviceModal : PFUIPanel private UnityEngine.Object deviceItem; private VerticalLayoutGroup content; private PfUIButton connectBtn; - private Dictionary deviceList; + private Dictionary deviceList; private Text noDevice,Title; private RectTransform searchIconRect; @@ -49,7 +49,7 @@ public class ConnectDeviceModal : PFUIPanel { base.Awake(); - deviceList = new Dictionary(); + deviceList = new Dictionary(); var container = this.transform.Find("GameObject"); var closeBtn = container.Find("CloseBtn"); @@ -64,7 +64,7 @@ public class ConnectDeviceModal : PFUIPanel _x = searchIconRect.localPosition.x; _y = searchIconRect.localPosition.y; - base.SetRounded(panel.GetComponent().transform, 20f); + base.SetRounded(panel.GetComponent().transform, 20f); UIManager.AddEvent(closeBtn.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction(e => { @@ -82,7 +82,16 @@ public class ConnectDeviceModal : PFUIPanel { 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(); 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(); - if(dd != null) + if (dd != null) { dd.DeviceInfo.Connect(); DeviceCache.Add(dd.DeviceInfo); @@ -98,7 +107,7 @@ public class ConnectDeviceModal : PFUIPanel this.Close(); })); - + } // Start is called before the first frame update @@ -131,6 +140,7 @@ public class ConnectDeviceModal : PFUIPanel //var a = AntConnector.Instance().discoveredDevices; switch (SensorType) { + case SensorType.SpeedCadence: case SensorType.Cadence: devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is ICadenceDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList(); break; @@ -140,9 +150,7 @@ public class ConnectDeviceModal : PFUIPanel case SensorType.Power: devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is IPowerDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList(); break; - case SensorType.Speed: - break; - case SensorType.SpeedCadence: + case SensorType.Speed: devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is ISpeedDevice && d.State == DeviceState.Connected)).OrderBy(d => d.Priority).ToList(); break; case SensorType.Trainer: @@ -154,7 +162,7 @@ public class ConnectDeviceModal : PFUIPanel foreach (var device in devices) { - if (deviceList.ContainsKey(device.DeviceNumber)) + if (deviceList.ContainsKey(device.Id)) { continue; } @@ -170,7 +178,7 @@ public class ConnectDeviceModal : PFUIPanel deviceItemObj.Set(true); foreach (var item in deviceList) { - if (item.Key != deviceItemObj.DeviceInfo.DeviceNumber) + if (item.Key != deviceItemObj.DeviceInfo.Id) { 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)) @@ -199,6 +207,12 @@ public class ConnectDeviceModal : PFUIPanel //connectBtn.text.text = "DISCOUNECT"; 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) + //} } } } diff --git a/Assets/Scripts/UI/Prefab/Device/DeviceItem.cs b/Assets/Scripts/UI/Prefab/Device/DeviceItem.cs index db9ee92f..6b66c8c8 100644 --- a/Assets/Scripts/UI/Prefab/Device/DeviceItem.cs +++ b/Assets/Scripts/UI/Prefab/Device/DeviceItem.cs @@ -73,7 +73,7 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler public override void OnDeselect(BaseEventData eventData) { //base.OnDeselect(eventData); - Debug.Log("deselect"); + //Debug.Log("deselect"); //DeviceInfo.Disconnect(); diff --git a/Assets/Scripts/UI/Prefab/Device/DeviceView.cs b/Assets/Scripts/UI/Prefab/Device/DeviceView.cs index 8af5e55f..3f9e6d91 100644 --- a/Assets/Scripts/UI/Prefab/Device/DeviceView.cs +++ b/Assets/Scripts/UI/Prefab/Device/DeviceView.cs @@ -158,7 +158,7 @@ public class DeviceView : MonoBehaviour powerUnit.text = "W"; } - else if (SensorType == SensorType.SpeedCadence) + else if (SensorType == SensorType.Speed) { sprite0 = Resources.Load("Images/Devices/Speed_0"); sprite1 = Resources.Load("Images/Devices/Speed_1"); @@ -166,7 +166,7 @@ public class DeviceView : MonoBehaviour powerUnit.text = "KPH"; } - else if (SensorType == SensorType.Cadence) + else if (SensorType == SensorType.Cadence || SensorType == SensorType.SpeedCadence) { sprite0 = Resources.Load("Images/Devices/Cadence_0"); sprite1 = Resources.Load("Images/Devices/Cadence_1"); @@ -289,15 +289,14 @@ public class DeviceView : MonoBehaviour { case SensorType.None: break; + case SensorType.SpeedCadence: case SensorType.Cadence: return "Cadence Sensor"; case SensorType.HeartRate: return "Heart Rate Monitor"; case SensorType.Power: return "Power Meter"; - case SensorType.Speed: - break; - case SensorType.SpeedCadence: + case SensorType.Speed: return "Speed Meter"; case SensorType.Trainer: return "Smart Trainer"; @@ -316,6 +315,7 @@ public class DeviceView : MonoBehaviour { case SensorType.None: break; + case SensorType.SpeedCadence: case SensorType.Cadence: //cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString(); return (connectedDevice as ICadenceDevice).Cadence.ToString(); @@ -324,8 +324,6 @@ public class DeviceView : MonoBehaviour case SensorType.Power: return (connectedDevice as IPowerDevice).Power.ToString(); case SensorType.Speed: - break; - case SensorType.SpeedCadence: return (connectedDevice as ISpeedDevice).Speed.ToString(); case SensorType.Trainer: //powerValue.text = (connectedDevice as IPowerDevice).Power.ToString(); @@ -357,6 +355,7 @@ public class DeviceView : MonoBehaviour { case SensorType.None: break; + case SensorType.SpeedCadence: case SensorType.Cadence: return devices.FirstOrDefault(d => d is ICadenceDevice); case SensorType.HeartRate: @@ -369,7 +368,6 @@ public class DeviceView : MonoBehaviour //} return item; case SensorType.Speed: - case SensorType.SpeedCadence: return devices.FirstOrDefault(d => d is ISpeedDevice); case SensorType.Trainer: var item3 = devices.FirstOrDefault(d => d.Sensor == SensorType.Trainer);