From 06aefb93c4a8e7513f21f7892fdee7788d0bf451 Mon Sep 17 00:00:00 2001 From: CaiYanPeng Date: Wed, 30 Mar 2022 18:25:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DC2=E5=88=92=E8=88=B9=E6=9C=BA?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=92=8Cmenu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Devices/Ant/Interfaces/IRowerDevice.cs | 1 + .../Devices/Ble/Characteristic/C2RowerData.cs | 36 +++- .../Scripts/Devices/Ble/Devices/FtmsRower.cs | 39 ++++- .../Scripts/Devices/Ble/Win/ServiceUuids.cs | 4 +- .../UI/Prefab/Panel/RowerHomeScript.cs | 156 ++++++++++-------- Assets/Scripts/Utils/Utils.cs | 3 +- 6 files changed, 162 insertions(+), 77 deletions(-) diff --git a/Assets/Scripts/Devices/Ant/Interfaces/IRowerDevice.cs b/Assets/Scripts/Devices/Ant/Interfaces/IRowerDevice.cs index a8966108..1c645131 100644 --- a/Assets/Scripts/Devices/Ant/Interfaces/IRowerDevice.cs +++ b/Assets/Scripts/Devices/Ant/Interfaces/IRowerDevice.cs @@ -13,5 +13,6 @@ namespace Assets.Scripts.Devices.Ant.Interfaces FtmsRowerData rowerData { get; } void Reset(); void SetResistanceLevel(ushort v); + void C2GetStatus(); } } diff --git a/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs b/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs index 72059a6c..6ea57ecd 100644 --- a/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs +++ b/Assets/Scripts/Devices/Ble/Characteristic/C2RowerData.cs @@ -50,6 +50,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic } } } + + public static bool isReadyStatus { get; private set; } + public static RowerTaskPanel.RowerType rowerType { get; private set; } public void HandleAttributeReceived(byte[] data) { Debug.Log("数据" + string.Join(",", data)); @@ -59,7 +62,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic AverageDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 15)) / 10); Debug.Log($"峰力值:{PeakDriveForce} 均力值{AverageDriveForce}"); } - else if (data[0] == 61) + else if (data[0] == 61) { List r = new List(); for (int i = 3; i < data.Length; i += 2) @@ -68,9 +71,36 @@ namespace Assets.Scripts.Devices.Ble.Characteristic r.Add(pull); PullValue = pull; } - - Debug.Log("拉力曲线:"+ string.Join(",",r)); + + Debug.Log("拉力曲线:" + string.Join(",", r)); } + else if (data[0] == 49) + { + byte status = data[18]; + int value = (data[17] << 16) + (data[16] << 8) + data[15]; + if (status == 128 && value != 0) + { + rowerType = new RowerTaskPanel.RowerType(); + rowerType.type = 1; + rowerType.value = value; + } + else if (status == 0) + { + rowerType = new RowerTaskPanel.RowerType(); + rowerType.type = 2; + rowerType.value = value / 100; + } + else + { + rowerType = null; + } + isReadyStatus = data[9] == 0; + //isReadyStatus = data[2] == 1 || data[2] == 129; + } + //else if (data[0] == 34) + //{ + // isReadyStatus = data[2] == 1 || data[2] == 129; + //} } private double LbsToNewton(double lbs) => 4.4482216 * lbs; public void SetUnavailable() diff --git a/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs b/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs index 7601b7c8..0bfcd814 100644 --- a/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs +++ b/Assets/Scripts/Devices/Ble/Devices/FtmsRower.cs @@ -23,7 +23,7 @@ namespace Assets.Scripts.Devices.Ble.Devices private BleCharacteristicInfo controlPointCharacteristic; private BleCharacteristicInfo c2Control; - public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) :base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower) + public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) : base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower) { Debug.Log(24); base.Characteristics.Add(new FtmsFitnessMachineFeature()); @@ -44,7 +44,7 @@ namespace Assets.Scripts.Devices.Ble.Devices { hwInterface.DiscoverCharacteristic(service, (hwInterface, service1, response) => { - + foreach (var character in response.Data) { //Debug.Log(character.Id.ToString()); @@ -70,13 +70,19 @@ namespace Assets.Scripts.Devices.Ble.Devices //C2RowerData.IsEnabled = true; this.hwInterface.SubscribeCharacteristic(character, null); } - else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerStatus)) + //else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerStatus)) + //{ + // Debug.Log("c2划船机响应数据" + service.Id); + // //C2RowerData.IsEnabled = true; + // this.hwInterface.SubscribeCharacteristic(character, null); + //} + else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerCourse)) { - Debug.Log("c2划船机响应数据" + service.Id); + Debug.Log("c2划船机课程数据" + service.Id); //C2RowerData.IsEnabled = true; this.hwInterface.SubscribeCharacteristic(character, null); } - else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerControl)) + else if (character.MatchGuid(ServiceUuids.Characteristics.C2RowerControl)) { Debug.Log("c2划船机控制台"); this.c2Control = character; @@ -97,7 +103,7 @@ namespace Assets.Scripts.Devices.Ble.Devices var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.RowerData); c.HandleAttributeReceived(response.Data); } - else + else { var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.C2RowerData); var data = new byte[] { characteristic.Id.ToByteArray()[0] }.Concat(response.Data).ToArray(); @@ -121,6 +127,27 @@ namespace Assets.Scripts.Devices.Ble.Devices // } //} } + public void C2GetStatus() + { + if (C2RowerData.IsEnabled == true) + { + //等对csafe协议研究透彻后写 + //if (this.c2Control != null) + //{ + + // var cmd = new byte[] { 0x80, 0xe8 }; + // byte a = cmd[0]; + // for (int i = 1; i < cmd.Length; i++) + // { + // a ^= cmd[i]; + // } + // cmd = new byte[] { 0xf1 }.Concat(cmd).Concat(new byte[] { a, 0xf2 }).ToArray(); + // Debug.Log("发送获取命令" + string.Join(",", cmd)); + // hwInterface.WriteCharacteristic(this.c2Control, cmd); + // //hwInterface.WriteCharacteristic(this.c2Control, new byte[] { 0xF1, 0x81, 0x81, 0xF2 }); + //} + } + } public void Reset() { diff --git a/Assets/Scripts/Devices/Ble/Win/ServiceUuids.cs b/Assets/Scripts/Devices/Ble/Win/ServiceUuids.cs index 2b353288..69e68161 100644 --- a/Assets/Scripts/Devices/Ble/Win/ServiceUuids.cs +++ b/Assets/Scripts/Devices/Ble/Win/ServiceUuids.cs @@ -375,7 +375,9 @@ namespace Assets.Scripts.Ble //拉力曲线 public static Guid C2RowerData1 = new Guid("ce06003D-43e5-11e4-916c-0800200c9a66"); //c2划船机状态 - public static Guid C2RowerStatus = new Guid("ce06003D-43e5-11e4-916c-0800200c9a66"); + public static Guid C2RowerStatus = new Guid("ce060022-43e5-11e4-916c-0800200c9a66"); + //c2划船机课程 + public static Guid C2RowerCourse = new Guid("CE060031-43E5-11E4-916C-0800200C9A66"); public static Guid C2Service = new Guid("CE060030-43E5-11E4-916C-0800200C9A66"); //ce060030-43e5-11e4-916c-0800200c9a66 } diff --git a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs index 986e91c4..a6c8688e 100644 --- a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs +++ b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs @@ -186,6 +186,7 @@ public class RowerHomeScript : PFUIPanel //UIManager.ShowRowerWelldone("81A85D49-ACAA-C764-101A-02555E6AC81A"); //return; if (checkRowing()) return; + if (C2RowerData.IsEnabled == true && C2RowerData.rowerType != null) return; UIManager.ShowRowerTaskPanel(type=> { rowerType = type; @@ -212,7 +213,17 @@ public class RowerHomeScript : PFUIPanel UIManager.AddEvent(transform.Find("Stopped/Confirm/BtnDrop").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => { transform.Find("Stopped").gameObject.SetActive(false); - Init(); + openTimer = false; + isPause = true; + if (C2RowerData.IsEnabled == true) + { + Utils.showToast(null, "Please press Menu to save.",int.MaxValue, stopFunc: () => C2RowerData.isReadyStatus, endCallback: Init); + } + else + { + Init(); + } + }); Init(); } @@ -271,8 +282,20 @@ public class RowerHomeScript : PFUIPanel btnStart.GetComponent().sprite = spriteDict["Start"]; btnStart.tag = "Start"; transform.Find("Stopped").gameObject.SetActive(false); - Save(); - Init(); + //Utils.showToast() + Action f = () => + { + Save(); + Init(); + }; + if (C2RowerData.IsEnabled == true) + { + Utils.showToast(null, "Please press Menu to save.",int.MaxValue, stopFunc: () => C2RowerData.isReadyStatus, endCallback: f); + } + else + { + f.Invoke(); + } } private IRowerCommonData RowerCommonDataInstance => Rower != null ? (C2RowerData.IsEnabled == true ? (IRowerCommonData)Rower.c2RowerData : (IRowerCommonData)Rower.rowerData) : null; private void HandleStartOrPause() @@ -462,7 +485,7 @@ public class RowerHomeScript : PFUIPanel if (rowerType.type == 1) { bottom.Find("Time/Value").GetComponent().text = "---"; - bottom.Find("KM/Value").GetComponent().text = $"{rowerType.value}M"; + bottom.Find("KM/Value").GetComponent().text = $"{rowerType.value}"; } else { @@ -511,14 +534,18 @@ public class RowerHomeScript : PFUIPanel private void ResChanged(object sender, EventArgs e) { print("收到阻力" + sender); - slider.GetComponent().SetValue((Convert.ToSingle(sender) - 50) / 300f); + if ((Convert.ToSingle(sender) > 50)) + { + slider.GetComponent().SetValue((Convert.ToSingle(sender) - 50) / 300f); + } + } public bool checkRowing() { if (seconds > 0) { - Utils.showToast(null, "Please end this training.", isLowest: true); + Utils.showToast(null, "Please end this training.", isLowest: true, isOnly: true); return true; } return false; @@ -627,43 +654,17 @@ public class RowerHomeScript : PFUIPanel totalDistance = (uint)distance; var pace = RowerData.InstantaneousPace; - if (rowerType.type == 2) - { - var remainTime = rowerType.value - (seconds++); - if (remainTime == 0) - { - records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}"); - tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy }; - values.Add(tmpdata); - SendDataToRace(tmpdata); - HandleSaveDirect(); - return; - } - bottom.Find("Time/Value").GetComponent().text = TimeSpan.FromSeconds(remainTime).ToPFString(); - } - else - { - bottom.Find("Time/Value").GetComponent().text = TimeSpan.FromSeconds(seconds++).ToPFString(); - } - if (rowerType.type == 1) - { - var remainDistance = rowerType.value - totalDistance; - if (remainDistance < 0) - { - records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}"); - tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy }; - values.Add(tmpdata); - SendDataToRace(tmpdata); - HandleSaveDirect(); - return; - } - bottom.Find("KM/Value").GetComponent().text = remainDistance.ToString(); - } - else - { - bottom.Find("KM/Value").GetComponent().text = totalDistance.ToString(); - } - if (pace != 0) + + + mid.Find("W/Value").GetComponent().text = power.ToString(); + bottom.Find("500/Value").GetComponent().text = TimeSpan.FromSeconds(pace).ToPFString(); + bottom.Find("MS/Value").GetComponent().text = rate.ToString(); + left.Find("Times/Value").GetComponent().text = strokeCount.ToString(); + left.Find("Calories/Value").GetComponent().text = energy.ToString(); + mid.Find("AvgForce/Value").GetComponent().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0"); + mid.Find("PeakForce/Value").GetComponent().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0"); + + if (pace != 0) { if (rowerType.type == 1) { @@ -694,28 +695,43 @@ public class RowerHomeScript : PFUIPanel bottom.Find("Expected/Value").GetComponent().text = $"{dis.ToString("#0")}"; } } - - //RowerPanel/Rower/Bottom/Expected/Value - - mid.Find("W/Value").GetComponent().text = power.ToString(); - //bottom.Find("W/AvgValue").GetComponent().text = RowerData.AveragePower.ToString(); - - bottom.Find("500/Value").GetComponent().text = TimeSpan.FromSeconds(pace).ToPFString(); - //bottom.Find("500/AvgValue").GetComponent().text = TimeSpan.FromSeconds(RowerData.AveragePace).ToString(@"mm\:ss"); - - bottom.Find("MS/Value").GetComponent().text = rate.ToString(); - //bottom.Find("MS/AvgValue").GetComponent().text = RowerData.AverageStrokeRate.ToString(); - //if (ushort.TryParse(left.Find("Times/Value").GetComponent().text, out ushort originStroke)) - //{ - // if (strokeCount != originStroke) - // { - // left.Find("Rower").GetComponent().StartAnimation(); - // } - //} - left.Find("Times/Value").GetComponent().text = strokeCount.ToString(); - left.Find("Calories/Value").GetComponent().text = energy.ToString(); - mid.Find("AvgForce/Value").GetComponent().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0"); - mid.Find("PeakForce/Value").GetComponent().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0"); + if (rowerType.type == 2) + { + var remainTime = rowerType.value - (seconds++); + bottom.Find("Time/Value").GetComponent().text = TimeSpan.FromSeconds(remainTime).ToPFString(); + if (remainTime == 0) + { + records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}"); + tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy }; + values.Add(tmpdata); + SendDataToRace(tmpdata); + HandleSaveDirect(); + return; + } + } + else + { + bottom.Find("Time/Value").GetComponent().text = TimeSpan.FromSeconds(seconds++).ToPFString(); + } + if (rowerType.type == 1) + { + var remainDistance = rowerType.value - totalDistance; + if (remainDistance < 0) + { + bottom.Find("KM/Value").GetComponent().text = "0"; + records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}"); + tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy }; + values.Add(tmpdata); + SendDataToRace(tmpdata); + HandleSaveDirect(); + return; + } + bottom.Find("KM/Value").GetComponent().text = remainDistance.ToString(); + } + else + { + bottom.Find("KM/Value").GetComponent().text = totalDistance.ToString(); + } records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}"); tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy }; values.Add(tmpdata); @@ -748,7 +764,7 @@ public class RowerHomeScript : PFUIPanel #if !UNITY_EDITOR if (!openTimer) { - if (y > 0) + if (y > 0 && !isPause) { //RowerCommonDataInstance.PullChanged -= PaintPullCurve; //RowerCommonDataInstance.PullChanged += PaintPullCurve; @@ -852,5 +868,13 @@ public class RowerHomeScript : PFUIPanel transform.Find("Ready/Text").gameObject.SetActive(flag); transform.Find("Ready/DeviceStatusConnect").gameObject.SetActive(flag); } + if (Rower != null) + { + if (C2RowerData.IsEnabled == true && !openTimer && !isPause && C2RowerData.rowerType!=null) + { + rowerType = C2RowerData.rowerType; + HandleSelectType(); + } + } } } diff --git a/Assets/Scripts/Utils/Utils.cs b/Assets/Scripts/Utils/Utils.cs index 4d22fb22..6dfbb721 100644 --- a/Assets/Scripts/Utils/Utils.cs +++ b/Assets/Scripts/Utils/Utils.cs @@ -176,7 +176,7 @@ namespace Assets.Scripts /// /// /// - public static void showToast(GameObject p, string text, int duration = 2, int type = 0, Func stopFunc = null, bool isLowest = false,bool showSeconds = false,Action endCallback = null,PFUIPanel _parent = null) + public static void showToast(GameObject p, string text, int duration = 2, int type = 0, Func stopFunc = null, bool isLowest = false,bool showSeconds = false,Action endCallback = null,PFUIPanel _parent = null,bool isOnly = false) { var parent = UIManager.Instance.ModalsPanel; if (parent == null) @@ -194,6 +194,7 @@ namespace Assets.Scripts var toast = parent.transform.Find("ToastContainer"); if (toast != null) { + if (isOnly) return; MonoBehaviour.DestroyImmediate(toast.gameObject); } #if UNITY_IOS || UNITY_ANDROID