设备连接稳定性

This commit is contained in:
lishuo 2022-06-08 13:05:56 +08:00 committed by CaiYanPeng
parent c333086e30
commit 46b6c7fa01
9 changed files with 111 additions and 62 deletions

View File

@ -24,6 +24,7 @@ public class BluetoothDeviceScript : MonoBehaviour
public Action<string, byte[]> PeripheralReceivedWriteDataAction; public Action<string, byte[]> PeripheralReceivedWriteDataAction;
public Action<string> ConnectedPeripheralAction; public Action<string> ConnectedPeripheralAction;
public Action<string> ConnectedDisconnectPeripheralAction { get; set; } public Action<string> ConnectedDisconnectPeripheralAction { get; set; }
public Action<string,string> ConnectErrorAction { get; set; }
public Action<string> DisconnectedPeripheralAction; public Action<string> DisconnectedPeripheralAction;
public Action<string> DeviceBleStatusDisconnectedAction; public Action<string> DeviceBleStatusDisconnectedAction;
public Action<string, string> DiscoveredServiceAction; public Action<string, string> DiscoveredServiceAction;
@ -53,10 +54,11 @@ public class BluetoothDeviceScript : MonoBehaviour
void Update () void Update ()
{ {
} }
const string connectionError = "ConnectionError";
const string deviceInitializedString = "Initialized"; const string deviceInitializedString = "Initialized";
const string deviceDeInitializedString = "DeInitialized"; const string deviceDeInitializedString = "DeInitialized";
const string deviceErrorString = "Error"; const string deviceErrorString = "Error";
const string deviceConnectErrorString = "ConnectionError";
const string deviceServiceAdded = "ServiceAdded"; const string deviceServiceAdded = "ServiceAdded";
const string deviceStartedAdvertising = "StartedAdvertising"; const string deviceStartedAdvertising = "StartedAdvertising";
const string deviceStoppedAdvertising = "StoppedAdvertising"; const string deviceStoppedAdvertising = "StoppedAdvertising";
@ -77,6 +79,7 @@ public class BluetoothDeviceScript : MonoBehaviour
public void OnBluetoothMessage (string message) public void OnBluetoothMessage (string message)
{ {
Debug.Log(message);
if (message != null) if (message != null)
{ {
char[] delim = new char[] { '~' }; char[] delim = new char[] { '~' };
@ -242,6 +245,10 @@ public class BluetoothDeviceScript : MonoBehaviour
DisconnectedPeripheralAction(parts[1]); DisconnectedPeripheralAction(parts[1]);
} }
} }
else if (message.Length > connectionError.Length && message.Substring(0,connectionError.Length) == connectionError){
if (ConnectErrorAction != null)
ConnectErrorAction(parts[1], parts[2]);
}
else if (message.Length >= deviceDiscoveredService.Length && message.Substring (0, deviceDiscoveredService.Length) == deviceDiscoveredService) else if (message.Length >= deviceDiscoveredService.Length && message.Substring (0, deviceDiscoveredService.Length) == deviceDiscoveredService)
{ {
if (parts.Length >= 3 && DiscoveredServiceAction != null) if (parts.Length >= 3 && DiscoveredServiceAction != null)

View File

@ -604,7 +604,7 @@ public class BluetoothLEHardwareInterface
#endif #endif
} }
public static void ConnectToPeripheral (string name, Action<string> connectAction, Action<string, string> serviceAction, Action<string, string, string> characteristicAction, Action<string> disconnectAction = null) public static void ConnectToPeripheral (string name, Action<string> connectAction, Action<string, string> serviceAction, Action<string, string, string> characteristicAction, Action<string> disconnectAction = null, Action<string,string> errorAction = null)
{ {
#if !UNITY_EDITOR_OSX || !EXPERIMENTAL_MACOS_EDITOR #if !UNITY_EDITOR_OSX || !EXPERIMENTAL_MACOS_EDITOR
@ -618,6 +618,7 @@ public class BluetoothLEHardwareInterface
bluetoothDeviceScript.DiscoveredCharacteristicAction = characteristicAction; bluetoothDeviceScript.DiscoveredCharacteristicAction = characteristicAction;
bluetoothDeviceScript.ConnectedDisconnectPeripheralAction = disconnectAction; bluetoothDeviceScript.ConnectedDisconnectPeripheralAction = disconnectAction;
bluetoothDeviceScript.DeviceBleStatusDisconnectedAction = disconnectAction; bluetoothDeviceScript.DeviceBleStatusDisconnectedAction = disconnectAction;
bluetoothDeviceScript.ConnectErrorAction = errorAction;
} }
#if EXPERIMENTAL_MACOS_EDITOR && (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX) #if EXPERIMENTAL_MACOS_EDITOR && (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)

View File

@ -711,7 +711,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &3643721405153075690 --- !u!224 &3643721405153075690
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -826,7 +826,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &3643721405012091660 --- !u!224 &3643721405012091660
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1436,7 +1436,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &8230995990077916237 --- !u!224 &8230995990077916237
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1739,7 +1739,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &2290133527418080840 --- !u!224 &2290133527418080840
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -106,6 +106,7 @@ namespace Assets.Scripts.Devices.Ble
if (response.Error != null) if (response.Error != null)
{ {
this.State = DeviceState.Disconnected;
if (response.Error.Code == WclBleErrors.WCL_E_BLUETOOTH_LE_DEVICE_NOT_FOUND) if (response.Error.Code == WclBleErrors.WCL_E_BLUETOOTH_LE_DEVICE_NOT_FOUND)
{ {
Debug.Log("未找到设备"); Debug.Log("未找到设备");

View File

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers;
using UnityEngine; using UnityEngine;
namespace Assets.Scripts.Ble namespace Assets.Scripts.Ble
@ -210,30 +211,41 @@ namespace Assets.Scripts.Ble
List<BleServiceInfo> servicelist = new List<BleServiceInfo>(); List<BleServiceInfo> servicelist = new List<BleServiceInfo>();
List<BleCharacteristicInfo> characteristilist = new List<BleCharacteristicInfo>(); List<BleCharacteristicInfo> characteristilist = new List<BleCharacteristicInfo>();
public void ConnectPeripheral(BlePeripheralInfo info, Action<IBleWinHwInterface, BlePeripheralInfo, BleResponse> callback) public void ConnectPeripheral(BlePeripheralInfo info, Action<IBleWinHwInterface, BlePeripheralInfo, BleResponse> callback)
{ {
if (!this.callbacks.ContainsKey(info)) var exsit = this.callbacks.Where(c => c.Key.Address == info.Address).Any();
if (!exsit)
{ {
this.callbacks.Add(info, callback); this.callbacks.Add(info, callback);
} }
else
{
var obj = this.callbacks.Where(c => c.Key.Address == info.Address).FirstOrDefault();
this.callbacks.Remove(obj.Key);
this.callbacks.Add(info, callback);
}
Debug.Log("try connect device" + info.Name + this.callbacks.Count.ToString()); Debug.Log("try connect device" + info.Name + this.callbacks.Count.ToString());
var self = this;
if (this.callbacks.Count == 1) if (this.callbacks.Count == 1)
{ {
BleResponse s = new BleResponse();
s.IsSuccess = true;
s.Error = null;
var self = this;
BluetoothLEHardwareInterface.ConnectToPeripheral(info.Address, (address) => BluetoothLEHardwareInterface.ConnectToPeripheral(info.Address, (address) =>
{ {
BleResponse s = new BleResponse
{
IsSuccess = true,
Error = null
};
callback?.Invoke(self, info, s); callback?.Invoke(self, info, s);
this.callbacks.Remove(info); this.callbacks.Remove(info);
Debug.Log("连接成功!"+info.Name); Debug.Log("连接成功!" + info.Name);
if (this.callbacks.Any()) if (this.callbacks.Any())
{ {
this.ConnectPeripheral(this.callbacks.First().Key, this.callbacks.First().Value); this.ConnectPeripheral(this.callbacks.First().Key, this.callbacks.First().Value);
} }
}, (address, service) => }, (address, service) =>
{ {
Debug.Log("发现服务");
ServicesDiscovered(address, service); ServicesDiscovered(address, service);
}, (address, service, characteristic) => }, (address, service, characteristic) =>
{ {
@ -242,9 +254,25 @@ namespace Assets.Scripts.Ble
{ {
Debug.Log("disconnect device:" + address); Debug.Log("disconnect device:" + address);
PeripheralDisconnected(address, info); PeripheralDisconnected(address, info);
}); },
(address, error) =>
{
BleResponse s = new BleResponse
{
IsSuccess = false,
Error = new BleHwInterfaceError(error)
};
callback?.Invoke(self, info, s);
this.callbacks.Remove(info);
if (this.callbacks.Any())
{
this.ConnectPeripheral(this.callbacks.First().Key, this.callbacks.First().Value);
}
}
);
} }
} }
#region #region
//服务发现 //服务发现
private void ServicesDiscovered(string address, string service) private void ServicesDiscovered(string address, string service)
@ -305,7 +333,7 @@ namespace Assets.Scripts.Ble
} }
var characteristicsDiscoveredCallback = characteristicsDiscoveredCallbacks.Where(c => c.Key.MatchAddress(address)); var characteristicsDiscoveredCallback = characteristicsDiscoveredCallbacks.Where(c => c.Key.MatchAddress(address));
if (serviceCallback.Any()) if (characteristicsDiscoveredCallback.Any())
{ {
characteristicsDiscoveredCallbacks.Remove(characteristicsDiscoveredCallback.First().Key); characteristicsDiscoveredCallbacks.Remove(characteristicsDiscoveredCallback.First().Key);
} }

View File

@ -267,7 +267,7 @@ public class ConnectDeviceModal : PFUIPanel
} }
} }
noDevice.text = deviceItemObj.DeviceInfo.Name + "-"+ deviceItemObj.DeviceInfo.DeviceNumber; noDevice.text = deviceItemObj.DeviceInfo.Name;
if (deviceItemObj.DeviceInfo.State == DeviceState.Connected) if (deviceItemObj.DeviceInfo.State == DeviceState.Connected)
{ {
noDevice.color = Color.white; noDevice.color = Color.white;

View File

@ -22,7 +22,7 @@ using static RowerTaskPanel;
public class RowerHomeScript : PFUIPanel public class RowerHomeScript : PFUIPanel
{ {
private class TempRowerCalc private class TempRowerCalc
{ {
public int power { get; set; } public int power { get; set; }
public ushort pace { get; set; } public ushort pace { get; set; }
@ -52,7 +52,7 @@ public class RowerHomeScript : PFUIPanel
protected override void OnDestroy() protected override void OnDestroy()
{ {
Debug.Log("銷毀"); Debug.Log("銷毀");
if (RowerData != null) if (RowerData != null)
{ {
RowerData.PullChanged -= PaintPullCurve; RowerData.PullChanged -= PaintPullCurve;
RowerData.StartEvent -= StartFunc; RowerData.StartEvent -= StartFunc;
@ -60,11 +60,11 @@ public class RowerHomeScript : PFUIPanel
} }
C2RowerData.EnableChanged -= ModeChanged; C2RowerData.EnableChanged -= ModeChanged;
} }
private IRowerDevice Rower private IRowerDevice Rower
{ {
get get
{ {
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower); var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => d.State == DeviceState.Connected && d.Sensor == SensorType.Rower);
if (device != null) if (device != null)
{ {
return (IRowerDevice)device; return (IRowerDevice)device;
@ -75,9 +75,9 @@ public class RowerHomeScript : PFUIPanel
/// <summary> /// <summary>
/// 心率数据 /// 心率数据
/// </summary> /// </summary>
private int? HeartRate private int? HeartRate
{ {
get get
{ {
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.HeartRate); var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.HeartRate);
if (device != null) if (device != null)
@ -88,12 +88,12 @@ public class RowerHomeScript : PFUIPanel
} }
} }
GameObject btnStart; GameObject btnStart;
Transform left, bottom, mid,rmydata; Transform left, bottom, mid, rmydata;
Image leftImage; Image leftImage;
Image rightImage; Image rightImage;
float timer = 1.0f; float timer = 1.0f;
List<DoubleVector2> pullList, historyPullList; List<DoubleVector2> pullList, historyPullList;
public Dictionary<object, Sprite> spriteDict,spriteDict2; public Dictionary<object, Sprite> spriteDict, spriteDict2;
List<string> records; List<string> records;
List<TempRowerCalc> values; List<TempRowerCalc> values;
DateTime startTime; DateTime startTime;
@ -127,7 +127,7 @@ public class RowerHomeScript : PFUIPanel
{ {
Id = Guid.NewGuid().ToString(); Id = Guid.NewGuid().ToString();
rowerType = new RowerType() { type = 1, value = 500 }; rowerType = new RowerType() { type = 1, value = 500 };
spriteDict = new Dictionary<object, Sprite>() spriteDict = new Dictionary<object, Sprite>()
{ {
{"Start",Resources.Load<Sprite>("Images/RowerNew/ICON_continue_44") }, {"Start",Resources.Load<Sprite>("Images/RowerNew/ICON_continue_44") },
@ -201,19 +201,19 @@ public class RowerHomeScript : PFUIPanel
UIManager.AddEvent(transform.Find("ResBar/BtnAdd").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => UIManager.AddEvent(transform.Find("ResBar/BtnAdd").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{ {
if (RowerData != null) if (RowerData != null)
{ {
slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel + 1 - 50) / 300f); slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel + 1 - 50) / 300f);
} }
}); });
UIManager.AddEvent(transform.Find("ResBar/BtnSub").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => UIManager.AddEvent(transform.Find("ResBar/BtnSub").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{ {
if (RowerData != null) if (RowerData != null)
{ {
slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel - 1 - 50) / 300f); slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel - 1 - 50) / 300f);
} }
}); });
slider.GetComponent<PFUISlider>().valueHandler = (a) => 50 + a * 300; slider.GetComponent<PFUISlider>().valueHandler = (a) => 50 + a * 300;
slider.GetComponent<PFUISlider>().SetValueChanged(r => slider.GetComponent<PFUISlider>().SetValueChanged(r =>
@ -240,12 +240,12 @@ public class RowerHomeScript : PFUIPanel
}); });
UIManager.AddEvent(transform.Find("Stopped/DeviceStatus").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => UIManager.AddEvent(transform.Find("Stopped/DeviceStatus").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{ {
if (checkRowing()) return; //if (checkRowing()) return;
UIManager.ShowRowerDevicePanel(); UIManager.ShowRowerDevicePanel();
}); });
UIManager.AddEvent(transform.Find("Stopped/DeviceStatusConnect").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => UIManager.AddEvent(transform.Find("Stopped/DeviceStatusConnect").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{ {
if (checkRowing()) return; //if (checkRowing()) return;
UIManager.ShowRowerDevicePanel(); UIManager.ShowRowerDevicePanel();
}); });
//手机版tab //手机版tab
@ -260,13 +260,13 @@ public class RowerHomeScript : PFUIPanel
//return; //return;
if (checkRowing()) return; if (checkRowing()) return;
if (C2RowerData.IsEnabled == true && C2RowerData.rowerType != null) return; if (C2RowerData.IsEnabled == true && C2RowerData.rowerType != null) return;
UIManager.ShowRowerTaskPanel(type=> UIManager.ShowRowerTaskPanel(type =>
{ {
rowerType = type; rowerType = type;
HandleSelectType(); HandleSelectType();
},rowerType); }, rowerType);
}, false); }, false);
var c2 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/记录"), () => var c2 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/记录"), () =>
{ {
if (checkRowing()) return; if (checkRowing()) return;
UIManager.ShowResultListPanel(); UIManager.ShowResultListPanel();
@ -289,7 +289,7 @@ public class RowerHomeScript : PFUIPanel
{ {
Discard(); Discard();
}); });
if (RowerData != null) if (RowerData != null)
{ {
RowerData.PullChanged -= PaintPullCurve; RowerData.PullChanged -= PaintPullCurve;
RowerData.PullChanged += PaintPullCurve; RowerData.PullChanged += PaintPullCurve;
@ -306,9 +306,9 @@ public class RowerHomeScript : PFUIPanel
public void ReRow(RowerResultModel r) public void ReRow(RowerResultModel r)
{ {
this.reRowData = r; this.reRowData = r;
if (r!= null && r.Type.HasValue) if (r != null && r.Type.HasValue)
{ {
rowerType = new RowerType { type = r.Type.Value,value = (float)r.TypeValue.Value }; rowerType = new RowerType { type = r.Type.Value, value = (float)r.TypeValue.Value };
if (Rower != null) if (Rower != null)
{ {
Rower.Reset(); Rower.Reset();
@ -320,15 +320,15 @@ public class RowerHomeScript : PFUIPanel
if (rowerType.type == 0) if (rowerType.type == 0)
{ {
dw = $"\nM/ 30Min"; dw = $"\nM/ 30Min";
} }
else if (rowerType.type == 2) else if (rowerType.type == 2)
{ {
dw = $"\nM"; dw = $"\nM";
} }
bottom.Find("Expected/Title").GetComponent<Text>().text = $"{App.GetLocalString("EST")}{dw}"; bottom.Find("Expected/Title").GetComponent<Text>().text = $"{App.GetLocalString("EST")}{dw}";
} }
} }
private void DeleteCacheDir() private void DeleteCacheDir()
{ {
//删除实时记录 //删除实时记录
try try
@ -340,12 +340,12 @@ public class RowerHomeScript : PFUIPanel
//Directory.Delete(dir, true); //Directory.Delete(dir, true);
} }
} }
catch (Exception e) catch (Exception e)
{ {
Debug.LogError(e.ToString()); Debug.LogError(e.ToString());
} }
} }
private void Discard() private void Discard()
{ {
openTimer = false; openTimer = false;
if (Application.internetReachability == NetworkReachability.NotReachable) if (Application.internetReachability == NetworkReachability.NotReachable)
@ -392,12 +392,17 @@ public class RowerHomeScript : PFUIPanel
//Utils.showToast(null, "请滑动划船机并开始", isLowest: true, type: 1); //Utils.showToast(null, "请滑动划船机并开始", isLowest: true, type: 1);
} }
protected override void OnDisable()
{
base.OnDisable();
//App.MainDeviceAdapter.StopScan();
}
public override void Show() public override void Show()
{ {
base.Show(); base.Show();
//var mainNav = this.transform.Find("MainNav").GetComponent<MainNav>(); //var mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
//mainNav.ShowRowerTab(); //mainNav.ShowRowerTab();
//App.MainDeviceAdapter.StartScan();
transform.MyDOFade(); transform.MyDOFade();
//Debug.Log("140,开始扫描"); //Debug.Log("140,开始扫描");
//App.MainDeviceAdapter.StartScan(); //App.MainDeviceAdapter.StartScan();
@ -405,18 +410,18 @@ public class RowerHomeScript : PFUIPanel
CheckLocalData(); CheckLocalData();
//transform.Find("Left/Rower").GetComponent<RowerAnimation>().StartAnimation(); //transform.Find("Left/Rower").GetComponent<RowerAnimation>().StartAnimation();
} }
void Disconnect() void Disconnect()
{ {
foreach(var d in App.MainDeviceAdapter.GetDevices()) foreach (var d in App.MainDeviceAdapter.GetDevices())
{ {
if ((d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && (d.Sensor == SensorType.Rower || d.Sensor == SensorType.HeartRate)) if ((d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && (d.Sensor == SensorType.Rower || d.Sensor == SensorType.HeartRate))
{ {
d.Disconnect(); d.Disconnect();
} }
} }
App.MainDeviceAdapter.StopScan(); App.MainDeviceAdapter.StopScan();
} }
void HandleDiscardDirect() void HandleDiscardDirect()
{ {
openTimer = false; openTimer = false;
isPause = true; isPause = true;
@ -425,7 +430,7 @@ public class RowerHomeScript : PFUIPanel
btnStart.tag = "Start"; btnStart.tag = "Start";
Init(); Init();
} }
void HandleSaveDirect() void HandleSaveDirect()
{ {
openTimer = false; openTimer = false;
isPause = true; isPause = true;
@ -440,7 +445,7 @@ public class RowerHomeScript : PFUIPanel
{ {
if (Save()) Init(); if (Save()) Init();
} }
else else
{ {
if (SaveFunc(tempRecordData.model, tempRecordData.files)) Init(); if (SaveFunc(tempRecordData.model, tempRecordData.files)) Init();
} }
@ -450,7 +455,7 @@ public class RowerHomeScript : PFUIPanel
{ {
Utils.showToast(null, "Press \"Menu\" to save.", int.MaxValue, stopFunc: () => C2RowerData.isReadyStatus, endCallback: f); Utils.showToast(null, "Press \"Menu\" to save.", int.MaxValue, stopFunc: () => C2RowerData.isReadyStatus, endCallback: f);
} }
else else
{ {
f.Invoke(); f.Invoke();
} }
@ -459,15 +464,15 @@ public class RowerHomeScript : PFUIPanel
int truelyTime = 0; int truelyTime = 0;
private void StartFunc(object sender, EventArgs e) private void StartFunc(object sender, EventArgs e)
{ {
if (UIManager.Instance.confirm!=null && UIManager.Instance.confirm.IsActive()) if (UIManager.Instance.confirm != null && UIManager.Instance.confirm.IsActive())
{ {
print("当前有弹窗"); print("当前有弹窗");
return; return;
} }
if (openTimer) return; if (openTimer) return;
Id = Guid.NewGuid().ToString(); Id = Guid.NewGuid().ToString();
if (transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)") && transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)").gameObject.activeInHierarchy) if (transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)") && transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)").gameObject.activeInHierarchy)
{ {
return; return;
} }
@ -479,7 +484,7 @@ public class RowerHomeScript : PFUIPanel
} }
if (!isPause) if (!isPause)
{ {
} }
if (!openTimer) if (!openTimer)
{ {
@ -498,9 +503,9 @@ public class RowerHomeScript : PFUIPanel
btnStart.GetComponent<Image>().sprite = spriteDict["Untagged"]; btnStart.GetComponent<Image>().sprite = spriteDict["Untagged"];
btnStart.tag = "Untagged"; btnStart.tag = "Untagged";
} }
private bool SaveFunc(RowerRecordModel model, List<string> files) private bool SaveFunc(RowerRecordModel model, List<string> files)
{ {
if (Application.internetReachability == NetworkReachability.NotReachable) if (Application.internetReachability == NetworkReachability.NotReachable)
{ {
transform.Find("Stopped").gameObject.SetActive(true); transform.Find("Stopped").gameObject.SetActive(true);
Utils.showToast(null, App.GetLocalString("Please check the network status!")); Utils.showToast(null, App.GetLocalString("Please check the network status!"));
@ -531,11 +536,11 @@ public class RowerHomeScript : PFUIPanel
tempRecordData = null; tempRecordData = null;
return true; return true;
} }
public class TempRecordData public class TempRecordData
{ {
public RowerRecordModel model; public RowerRecordModel model;
public List<string> files; public List<string> files;
public TempRecordData(RowerRecordModel model, List<string> files) public TempRecordData(RowerRecordModel model, List<string> files)
{ {
this.model = model; this.model = model;
this.files = files; this.files = files;
@ -547,15 +552,21 @@ public class RowerHomeScript : PFUIPanel
RowerRecordModel model = new RowerRecordModel(); RowerRecordModel model = new RowerRecordModel();
model.Ticks = records.Count; model.Ticks = records.Count;
var bleDevice = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower) as BleDevice; var bleDevice = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower) as BleDevice;
if (bleDevice != null) if (bleDevice != null)
{ {
model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor; model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor;
model.DeviceNumber = $"{ bleDevice.Address },{ bleDevice.Sensor }"; model.DeviceNumber = $"{ bleDevice.Address },{ bleDevice.Sensor }";
} }
model.Id = Id;//Guid.NewGuid().ToString(); model.Id = Id;//Guid.NewGuid().ToString();
model.Weight = App.CurrentUser.Weight; model.Weight = App.CurrentUser.Weight;
if (string.IsNullOrEmpty(shadowids))
model.StartTime = createTime.Value.AddSeconds(-values.Count); {
model.StartTime = startTime;
}
else
{
model.StartTime = createTime.Value.AddSeconds(-values.Count);
}
model.CreateTime = createTime.Value; model.CreateTime = createTime.Value;
Debug.Log(values.Count); Debug.Log(values.Count);
if (values.Count > 0) if (values.Count > 0)
@ -786,7 +797,7 @@ public class RowerHomeScript : PFUIPanel
#if !UNITY_EDITOR #if !UNITY_EDITOR
if (Rower == null) if (Rower == null)
{ {
HandleDiscardDirect(); //HandleDiscardDirect();
return; return;
} }
if (RowerData == null) return; if (RowerData == null) return;
@ -1251,7 +1262,7 @@ public class RowerHomeScript : PFUIPanel
//graph.DataSource.AddPointToCategoryRealtime("Player 2", item.x, item.y); //graph.DataSource.AddPointToCategoryRealtime("Player 2", item.x, item.y);
if (M1.localPosition.x == 0) if (M1.localPosition.x == 0)
{ {
rowerGraphChartFeed.SetData(v1, v2); rowerGraphChartFeed.SetData(v1, v2);
} }
else else
{ {

View File

@ -10,6 +10,7 @@ public class RowerDevicePanel : PFUIPanel
{ {
UIManager.AddEvent(transform.Find("Container/Tools/Back").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => UIManager.AddEvent(transform.Find("Container/Tools/Back").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{ {
App.MainDeviceAdapter.StopScan();
Close(); Close();
}); });
} }