心率,阻力逻辑调整

This commit is contained in:
lishuo 2022-06-14 18:37:58 +08:00
parent f25d0b7b8c
commit 0202814f67
5 changed files with 68 additions and 29 deletions

View File

@ -25,24 +25,25 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
/// </summary> /// </summary>
public int AverageStrokeRate { get; set; } = 0; public int AverageStrokeRate { get; set; } = 0;
//private UInt32 _totalDistance = 1; private UInt32 _totalDistance = 1;
public UInt32 TotalDistance { get; set; } = 1; public UInt32 TotalDistance
private UInt16 _instantaneousPace = 1;
/// <summary>
/// 即时配速
/// </summary>
public UInt16 InstantaneousPace
{ {
get => _instantaneousPace; get => _totalDistance;
set set
{ {
if (_instantaneousPace == 0 && value != 0 && StartEvent != null) if (_totalDistance == 0 && value != 0 && StartEvent != null)
{ {
StartEvent.Invoke(this, null); StartEvent.Invoke(this, null);
} }
_instantaneousPace = value; _totalDistance = value;
} }
} }
//private UInt16 _instantaneousPace = 1;
/// <summary>
/// 即时配速
/// </summary>
public UInt16 InstantaneousPace { get; set; } = 0;
/// <summary> /// <summary>
/// 平均配速 /// 平均配速
/// </summary> /// </summary>

View File

@ -1,5 +1,6 @@
using Assets.Scripts.Ble; using Assets.Scripts.Ble;
using System.Timers; using System.Timers;
using UnityEngine;
namespace Assets.Scripts.Devices.Ble namespace Assets.Scripts.Devices.Ble
{ {
@ -35,7 +36,7 @@ namespace Assets.Scripts.Devices.Ble
this.managerStatusChanged -= value; this.managerStatusChanged -= value;
} }
} }
WclBleManagerStatus statusEnum = WclBleManagerStatus.RadioOff; WclBleManagerStatus statusEnum = WclBleManagerStatus.RadioOn;
internal BleMobileThread() { internal BleMobileThread() {
Initialize();//初始蓝牙 Initialize();//初始蓝牙
} }
@ -44,7 +45,8 @@ namespace Assets.Scripts.Devices.Ble
var self = this; var self = this;
if (statusEnum == WclBleManagerStatus.RadioOff) if (statusEnum == WclBleManagerStatus.RadioOff)
{ {
Initialize(); //Initialize();
BluetoothLEHardwareInterface.BluetoothEnable(true);
} }
else else
{ {
@ -56,6 +58,7 @@ namespace Assets.Scripts.Devices.Ble
} }
public void Initialize() public void Initialize()
{ {
Debug.Log("Initialize");
var self = this; var self = this;
BluetoothLEHardwareInterface.BluetoothEnable(true); BluetoothLEHardwareInterface.BluetoothEnable(true);
BluetoothLEHardwareInterface.Initialize(true, false, () => BluetoothLEHardwareInterface.Initialize(true, false, () =>

View File

@ -37,23 +37,39 @@ public class PFUISlider : MonoBehaviour
public bool runCallback = false; public bool runCallback = false;
public void SetValueChanged(System.Action<float> a) public void SetValueChanged(System.Action<float> a)
{ {
this.ValueChangedHandler = a;
slider = transform.GetComponent<Slider>(); slider = transform.GetComponent<Slider>();
slider.onValueChanged.RemoveAllListeners(); slider.onValueChanged.RemoveAllListeners();
UIManager.AddEvent(slider.gameObject, EventTriggerType.EndDrag, (e) =>
{
OnValueChanged();
});
slider.onValueChanged.AddListener((f) => slider.onValueChanged.AddListener((f) =>
{ {
var step = 1f / (colorGradientList.Count-1); current = f;
var index = (int)Math.Round(f / step, 0);
slider.targetGraphic.color = colorGradientList[index];
text.text = $"{valueHandler(f).ToString("#0")}";
a.Invoke(f);
}); });
} }
float current;
System.Action<float> ValueChangedHandler;
private void OnValueChanged()
{
float f = current;
var step = 1f / (colorGradientList.Count - 1);
var index = (int)Math.Round(f / step, 0);
slider.targetGraphic.color = colorGradientList[index];
text.text = $"{valueHandler(f):#0}";
this.ValueChangedHandler?.Invoke(f);
}
public void SetValue(float a) public void SetValue(float a)
{ {
a = a > 1 ? 1 : a; a = a > 1 ? 1 : a;
a = a < 0 ? 0 : a; a = a < 0 ? 0 : a;
slider.value = a; slider.value = a;
slider.onValueChanged?.Invoke(a); OnValueChanged();
} }
public float GetValue() public float GetValue()

View File

@ -17,6 +17,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.Android;
using UnityEngine.UI; using UnityEngine.UI;
using static RowerTaskPanel; using static RowerTaskPanel;
@ -220,11 +221,7 @@ public class RowerHomeScript : PFUIPanel
{ {
var v = (ushort)Math.Round((r * 300)); var v = (ushort)Math.Round((r * 300));
print("设置阻力" + v); print("设置阻力" + v);
if (Rower != null) StartCoroutine(SetResistanceLevel(v));
{
Rower.SetResistanceLevel(v);
//RowerData.
}
}); });
//transform.Find("Ready/DeviceStatus").gameObject.SetActive(!flag); //transform.Find("Ready/DeviceStatus").gameObject.SetActive(!flag);
//transform.Find("Ready/DeviceStatusConnect").gameObject.SetActive(flag); //transform.Find("Ready/DeviceStatusConnect").gameObject.SetActive(flag);
@ -295,8 +292,6 @@ public class RowerHomeScript : PFUIPanel
RowerData.PullChanged += PaintPullCurve; RowerData.PullChanged += PaintPullCurve;
RowerData.StartEvent -= StartFunc; RowerData.StartEvent -= StartFunc;
RowerData.StartEvent += StartFunc; RowerData.StartEvent += StartFunc;
RowerData.RowerResChanged -= ResChanged;
RowerData.RowerResChanged += ResChanged;
} }
rowerType = new RowerType { type = 1, value = 500 }; rowerType = new RowerType { type = 1, value = 500 };
HandleSelectType(); HandleSelectType();
@ -304,6 +299,15 @@ public class RowerHomeScript : PFUIPanel
isFirstReset = false; isFirstReset = false;
} }
IEnumerator SetResistanceLevel(ushort res)
{
yield return new WaitForSeconds(0.1f);
if (Rower != null)
{
Rower.SetResistanceLevel(res);
}
}
RowerResultModel reRowData = null; RowerResultModel reRowData = null;
public void ReRow(RowerResultModel r) public void ReRow(RowerResultModel r)
{ {
@ -799,6 +803,7 @@ public class RowerHomeScript : PFUIPanel
void TimerTicks() void TimerTicks()
{ {
var heartRate = HeartRate ?? 0;
#if UNITY_EDITOR #if UNITY_EDITOR
var a = tempList[(tempx++) % tempList.Count]; var a = tempList[(tempx++) % tempList.Count];
Debug.Log(a); Debug.Log(a);
@ -825,8 +830,6 @@ public class RowerHomeScript : PFUIPanel
if (interruptFlag) return; if (interruptFlag) return;
if (RowerData == null) return; if (RowerData == null) return;
//#endif //#endif
var heartRate = HeartRate ?? 0;
BPMText.text = heartRate.ToString();
//断线重连继续 //断线重连继续
var distance = (int)RowerData.TotalDistance + historyDistance; var distance = (int)RowerData.TotalDistance + historyDistance;
var energy = RowerData.TotalEnergy + historyEnergy; var energy = RowerData.TotalEnergy + historyEnergy;
@ -1265,6 +1268,8 @@ public class RowerHomeScript : PFUIPanel
staticTimer -= Time.deltaTime; staticTimer -= Time.deltaTime;
if (staticTimer <= 0) if (staticTimer <= 0)
{ {
var heartRate = HeartRate ?? 0;
BPMText.text = heartRate == 0 ? "---": heartRate.ToString();
HandleStatic(); HandleStatic();
staticTimer += 1f; staticTimer += 1f;
} }
@ -1323,7 +1328,8 @@ public class RowerHomeScript : PFUIPanel
if (flag && RowerData.TotalDistance != 0) if (flag && RowerData.TotalDistance != 0)
{ {
Rower.Reset(); Rower.Reset();
//RowerData.Reset(); if(C2RowerData.IsEnabled)
RowerData.Reset();
} }
} }
if (transform.Find("Stopped").gameObject.activeInHierarchy) if (transform.Find("Stopped").gameObject.activeInHierarchy)

View File

@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Android;
using UnityEngine.UI; using UnityEngine.UI;
public class RowerDevicePanel : PFUIPanel public class RowerDevicePanel : PFUIPanel
@ -26,6 +27,18 @@ public class RowerDevicePanel : PFUIPanel
#if UNITY_ANDROID || UNITY_IOS #if UNITY_ANDROID || UNITY_IOS
#if UNITY_ANDROID #if UNITY_ANDROID
Utils.CallAndroidMethod("OpenLocationService"); Utils.CallAndroidMethod("OpenLocationService");
if (!Permission.HasUserAuthorizedPermission(Permission.CoarseLocation))
{
Permission.RequestUserPermission(Permission.CoarseLocation);
Permission.RequestUserPermission(Permission.FineLocation);
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Powerfun need location service permission,please open the location permission.")
, () => {
UIManager.CloseConfirm();
}, 2
, () => {
UIManager.CloseConfirm();
});
}
#endif #endif
App.MainDeviceAdapter.StartScan(); App.MainDeviceAdapter.StartScan();
#endif #endif