From 06b9051b3cc072a63c794bcd634a7bf445d6516b Mon Sep 17 00:00:00 2001 From: lishuo Date: Fri, 24 Jun 2022 18:03:36 +0800 Subject: [PATCH] =?UTF-8?q?c2=E5=90=8C=E6=AD=A5=E8=AF=BE=E7=A8=8B=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Devices/Ble/Characteristic/C2RowerData.cs | 6 +++--- .../Scripts/Devices/Ble/Devices/FtmsRower.cs | 13 +++++++++--- .../Devices/Ble/mobile/BleMobileInterface.cs | 6 ++++-- .../UI/Prefab/Activity/ActivityController.cs | 17 ++++++++------- .../UI/Prefab/Panel/RowerHomeScript.cs | 21 ++++++++++++++----- Assets/UniWebView/Script/UniWebView.cs | 2 ++ 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs b/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs index 9d7103f4..a9dbde56 100644 --- a/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs +++ b/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs @@ -70,7 +70,6 @@ namespace Assets.Scripts.Devices.Ble.Characteristic ElapsedTime = (int)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 1)) / 100); TotalDistance = (uint)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 4)) / 10); StrokeCount = BitConvertHelper.ToUInt16(data, 19); - Debug.Log("数据" + string.Join(",", data) +$" | {ElapsedTime}-{TotalDistance}"); } else if (data[0] == 0x3d) { @@ -140,10 +139,11 @@ namespace Assets.Scripts.Devices.Ble.Characteristic } else if (data[0] == 0x39) { - ElapsedTime = (int)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 1)) / 100); - TotalDistance = (uint)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 4)) / 10); + ElapsedTime = (int)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 5)) / 100); + TotalDistance = (uint)(Convert.ToDouble(BitConvertHelper.ToUInt24(data, 8)) / 10); CompleteEvent?.Invoke(this, null); } + Debug.Log("数据" + string.Join(",", data) + $" | {ElapsedTime}-{TotalDistance}"); //else if (data[0] == 34) //{ // isReadyStatus = data[2] == 1 || data[2] == 129; diff --git a/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs b/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs index 2bebb7af..f655bfbd 100644 --- a/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs +++ b/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs @@ -229,11 +229,13 @@ namespace Assets.Scripts.Devices.Ble.Devices checkSum = GetChecksumHexString(data); data = BitConvertHelper.HexToByteArray($"F1 76 03 01 01 {typeHex} {checkSum} F2"); hwInterface.WriteCharacteristic(this.c2Control, data); + Thread.Sleep(5); } public void SetConfigureWorkout() { var data = BitConvertHelper.HexToByteArray("F1 76 03 14 01 01 61 F2"); //03? hwInterface.WriteCharacteristic(this.c2Control, data); + Thread.Sleep(5); } public void SetScreenState() { @@ -250,6 +252,7 @@ namespace Assets.Scripts.Devices.Ble.Devices var data = BitConvertHelper.HexToByteArray("F1 76 07 01 01 01 13 02 01 01 61 F2"); Debug.Log($"SetJustRow:{string.Join(",", data)}"); hwInterface.WriteCharacteristic(this.c2Control, data); + Thread.Sleep(5); SetScreenState(); } public void SetFixedDistance(int distance) @@ -258,16 +261,19 @@ namespace Assets.Scripts.Devices.Ble.Devices return; SetWorkoutType(3); + var hexditance = distance.ToString("X4"); var checkSum = "00"; var data = BitConvertHelper.HexToByteArray($"F1 76 07 03 05 80 00 00 {hexditance} {checkSum} F2");//F1 76 07 03 05 80 00 00 {hexditance} {checkSum} F2 checkSum = GetChecksumHexString(data); data = BitConvertHelper.HexToByteArray($"F1 76 07 03 05 80 00 00 {hexditance} {checkSum} F2");//07? hwInterface.WriteCharacteristic(this.c2Control, data); + Thread.Sleep(5); SetConfigureWorkout(); + SetScreenState(); - + } private string GetChecksumHexString(byte[] data) { @@ -281,15 +287,16 @@ namespace Assets.Scripts.Devices.Ble.Devices public void SetFixedTime(int mins) { SetWorkoutType(5); - + Thread.Sleep(5); var timeHex = (mins * 100).ToString("X6"); var checkNum = "00"; var data = BitConvertHelper.HexToByteArray($"F1 76 07 03 05 00 00 {timeHex} {checkNum} F2"); checkNum = GetChecksumHexString(data); data = BitConvertHelper.HexToByteArray($"F1 76 07 03 05 00 00 {timeHex} {checkNum} F2"); hwInterface.WriteCharacteristic(this.c2Control, data); - + Thread.Sleep(5); SetConfigureWorkout(); + Thread.Sleep(5); SetScreenState(); } diff --git a/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs b/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs index e3af36f0..9c68d7c5 100644 --- a/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs +++ b/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Timers; using UnityEngine; @@ -413,10 +414,11 @@ namespace Assets.Scripts.Ble { this.characteristicNotificationCallbacks.Add(characteristic.Peripheral, callback); } - Debug.Log("SubscribeCharacteristic" + characteristic.Peripheral.Name + characteristic.Service.ToString() + characteristic.Service.ToString()); + Thread.Sleep(50); + Debug.Log("SubscribeCharacteristic" + characteristic.Peripheral.Name + characteristic.Service.ToString() + characteristic.Id.ToString()); BluetoothLEHardwareInterface.SubscribeCharacteristicWithDeviceAddress(characteristic.Peripheral.Address, characteristic.Service.ToString(), characteristic.Id.ToString(), (a,b)=> { - Debug.Log("返回特征值," + a + "," + b); + Debug.Log("返回特征值," + a + "," + b+DateTime.Now.ToString()); }, (deviceAddress, characteristric, bytes) => { if (characteristicReadEvent != null) diff --git a/Assets/Scripts/UI/Prefab/Activity/ActivityController.cs b/Assets/Scripts/UI/Prefab/Activity/ActivityController.cs index f815d0b7..79812d29 100644 --- a/Assets/Scripts/UI/Prefab/Activity/ActivityController.cs +++ b/Assets/Scripts/UI/Prefab/Activity/ActivityController.cs @@ -98,14 +98,15 @@ public class ActivityController : PFUIPanel webView.SetUserAgent($"UniWebView {Application.platform} {Application.version}"); webView.BackgroundColor = Utils.HexToColorHtml("#23232d"); //webView.CleanCache(); - if (action == null) - { - webView.Load(url); - } - else - { - action.Invoke(); - } + webView.Load(url); + //if (action == null) + //{ + // webView.Load(url); + //} + //else + //{ + // action.Invoke(); + //} // Show it. webView.Show(); webView.OnMessageReceived -= FromJs; diff --git a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs index 5c51a796..9ab58820 100644 --- a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs +++ b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs @@ -508,7 +508,7 @@ public class RowerHomeScript : PFUIPanel if (rowdata != RowerData) return; - Debug.Log($"开始了:{openTimer}"); + Debug.Log($"开始了:{openTimer}-{DateTime.Now}"); if (UIManager.Instance.confirm != null && UIManager.Instance.confirm.IsActive()) { print("当前有弹窗"); @@ -561,9 +561,19 @@ public class RowerHomeScript : PFUIPanel var power = RowerData.InstantaneousPower; var rate = RowerData.StrokeRate; - KMText.text = "0"; - records.Add($"{strokeCount},{RowerData.ElapsedTime},{rowerType.value},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{RowerData.ElapsedTime}"); - var tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = RowerData.InstantaneousPace, power = power, rate = rate, heartRate = heartRate, distance = (int)rowerType.value, energy = energy }; + if (rowerType.type == 1) + { + TimeText.text = $"{RowerData.ElapsedTime}"; + KMText.text = "0"; + } + else + { + TimeText.text = TimeSpan.FromSeconds(0).ToPFString(); + KMText.text = $"{RowerData.TotalDistance}"; + } + + records.Add($"{strokeCount},{RowerData.ElapsedTime},{RowerData.TotalDistance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{RowerData.ElapsedTime}"); + var tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = RowerData.InstantaneousPace, power = power, rate = rate, heartRate = heartRate, distance = (int)RowerData.TotalDistance, energy = energy }; values.Add(tmpdata); SendDataToRace(tmpdata); HandleSaveDirect(); @@ -920,7 +930,7 @@ public class RowerHomeScript : PFUIPanel TempRowerCalc tmpdata = null; //解决C2里程训练无法结束的问题 - var c2notStop = C2RowerData.IsEnabled && rowerType.type == 1 && (rowerType.value-totalDistance) <= 5; + var c2notStop = C2RowerData.IsEnabled && rowerType!=null && rowerType.type !=0 && (rowerType.value-totalDistance) <= 5; //里程停止逻辑 if (totalDistance == RowerData.TotalDistance && !c2notStop) { @@ -934,6 +944,7 @@ public class RowerHomeScript : PFUIPanel } if (stopSeconds >= 2) { + Debug.Log($"stopSeconds:{RowerData.TotalDistance}"); if (UIManager.Instance.confirm != null && UIManager.Instance.confirm.IsActive()) { Debug.Log("stopSeconds >= 2"); transform.Find("Stopped").gameObject.SetActive(false); diff --git a/Assets/UniWebView/Script/UniWebView.cs b/Assets/UniWebView/Script/UniWebView.cs index cac0490d..2e43cd52 100644 --- a/Assets/UniWebView/Script/UniWebView.cs +++ b/Assets/UniWebView/Script/UniWebView.cs @@ -294,6 +294,8 @@ public class UniWebView: MonoBehaviour { /// public void UpdateFrame() { Rect rect = NextFrameRect(); + if (listener == null) + return; UniWebViewInterface.SetFrame(listener.Name, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); }