心率,阻力逻辑调整

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>
public int AverageStrokeRate { get; set; } = 0;
//private UInt32 _totalDistance = 1;
public UInt32 TotalDistance { get; set; } = 1;
private UInt16 _instantaneousPace = 1;
/// <summary>
/// 即时配速
/// </summary>
public UInt16 InstantaneousPace
private UInt32 _totalDistance = 1;
public UInt32 TotalDistance
{
get => _instantaneousPace;
get => _totalDistance;
set
{
if (_instantaneousPace == 0 && value != 0 && StartEvent != null)
if (_totalDistance == 0 && value != 0 && StartEvent != null)
{
StartEvent.Invoke(this, null);
}
_instantaneousPace = value;
_totalDistance = value;
}
}
//private UInt16 _instantaneousPace = 1;
/// <summary>
/// 即时配速
/// </summary>
public UInt16 InstantaneousPace { get; set; } = 0;
/// <summary>
/// 平均配速
/// </summary>

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Android;
using UnityEngine.UI;
public class RowerDevicePanel : PFUIPanel
@ -26,6 +27,18 @@ public class RowerDevicePanel : PFUIPanel
#if UNITY_ANDROID || UNITY_IOS
#if UNITY_ANDROID
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
App.MainDeviceAdapter.StartScan();
#endif