拉力曲线性能优化&解决划船时间误差问题
This commit is contained in:
parent
6c9b3f825a
commit
573b96d86c
@ -1269,7 +1269,7 @@ MonoBehaviour:
|
||||
m_HorizontalOverflow: 1
|
||||
m_VerticalOverflow: 1
|
||||
m_LineSpacing: 1
|
||||
m_Text: Please make sure the device is powered on an awakened
|
||||
m_Text: Please make sure the device is powered on and awakened
|
||||
--- !u!114 &6648807303715948149
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -368,8 +368,9 @@
|
||||
"FINISH": "终点",
|
||||
"Continue the game?": "有中断的划船记录,是否继续?",
|
||||
"Save the game?": "有中断的划船记录,是否保存?",
|
||||
"Please make sure the device is powered on an awakened": "请确保设备有电且已唤醒",
|
||||
"Powerfun need location service permission,please open the location permission.": "Powerfun需要定位服务权限,请打开定位服务权限!"
|
||||
"Please make sure the device is powered on and awakened": "请确保设备有电且已唤醒",
|
||||
"Powerfun need location service permission,please open the location permission.": "Powerfun需要定位服务权限,请打开定位服务权限!",
|
||||
"Disconnect the device?": "是否断开该设备?"
|
||||
},
|
||||
"en": {
|
||||
"HOT ROUTES": "HOT ROUTES",
|
||||
@ -732,7 +733,8 @@
|
||||
"FINISH": "FINISH",
|
||||
"Continue the game?": "Continue the game?",
|
||||
"Save the game?": "Save the game?",
|
||||
"Please make sure the device is powered on an awakened": "Please make sure the device is powered on an awakened",
|
||||
"Powerfun need location service permission,please open the location permission.": "Powerfun need location service permission,please open the location permission."
|
||||
"Please make sure the device is powered on and awakened": "Please make sure the device is powered on and awakened",
|
||||
"Powerfun need location service permission,please open the location permission.": "Powerfun need location service permission,please open the location permission.",
|
||||
"Disconnect the device?": "Disconnect the device?"
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,11 +51,13 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsUserDefined { get; set; }
|
||||
|
||||
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));
|
||||
|
||||
if (data[0] == 0x35)
|
||||
{
|
||||
PeakDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 13)) / 10, true);
|
||||
@ -63,7 +65,7 @@ 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($"峰力值:{PeakDriveForce} 均力值{AverageDriveForce}");
|
||||
Debug.Log("数据" + string.Join(",", data) +$" | {ElapsedTime}-{TotalDistance}");
|
||||
}
|
||||
else if (data[0] == 0x3d)
|
||||
{
|
||||
@ -71,7 +73,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
//List<ushort> r = new List<ushort>();
|
||||
for (int i = 3; i < data.Length; i += 2)
|
||||
{
|
||||
ushort pull = data[i] < 5 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i], true)));
|
||||
ushort pull = data[i] < 10 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i], true)));
|
||||
//r.Add(pull);
|
||||
PullValue = pull;
|
||||
}
|
||||
@ -87,17 +89,21 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
rowerType = new RowerTaskPanel.RowerType();
|
||||
rowerType.type = 1;
|
||||
rowerType.value = value;
|
||||
IsUserDefined = true;
|
||||
}
|
||||
else if (status == 0)
|
||||
{
|
||||
rowerType = new RowerTaskPanel.RowerType();
|
||||
rowerType.type = 2;
|
||||
rowerType.value = value / 100;
|
||||
IsUserDefined = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
rowerType = null;
|
||||
IsUserDefined = false;
|
||||
}
|
||||
Debug.Log($"里程:{TotalDistance}峰力值:{PeakDriveForce} 均力值{AverageDriveForce} ReadyStatus:{isReadyStatus} TIME{DateTime.Now}");
|
||||
//isReadyStatus = data[9] == 0;
|
||||
var time = ((data[3] << 16) + (data[2] << 8) + data[1]) / 100;
|
||||
Debug.Log("划船时间" + time);
|
||||
|
||||
@ -25,6 +25,7 @@ public class MainController : BaseScene
|
||||
Debug.Log("执行25");
|
||||
Version = this.transform.Find("GameObject").Find("Version").GetComponent<Text>();
|
||||
Version.text = "V"+App.AppVersion;
|
||||
transform.Find("Text").GetComponent<Text>().text = "2022-6-21-V1";
|
||||
DeviceCache.Init(PFConstants.DeviceCacheFolder);
|
||||
Loom.Initialize();
|
||||
msg = transform.Find("GameObject/Message").GetComponent<CanvasGroup>();
|
||||
|
||||
@ -92,7 +92,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
Transform left, bottom, mid, rmydata;
|
||||
Image leftImage;
|
||||
Image rightImage;
|
||||
float timer = 1.0f;
|
||||
float timer = 0f;
|
||||
List<DoubleVector2> pullList, historyPullList;
|
||||
public Dictionary<object, Sprite> spriteDict, spriteDict2;
|
||||
List<string> records;
|
||||
@ -513,7 +513,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
truelyTime = historyTime;
|
||||
//TimerTicks();
|
||||
openTimer = true;
|
||||
timer = 1.0f;
|
||||
timer = 0f;
|
||||
}
|
||||
transform.Find("Ready").gameObject.SetActive(false);
|
||||
//if (UIManager.Instance.RowerWelldone)
|
||||
@ -657,6 +657,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
|
||||
private void Init()
|
||||
{
|
||||
ResetChart();
|
||||
deviceName = "";
|
||||
deviceNetwork = "";
|
||||
deviceAddress = "";
|
||||
@ -833,7 +834,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
var heartRate = HeartRate ?? 0;
|
||||
#if UNITY_EDITOR
|
||||
var a = tempList[(tempx++) % tempList.Count];
|
||||
Debug.Log(a);
|
||||
//Debug.Log(a);
|
||||
PaintPullCurve((ushort)(a / 10));
|
||||
if (RowerData == null) return;
|
||||
#endif
|
||||
@ -859,8 +860,9 @@ public class RowerHomeScript : PFUIPanel
|
||||
return;
|
||||
}
|
||||
if (RowerData == null) return;
|
||||
//#endif
|
||||
//断线重连继续
|
||||
transform.Find("Text").GetComponent<Text>().text = $"{RowerData.ElapsedTime}:{RowerData.TotalDistance}";
|
||||
//#endif
|
||||
//断线重连继续()
|
||||
var distance = (int)RowerData.TotalDistance + historyDistance;
|
||||
var energy = RowerData.TotalEnergy + historyEnergy;
|
||||
var strokeCount = RowerData.StrokeCount + historyStrokeCount;
|
||||
@ -868,10 +870,24 @@ public class RowerHomeScript : PFUIPanel
|
||||
var power = RowerData.InstantaneousPower;
|
||||
var rate = RowerData.StrokeRate;
|
||||
truelyTime++;
|
||||
Debug.Log($"ElapsedTime :{RowerData.ElapsedTime} : {truelyTime}-{RowerData.TotalDistance}");
|
||||
TempRowerCalc tmpdata = null;
|
||||
|
||||
//解决里程训练无法结束的问题
|
||||
var c2notStop = rowerType.type == 1 && (rowerType.value-totalDistance) <= 5;
|
||||
if (c2notStop)
|
||||
{
|
||||
distance = (int)rowerType.value;
|
||||
KMText.text = "0";
|
||||
records.Add($"{strokeCount},{RowerData.ElapsedTime},{rowerType.value},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
|
||||
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = RowerData.InstantaneousPace, power = power, rate = rate, heartRate = heartRate, distance = (int)rowerType.value, energy = energy };
|
||||
values.Add(tmpdata);
|
||||
SendDataToRace(tmpdata);
|
||||
HandleSaveDirect();
|
||||
return;
|
||||
}
|
||||
//里程停止逻辑
|
||||
if (totalDistance == RowerData.TotalDistance + historyDistance)
|
||||
if (totalDistance == RowerData.TotalDistance && !c2notStop)
|
||||
{
|
||||
//判定一次停止
|
||||
stopSeconds++;
|
||||
@ -884,6 +900,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
if (stopSeconds >= 2)
|
||||
{
|
||||
if (UIManager.Instance.confirm != null && UIManager.Instance.confirm.IsActive()) {
|
||||
Debug.Log("stopSeconds >= 2");
|
||||
transform.Find("Stopped").gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
@ -1012,10 +1029,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
|
||||
values.Add(tmpdata);
|
||||
SendDataToRace(tmpdata);
|
||||
if (C2RowerData.IsEnabled == true && C2RowerData.isReadyStatus && values.Count()>10)
|
||||
{
|
||||
HandleSaveDirect();
|
||||
}
|
||||
|
||||
if (ticks % 5 == 0)
|
||||
{
|
||||
SaveRealTimes();//实时保存数据
|
||||
@ -1036,6 +1050,10 @@ public class RowerHomeScript : PFUIPanel
|
||||
if (files.Length == 0)
|
||||
return;
|
||||
var historyRowerTime = PlayerPrefs.GetString("historyRowerTime");
|
||||
deviceName = PlayerPrefs.GetString("deviceName");
|
||||
deviceNetwork = PlayerPrefs.GetString("deviceNetwork");
|
||||
deviceAddress = PlayerPrefs.GetString("deviceAddress");
|
||||
deviceSensor = PlayerPrefs.GetString("deviceSensor");
|
||||
if (!string.IsNullOrEmpty(historyRowerTime))
|
||||
{
|
||||
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Save the game?"), () =>
|
||||
@ -1102,7 +1120,12 @@ public class RowerHomeScript : PFUIPanel
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
File.WriteAllText(path, string.Join("\r\n", records));
|
||||
File.WriteAllText($"{PFConstants.RowerRecordCacheFolder}/cache.txt", string.Join("\r\n", App.cacheList));
|
||||
//File.WriteAllText($"{PFConstants.RowerRecordCacheFolder}/cache.txt", string.Join("\r\n", App.cacheList));
|
||||
PlayerPrefs.SetString("deviceName", deviceName);
|
||||
PlayerPrefs.SetString("deviceNetwork", deviceNetwork);
|
||||
PlayerPrefs.SetString("deviceAddress", deviceAddress);
|
||||
PlayerPrefs.SetString("deviceSensor", deviceSensor);
|
||||
|
||||
PlayerPrefs.SetString("historyRowerType", $"{rowerType.type},{rowerType.value}");
|
||||
PlayerPrefs.SetString("historyRowerTime", UIManager.Now.GetDateTime().ToString());
|
||||
PlayerPrefs.SetString("historyRowerShadowIds", string.Join(",", GetComponent<RowerMultiModeScript>().shadowList.Select(x => x.Nid)));
|
||||
@ -1141,7 +1164,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
int pointCount = 0;
|
||||
void PaintPullCurve(ushort y)
|
||||
{
|
||||
Debug.Log($"收到拉力 x={x} , y={y}");
|
||||
//Debug.Log($"收到拉力 x={x} , y={y}");
|
||||
//#if !UNITY_EDITOR
|
||||
// if (!openTimer)
|
||||
// {
|
||||
@ -1162,7 +1185,6 @@ public class RowerHomeScript : PFUIPanel
|
||||
if (rate > 1) rate = 1f;
|
||||
leftImage.fillAmount = rate;
|
||||
rightImage.fillAmount = rate;
|
||||
|
||||
//动画
|
||||
//left.Find("Rower").GetComponent<Image>().sprite = spriteDict[y / 67];
|
||||
//曲线
|
||||
@ -1171,9 +1193,9 @@ public class RowerHomeScript : PFUIPanel
|
||||
//if (pullList.Count == 0)
|
||||
if(pointCount == 0)
|
||||
{
|
||||
ClearChart("Player 2");
|
||||
ClearChart();
|
||||
isPlay = true;
|
||||
x = 0.1;
|
||||
x = 0;
|
||||
pointCount++;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
SetChartData(x, y);
|
||||
@ -1188,19 +1210,18 @@ public class RowerHomeScript : PFUIPanel
|
||||
historyPullList = pullList.Select(x => x).ToList();
|
||||
pullList.Clear();
|
||||
pointCount = 0;
|
||||
x = 0.1;
|
||||
//x = 0.1;
|
||||
//SetChartData(x, y);
|
||||
pointCount = 1;
|
||||
//isPlay = true;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
//pullList.Add(new DoubleVector2(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
//只有0并且两秒没拉,曲线消失
|
||||
if (stopSeconds == 1)
|
||||
{
|
||||
ClearChart("Player 1");
|
||||
ClearChart("Player 2");
|
||||
ClearChart();
|
||||
//SetChartData(new List<DoubleVector2>(), new List<DoubleVector2>());
|
||||
}
|
||||
}
|
||||
@ -1209,9 +1230,9 @@ public class RowerHomeScript : PFUIPanel
|
||||
{
|
||||
if (pullList.Count(x => x.y == 0) == pullList.Count)
|
||||
{
|
||||
ClearChart("Player 2");
|
||||
ClearChart();
|
||||
pointCount = 0;
|
||||
SetChartData(0.1, 0);
|
||||
//SetChartData(0.1, 0);
|
||||
}
|
||||
x += 0.1;
|
||||
pointCount++;
|
||||
@ -1239,18 +1260,25 @@ public class RowerHomeScript : PFUIPanel
|
||||
// x += 0.1f;
|
||||
//}
|
||||
}
|
||||
void ClearChart(string cateName)
|
||||
void ClearChart()
|
||||
{
|
||||
rowerGraphChartFeed.ClearChart(cateName);
|
||||
graphChartFeed.ClearChart(cateName);
|
||||
if (x > 0)
|
||||
{
|
||||
rowerGraphChartFeed.ClearChart();
|
||||
graphChartFeed.ClearChart();
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
void ResetChart() {
|
||||
rowerGraphChartFeed?.ResetChart();
|
||||
graphChartFeed?.ResetChart();
|
||||
}
|
||||
double preX, preY;
|
||||
void SetChartData(double x, double y)
|
||||
{
|
||||
if (M1.localPosition.x == 0)
|
||||
{
|
||||
rowerGraphChartFeed.SetCurrentPoint(x, y);
|
||||
rowerGraphChartFeed.SetHistoryData(historyPullList);
|
||||
rowerGraphChartFeed.SetHistoryData(x, historyPullList);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1275,48 +1303,36 @@ public class RowerHomeScript : PFUIPanel
|
||||
int ticks { get; set; } = 0;
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (openTimer || true)
|
||||
#else
|
||||
if (openTimer)
|
||||
#endif
|
||||
shortTimer -= Time.deltaTime;
|
||||
if (shortTimer <= 0)
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
shortTimer -= Time.deltaTime;
|
||||
if (shortTimer <= 0)
|
||||
{
|
||||
ShortUpdateData();
|
||||
shortTimer += 0.25f;
|
||||
}
|
||||
if (timer <= 0)
|
||||
ShortUpdateData();
|
||||
shortTimer += 0.25f;
|
||||
}
|
||||
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (openTimer || true)
|
||||
#else
|
||||
if (openTimer)
|
||||
#endif
|
||||
{
|
||||
TimerTicks();
|
||||
ticks++;
|
||||
timer = 1f + timer;
|
||||
}
|
||||
}
|
||||
|
||||
staticTimer -= Time.deltaTime;
|
||||
if (staticTimer <= 0)
|
||||
{
|
||||
var heartRate = HeartRate ?? 0;
|
||||
BPMText.text = heartRate == 0 ? "---": heartRate.ToString();
|
||||
BPMText.text = heartRate == 0 ? "---" : heartRate.ToString();
|
||||
HandleStatic();
|
||||
staticTimer += 1f;
|
||||
}
|
||||
|
||||
//shortTimer -= Time.deltaTime;
|
||||
//if (shortTimer <= 0)
|
||||
//{
|
||||
// if (openTimer)
|
||||
// {
|
||||
// ShortUpdateData();
|
||||
// }
|
||||
// shortTimer += 0.5f;
|
||||
//}
|
||||
timer += 1f ;
|
||||
}
|
||||
}
|
||||
void ShortUpdateData()
|
||||
{
|
||||
if (!openTimer) return;
|
||||
if (RowerData == null) return;
|
||||
var power = RowerData.InstantaneousPower;
|
||||
var rate = RowerData.StrokeRate;
|
||||
@ -1325,12 +1341,12 @@ public class RowerHomeScript : PFUIPanel
|
||||
var distance = (int)RowerData.TotalDistance + historyDistance;
|
||||
var energy = RowerData.TotalEnergy + historyEnergy;
|
||||
var heartRate = HeartRate ?? 0;
|
||||
if (rowerType.type == 1 && totalDistance >=rowerType.value && !createTime.HasValue)
|
||||
if (rowerType.type == 1 && (rowerType.value - totalDistance) <= 5 && !createTime.HasValue)
|
||||
{
|
||||
openTimer = false;
|
||||
KMText.text = "0";
|
||||
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
|
||||
var tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
|
||||
records.Add($"{strokeCount},{RowerData.ElapsedTime},{rowerType.value},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
|
||||
var tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = (int)rowerType.value, energy = energy };
|
||||
values.Add(tmpdata);
|
||||
SendDataToRace(tmpdata);
|
||||
HandleSaveDirect();
|
||||
|
||||
@ -132,7 +132,7 @@ public class RowerDeviceView : MonoBehaviour
|
||||
var device = GetDevice();
|
||||
if (device != null && device.State == DeviceState.Connected)
|
||||
{
|
||||
UIManager.ShowConfirm("警告", "是否断开该设备?", () =>
|
||||
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Disconnect the device?"), () =>
|
||||
{
|
||||
device.Disconnect(false);
|
||||
DeviceCache.Remove(device);
|
||||
@ -147,7 +147,7 @@ public class RowerDeviceView : MonoBehaviour
|
||||
}
|
||||
});
|
||||
UIManager.AddEvent(mDisconnectButton, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e => {
|
||||
UIManager.ShowConfirm("警告", "是否断开该设备?", () =>
|
||||
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Disconnect the device?"), () =>
|
||||
{
|
||||
var device = GetDevice();
|
||||
if (device != null && device.State == DeviceState.Connected)
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using UnityEngine;
|
||||
using ChartAndGraph;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class RowerGraphChartFeed : MonoBehaviour
|
||||
@ -42,25 +43,44 @@ public class RowerGraphChartFeed : MonoBehaviour
|
||||
}
|
||||
public void SetCurrentPoint(double x,double y)
|
||||
{
|
||||
if(dataSource != null)
|
||||
x += dataSource.HorizontalViewOrigin;
|
||||
Debug.Log($"SetCurrentPoint:{x}-{y}");
|
||||
|
||||
dataSource?.AddPointToCategoryRealtime("Player 2", x, y);
|
||||
}
|
||||
public void ClearChart(string cat = "Player 2")
|
||||
public void ClearChart()
|
||||
{
|
||||
dataSource?.ClearCategory(cat);
|
||||
}
|
||||
public void SetHistoryData(List<DoubleVector2> list2 = null)
|
||||
{
|
||||
if (list2 != null)
|
||||
if (dataSource != null)
|
||||
{
|
||||
dataSource?.ClearCategory("Player 1");
|
||||
dataSource.HorizontalViewOrigin += 10;
|
||||
SetCurrentPoint(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHistoryData(double x,List<DoubleVector2> list2 = null)
|
||||
{
|
||||
if (list2 != null && list2.Count > 0)
|
||||
{
|
||||
var offset = dataSource.HorizontalViewOrigin;
|
||||
graph.DataSource.AddPointToCategoryRealtime("Player 1", offset, 0);
|
||||
for (int i = 0; i < list2.Count; i++)
|
||||
{
|
||||
var item = list2[i];
|
||||
graph.DataSource.AddPointToCategoryRealtime("Player 1", item.x, item.y);
|
||||
graph.DataSource.AddPointToCategoryRealtime("Player 1", item.x + offset, item.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetChart()
|
||||
{
|
||||
if (dataSource != null)
|
||||
{
|
||||
dataSource.HorizontalViewOrigin = -0.03;
|
||||
dataSource.ClearCategory("Player 1");
|
||||
dataSource.ClearCategory("Player 2");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetData(List<DoubleVector2> list,List<DoubleVector2> list2 = null)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user