2021-04-01 09:33:19 +08:00
|
|
|
|
using Assets.Scripts.Devices.Ant;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
using Assets.Scripts.Devices.Ant.Interfaces;
|
2021-04-14 15:02:33 +08:00
|
|
|
|
using Assets.Scripts.UI.UIEffect;
|
|
|
|
|
|
using Assets.Scripts;
|
2021-04-23 09:22:12 +08:00
|
|
|
|
using DG.Tweening;
|
2021-04-30 18:03:34 +08:00
|
|
|
|
using Assets.Scripts.UI.Prefab.Device;
|
2021-05-19 14:38:48 +08:00
|
|
|
|
using Assets.Scripts.Devices;
|
2021-04-01 09:33:19 +08:00
|
|
|
|
|
|
|
|
|
|
public class DeviceView : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[SerializeField]
|
2021-04-14 15:02:33 +08:00
|
|
|
|
private SensorType mType;
|
2021-04-01 09:33:19 +08:00
|
|
|
|
|
|
|
|
|
|
private SensorType SensorType
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
//Debug.Log(mType);
|
2021-04-14 15:02:33 +08:00
|
|
|
|
//Enum.TryParse(mType, out SensorType sensorType);
|
|
|
|
|
|
return mType;
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private GameObject mSearchButton;
|
|
|
|
|
|
private GameObject mPairButton;
|
|
|
|
|
|
private GameObject mDisconnectButton;
|
|
|
|
|
|
private GameObject unconnectionPanel;
|
|
|
|
|
|
private GameObject connectionPanel;
|
|
|
|
|
|
private Text searchState;
|
|
|
|
|
|
private ConnectDeviceModal deviceModal;
|
|
|
|
|
|
private Text title;
|
|
|
|
|
|
private Text noDevice;
|
|
|
|
|
|
private Text powerValue;
|
2021-04-23 09:22:12 +08:00
|
|
|
|
private Text powerUnit;
|
2021-04-14 15:02:33 +08:00
|
|
|
|
//private Text cadenceValue;
|
|
|
|
|
|
//private Text speedValue;
|
|
|
|
|
|
//private Text heartRateValue;
|
2021-04-01 09:33:19 +08:00
|
|
|
|
private Image logo;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 没有设备的logo
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Sprite sprite0;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 连接中的logo
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Sprite sprite1;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 已连接的logo
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Sprite sprite3;
|
|
|
|
|
|
|
|
|
|
|
|
private float timer = 1.0f;
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
title = this.transform.Find("Title").GetComponent<Text>();
|
|
|
|
|
|
noDevice = this.transform.Find("NoDevice").GetComponent<Text>();
|
|
|
|
|
|
unconnectionPanel = this.transform.Find("UnconnectionPanel").gameObject;
|
|
|
|
|
|
mSearchButton = unconnectionPanel.transform.Find("SearchButton").gameObject;
|
|
|
|
|
|
mPairButton = unconnectionPanel.transform.Find("PairButton").gameObject;
|
|
|
|
|
|
searchState = unconnectionPanel.transform.Find("SearchState").GetComponent<Text>();
|
|
|
|
|
|
mPairButton.SetActive(false);
|
2021-04-14 15:02:33 +08:00
|
|
|
|
connectionPanel = this.transform.Find("ConnectionPanel").gameObject;
|
|
|
|
|
|
|
|
|
|
|
|
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
|
|
|
|
|
var rect = ((RectTransform)transform).rect;
|
|
|
|
|
|
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height * 0.2f, 0));
|
2021-04-29 18:10:09 +08:00
|
|
|
|
this.GetComponent<Image>().material = material;
|
|
|
|
|
|
|
2021-04-14 15:02:33 +08:00
|
|
|
|
var img1 = unconnectionPanel.GetComponent<Image>();
|
|
|
|
|
|
if(img1 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
img1.material = material;
|
2021-04-01 09:33:19 +08:00
|
|
|
|
|
2021-04-29 18:10:09 +08:00
|
|
|
|
//var gradient = unconnectionPanel.GetComponent<UIGradient>();
|
|
|
|
|
|
//if (gradient != null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// gradient.color1 = Utils.HexToColor("353543");
|
|
|
|
|
|
// gradient.color2 = Utils.HexToColor("23232D");
|
|
|
|
|
|
//}
|
2021-04-23 09:22:12 +08:00
|
|
|
|
}
|
2021-04-14 15:02:33 +08:00
|
|
|
|
|
|
|
|
|
|
var img2 = connectionPanel.GetComponent<Image>();
|
|
|
|
|
|
if(img2 != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
img2.material = material;
|
|
|
|
|
|
|
2021-04-29 18:10:09 +08:00
|
|
|
|
//var gradient1 = connectionPanel.GetComponent<UIGradient>();
|
|
|
|
|
|
//if (gradient1 != null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// gradient1.color1 = Utils.HexToColor("FF7485");
|
|
|
|
|
|
// gradient1.color2 = Utils.HexToColor("F93086");
|
|
|
|
|
|
//}
|
2021-04-14 15:02:33 +08:00
|
|
|
|
}
|
2021-04-01 09:33:19 +08:00
|
|
|
|
|
|
|
|
|
|
logo = this.transform.Find("Logo").GetComponent<Image>();
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
2021-04-14 15:02:33 +08:00
|
|
|
|
|
2021-04-01 09:33:19 +08:00
|
|
|
|
mDisconnectButton = connectionPanel.transform.Find("DisconnectBtn").gameObject;
|
|
|
|
|
|
var powerValueObj = connectionPanel.transform.Find("PowerValue");
|
|
|
|
|
|
if(powerValueObj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
powerValue = powerValueObj.gameObject.GetComponent<Text>();
|
|
|
|
|
|
}
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
|
|
|
|
|
var powerUnitObj = connectionPanel.transform.Find("PowerUnit");
|
|
|
|
|
|
if(powerUnitObj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
powerUnit = powerUnitObj.gameObject.GetComponent<Text>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InitLogo();
|
2021-06-10 19:11:14 +08:00
|
|
|
|
title.text = GetTitle();
|
2021-04-01 09:33:19 +08:00
|
|
|
|
|
|
|
|
|
|
connectionPanel.SetActive(false);
|
|
|
|
|
|
|
|
|
|
|
|
UIManager.AddEvent(mPairButton, EventTriggerType.PointerClick, new UnityAction<UnityEngine.EventSystems.BaseEventData>(e =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (deviceModal == null)
|
|
|
|
|
|
{
|
2021-08-31 16:27:36 +08:00
|
|
|
|
|
|
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
|
|
|
|
var obj = Resources.Load("UI/Prefab/Device/Mobile/ConnectDeviceModal");
|
|
|
|
|
|
#else
|
2021-04-01 09:33:19 +08:00
|
|
|
|
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
|
2021-08-31 16:27:36 +08:00
|
|
|
|
#endif
|
2021-04-01 09:33:19 +08:00
|
|
|
|
GameObject gameObject = (GameObject)Instantiate(obj);
|
|
|
|
|
|
deviceModal = gameObject.GetComponent<ConnectDeviceModal>();
|
|
|
|
|
|
}
|
|
|
|
|
|
deviceModal.SensorType = this.SensorType;
|
|
|
|
|
|
UIManager.Show(deviceModal, null, true);
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
UIManager.AddEvent(mDisconnectButton, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e => {
|
|
|
|
|
|
//var device = GetDevice();
|
|
|
|
|
|
//if(device != null && device.State == DeviceState.Connected)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// device.Disconnect();
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
2021-08-31 16:27:36 +08:00
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
|
|
|
|
var obj = Resources.Load("UI/Prefab/Device/Mobile/ConnectDeviceModal");
|
|
|
|
|
|
#else
|
2021-04-01 09:33:19 +08:00
|
|
|
|
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
|
2021-08-31 16:27:36 +08:00
|
|
|
|
#endif
|
2021-04-01 09:33:19 +08:00
|
|
|
|
GameObject gameObject = (GameObject)Instantiate(obj);
|
|
|
|
|
|
deviceModal = gameObject.GetComponent<ConnectDeviceModal>();
|
|
|
|
|
|
deviceModal.SensorType = this.SensorType;
|
|
|
|
|
|
UIManager.Show(deviceModal, null, true);
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitLogo()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SensorType == SensorType.Power)
|
|
|
|
|
|
{
|
|
|
|
|
|
sprite0 = Resources.Load<Sprite>("Images/Devices/Power_0");
|
|
|
|
|
|
sprite1 = Resources.Load<Sprite>("Images/Devices/Power_1");
|
2021-04-29 18:10:09 +08:00
|
|
|
|
sprite3 = Resources.Load<Sprite>("Images/Devices/Power_4");
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
|
|
|
|
|
powerUnit.text = "W";
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
2021-06-04 18:28:11 +08:00
|
|
|
|
else if (SensorType == SensorType.Speed)
|
2021-04-01 09:33:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_0");
|
|
|
|
|
|
sprite1 = Resources.Load<Sprite>("Images/Devices/Speed_1");
|
2021-04-29 18:10:09 +08:00
|
|
|
|
sprite3 = Resources.Load<Sprite>("Images/Devices/Speed_4");
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
|
|
|
|
|
powerUnit.text = "KPH";
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
2021-06-04 18:28:11 +08:00
|
|
|
|
else if (SensorType == SensorType.Cadence || SensorType == SensorType.SpeedCadence)
|
2021-04-01 09:33:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_0");
|
|
|
|
|
|
sprite1 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
|
2021-04-29 18:10:09 +08:00
|
|
|
|
sprite3 = Resources.Load<Sprite>("Images/Devices/Cadence_4");
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
|
|
|
|
|
powerUnit.text = "RPM";
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (SensorType == SensorType.HeartRate)
|
|
|
|
|
|
{
|
|
|
|
|
|
sprite0 = Resources.Load<Sprite>("Images/Devices/Heart Rate_0");
|
|
|
|
|
|
sprite1 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
|
2021-04-29 18:10:09 +08:00
|
|
|
|
sprite3 = Resources.Load<Sprite>("Images/Devices/Heart Rate_4");
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
|
|
|
|
|
powerUnit.text = "BPM";
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
2021-04-23 09:22:12 +08:00
|
|
|
|
else if(SensorType == SensorType.Trainer)
|
2021-04-01 09:33:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
sprite0 = Resources.Load<Sprite>("Images/Devices/Trainer_0");
|
|
|
|
|
|
sprite1 = Resources.Load<Sprite>("Images/Devices/Trainer_1");
|
2021-04-29 18:10:09 +08:00
|
|
|
|
sprite3 = Resources.Load<Sprite>("Images/Devices/Trainer_4");
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
Main();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
2021-06-08 10:30:26 +08:00
|
|
|
|
//if(SensorType != SensorType.Trainer)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//}
|
2021-04-01 09:33:19 +08:00
|
|
|
|
timer -= Time.deltaTime;
|
|
|
|
|
|
if (timer <= 0)
|
2021-06-08 10:30:26 +08:00
|
|
|
|
{
|
2021-04-01 09:33:19 +08:00
|
|
|
|
Main();
|
|
|
|
|
|
|
|
|
|
|
|
timer = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Main()
|
|
|
|
|
|
{
|
|
|
|
|
|
var connectedDevice = GetCurrentDevice();
|
|
|
|
|
|
if(connectedDevice == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
connectedDevice = GetDevice();
|
|
|
|
|
|
}
|
|
|
|
|
|
if(connectedDevice == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
unconnectionPanel.SetActive(true);
|
|
|
|
|
|
connectionPanel.SetActive(false);
|
|
|
|
|
|
|
|
|
|
|
|
logo.sprite = sprite0;
|
|
|
|
|
|
noDevice.text = "NO DEVICE";
|
2021-06-10 19:11:14 +08:00
|
|
|
|
searchState.text = "Searching...";
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
2021-05-19 14:38:48 +08:00
|
|
|
|
var hasDevice = App.MainDeviceAdapter.GetDevices().Any(d => d.Sensor == SensorType);
|
2021-04-01 09:33:19 +08:00
|
|
|
|
if (hasDevice)
|
|
|
|
|
|
{
|
|
|
|
|
|
mSearchButton.SetActive(false);
|
|
|
|
|
|
mPairButton.SetActive(true);
|
2021-08-31 16:27:36 +08:00
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
2021-09-15 14:17:11 +08:00
|
|
|
|
//searchState.gameObject.SetActive(false);
|
2021-08-31 16:27:36 +08:00
|
|
|
|
#endif
|
2021-04-01 09:33:19 +08:00
|
|
|
|
logo.sprite = sprite1;
|
2021-06-08 10:30:26 +08:00
|
|
|
|
|
|
|
|
|
|
//App.MainDeviceAdapter.GetDevices().First(d => d.Sensor == SensorType).Connect();
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-08-31 16:27:36 +08:00
|
|
|
|
#if !(UNITY_IOS || UNITY_ANDROID)
|
2021-04-01 09:33:19 +08:00
|
|
|
|
mSearchButton.SetActive(true);
|
2021-08-31 16:27:36 +08:00
|
|
|
|
#endif
|
2021-04-01 09:33:19 +08:00
|
|
|
|
mPairButton.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(connectedDevice.State == DeviceState.Connecting)
|
|
|
|
|
|
{
|
|
|
|
|
|
unconnectionPanel.SetActive(true);
|
|
|
|
|
|
connectionPanel.SetActive(false);
|
|
|
|
|
|
logo.sprite = sprite1;
|
|
|
|
|
|
|
2021-06-10 17:46:43 +08:00
|
|
|
|
//title.text = connectedDevice.Name;
|
2021-06-09 11:27:11 +08:00
|
|
|
|
if (connectedDevice.Network == NetworkType.BLE)
|
|
|
|
|
|
{
|
2021-06-10 17:46:43 +08:00
|
|
|
|
//noDevice.enabled = false;
|
|
|
|
|
|
noDevice.text = connectedDevice.Name;
|
2021-06-09 11:27:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-06-10 17:46:43 +08:00
|
|
|
|
//noDevice.enabled = true;
|
|
|
|
|
|
noDevice.text = connectedDevice.Name +" "+ connectedDevice.DeviceNumber.ToString();
|
2021-06-09 11:27:11 +08:00
|
|
|
|
}
|
2021-09-15 14:17:11 +08:00
|
|
|
|
#if (UNITY_IOS || UNITY_ANDROID)
|
|
|
|
|
|
mPairButton.SetActive(true);
|
|
|
|
|
|
searchState.gameObject.SetActive(true);
|
|
|
|
|
|
#endif
|
2021-04-01 09:33:19 +08:00
|
|
|
|
searchState.text = "Connecting...";
|
2021-06-09 11:27:11 +08:00
|
|
|
|
|
2021-09-15 14:17:11 +08:00
|
|
|
|
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (connectedDevice.State == DeviceState.Connected)
|
|
|
|
|
|
{
|
|
|
|
|
|
unconnectionPanel.SetActive(false);
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
|
|
|
|
|
if (connectionPanel.activeInHierarchy == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
var connectionCanvasGroup = connectionPanel.GetComponent<CanvasGroup>();
|
|
|
|
|
|
connectionCanvasGroup.alpha = 0;
|
|
|
|
|
|
connectionPanel.SetActive(true);
|
2021-04-29 18:10:09 +08:00
|
|
|
|
connectionCanvasGroup.DOFade(1f, .3f).OnComplete(()=> {
|
|
|
|
|
|
//if (logoSprite != null) {
|
|
|
|
|
|
// logo.sprite = logoSprite;
|
|
|
|
|
|
//}
|
|
|
|
|
|
});
|
2021-04-30 18:03:34 +08:00
|
|
|
|
DeviceCache.Add(connectedDevice);
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log("connected");
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-23 09:22:12 +08:00
|
|
|
|
}
|
2021-04-30 18:03:34 +08:00
|
|
|
|
|
2021-04-01 09:33:19 +08:00
|
|
|
|
logo.sprite = sprite3;
|
|
|
|
|
|
|
2021-06-10 17:46:43 +08:00
|
|
|
|
//title.text = connectedDevice.Name;
|
2021-06-09 18:16:35 +08:00
|
|
|
|
if (connectedDevice.Network == NetworkType.BLE)
|
|
|
|
|
|
{
|
2021-06-10 17:46:43 +08:00
|
|
|
|
//noDevice.enabled = false;
|
|
|
|
|
|
noDevice.text = connectedDevice.Name;
|
2021-06-09 18:16:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-06-10 17:46:43 +08:00
|
|
|
|
//noDevice.enabled = true;
|
|
|
|
|
|
noDevice.text = connectedDevice.Name +" "+ connectedDevice.DeviceNumber.ToString();
|
2021-06-09 18:16:35 +08:00
|
|
|
|
}
|
2021-04-01 09:33:19 +08:00
|
|
|
|
noDevice.color = Color.white;
|
2021-04-23 09:22:12 +08:00
|
|
|
|
|
|
|
|
|
|
if (powerValue != null)
|
2021-04-01 09:33:19 +08:00
|
|
|
|
{
|
2021-04-23 09:22:12 +08:00
|
|
|
|
powerValue.text = GetValue(connectedDevice);
|
2021-04-30 18:03:34 +08:00
|
|
|
|
}
|
2021-06-08 10:30:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Debug.Log(Newtonsoft.Json.JsonConvert.SerializeObject(App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType)));
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-23 09:22:12 +08:00
|
|
|
|
string GetTitle()
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (SensorType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SensorType.None:
|
|
|
|
|
|
break;
|
2021-06-04 18:28:11 +08:00
|
|
|
|
case SensorType.SpeedCadence:
|
2021-04-23 09:22:12 +08:00
|
|
|
|
case SensorType.Cadence:
|
|
|
|
|
|
return "Cadence Sensor";
|
|
|
|
|
|
case SensorType.HeartRate:
|
|
|
|
|
|
return "Heart Rate Monitor";
|
|
|
|
|
|
case SensorType.Power:
|
|
|
|
|
|
return "Power Meter";
|
2021-06-04 18:28:11 +08:00
|
|
|
|
case SensorType.Speed:
|
2021-04-23 09:22:12 +08:00
|
|
|
|
return "Speed Meter";
|
|
|
|
|
|
case SensorType.Trainer:
|
|
|
|
|
|
return "Smart Trainer";
|
|
|
|
|
|
case SensorType.VirtualPower:
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-19 14:38:48 +08:00
|
|
|
|
string GetValue(AbstractDevice connectedDevice)
|
2021-04-23 09:22:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
switch (SensorType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SensorType.None:
|
|
|
|
|
|
break;
|
2021-06-04 18:28:11 +08:00
|
|
|
|
case SensorType.SpeedCadence:
|
2021-04-23 09:22:12 +08:00
|
|
|
|
case SensorType.Cadence:
|
|
|
|
|
|
//cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
|
|
|
|
|
return (connectedDevice as ICadenceDevice).Cadence.ToString();
|
|
|
|
|
|
case SensorType.HeartRate:
|
|
|
|
|
|
return (connectedDevice as IHeartRateDevice).HeartRate.ToString();
|
|
|
|
|
|
case SensorType.Power:
|
|
|
|
|
|
return (connectedDevice as IPowerDevice).Power.ToString();
|
|
|
|
|
|
case SensorType.Speed:
|
|
|
|
|
|
return (connectedDevice as ISpeedDevice).Speed.ToString();
|
|
|
|
|
|
case SensorType.Trainer:
|
|
|
|
|
|
//powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
|
|
|
|
|
|
//cadenceValue.GetComponent<Text>().text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
|
|
|
|
|
//speedValue.GetComponent<Text>().text = (connectedDevice as ISpeedDevice).Speed.ToString();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SensorType.VirtualPower:
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2021-05-19 14:38:48 +08:00
|
|
|
|
AbstractDevice GetCurrentDevice()
|
2021-04-01 09:33:19 +08:00
|
|
|
|
{
|
2021-05-19 14:38:48 +08:00
|
|
|
|
//return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
|
|
|
|
|
return App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
2021-04-01 09:33:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取已经连接的设备
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2021-05-19 14:38:48 +08:00
|
|
|
|
AbstractDevice GetDevice()
|
2021-04-01 09:33:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
//return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
2021-05-19 14:38:48 +08:00
|
|
|
|
var devices = App.MainDeviceAdapter.GetDevices().Where(d => (d.State == DeviceState.Connected));
|
2021-04-01 09:33:19 +08:00
|
|
|
|
switch (SensorType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SensorType.None:
|
|
|
|
|
|
break;
|
2021-06-04 18:28:11 +08:00
|
|
|
|
case SensorType.SpeedCadence:
|
2021-04-01 09:33:19 +08:00
|
|
|
|
case SensorType.Cadence:
|
|
|
|
|
|
return devices.FirstOrDefault(d => d is ICadenceDevice);
|
|
|
|
|
|
case SensorType.HeartRate:
|
|
|
|
|
|
return devices.FirstOrDefault(d => d is IHeartRateDevice);
|
|
|
|
|
|
case SensorType.Power:
|
|
|
|
|
|
var item = devices.FirstOrDefault(d => d is IPowerDevice);
|
|
|
|
|
|
//if (powerValue != null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// powerValue.GetComponent<Text>().text = (item as IPowerDevice).Power.ToString();
|
|
|
|
|
|
//}
|
|
|
|
|
|
return item;
|
|
|
|
|
|
case SensorType.Speed:
|
|
|
|
|
|
return devices.FirstOrDefault(d => d is ISpeedDevice);
|
|
|
|
|
|
case SensorType.Trainer:
|
|
|
|
|
|
var item3 = devices.FirstOrDefault(d => d.Sensor == SensorType.Trainer);
|
|
|
|
|
|
return item3;
|
|
|
|
|
|
case SensorType.VirtualPower:
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|