适配C2划船机课程和menu

This commit is contained in:
CaiYanPeng 2022-03-30 18:25:51 +08:00
parent e0649f7ea1
commit 06aefb93c4
6 changed files with 162 additions and 77 deletions

View File

@ -13,5 +13,6 @@ namespace Assets.Scripts.Devices.Ant.Interfaces
FtmsRowerData rowerData { get; } FtmsRowerData rowerData { get; }
void Reset(); void Reset();
void SetResistanceLevel(ushort v); void SetResistanceLevel(ushort v);
void C2GetStatus();
} }
} }

View File

@ -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) public void HandleAttributeReceived(byte[] data)
{ {
Debug.Log("数据" + string.Join(",", data)); Debug.Log("数据" + string.Join(",", data));
@ -69,8 +72,35 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
PullValue = 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; private double LbsToNewton(double lbs) => 4.4482216 * lbs;
public void SetUnavailable() public void SetUnavailable()

View File

@ -23,7 +23,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
private BleCharacteristicInfo controlPointCharacteristic; private BleCharacteristicInfo controlPointCharacteristic;
private BleCharacteristicInfo c2Control; 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); Debug.Log(24);
base.Characteristics.Add(new FtmsFitnessMachineFeature()); base.Characteristics.Add(new FtmsFitnessMachineFeature());
@ -70,9 +70,15 @@ namespace Assets.Scripts.Devices.Ble.Devices
//C2RowerData.IsEnabled = true; //C2RowerData.IsEnabled = true;
this.hwInterface.SubscribeCharacteristic(character, null); 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; //C2RowerData.IsEnabled = true;
this.hwInterface.SubscribeCharacteristic(character, null); this.hwInterface.SubscribeCharacteristic(character, null);
} }
@ -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() public void Reset()
{ {

View File

@ -375,7 +375,9 @@ namespace Assets.Scripts.Ble
//拉力曲线 //拉力曲线
public static Guid C2RowerData1 = new Guid("ce06003D-43e5-11e4-916c-0800200c9a66"); public static Guid C2RowerData1 = new Guid("ce06003D-43e5-11e4-916c-0800200c9a66");
//c2划船机状态 //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"); public static Guid C2Service = new Guid("CE060030-43E5-11E4-916C-0800200C9A66");
//ce060030-43e5-11e4-916c-0800200c9a66 //ce060030-43e5-11e4-916c-0800200c9a66
} }

View File

@ -186,6 +186,7 @@ public class RowerHomeScript : PFUIPanel
//UIManager.ShowRowerWelldone("81A85D49-ACAA-C764-101A-02555E6AC81A"); //UIManager.ShowRowerWelldone("81A85D49-ACAA-C764-101A-02555E6AC81A");
//return; //return;
if (checkRowing()) return; if (checkRowing()) return;
if (C2RowerData.IsEnabled == true && C2RowerData.rowerType != null) return;
UIManager.ShowRowerTaskPanel(type=> UIManager.ShowRowerTaskPanel(type=>
{ {
rowerType = type; rowerType = type;
@ -212,7 +213,17 @@ public class RowerHomeScript : PFUIPanel
UIManager.AddEvent(transform.Find("Stopped/Confirm/BtnDrop").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => UIManager.AddEvent(transform.Find("Stopped/Confirm/BtnDrop").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{ {
transform.Find("Stopped").gameObject.SetActive(false); 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(); Init();
} }
@ -271,8 +282,20 @@ public class RowerHomeScript : PFUIPanel
btnStart.GetComponent<Image>().sprite = spriteDict["Start"]; btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start"; btnStart.tag = "Start";
transform.Find("Stopped").gameObject.SetActive(false); transform.Find("Stopped").gameObject.SetActive(false);
Save(); //Utils.showToast()
Init(); 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 IRowerCommonData RowerCommonDataInstance => Rower != null ? (C2RowerData.IsEnabled == true ? (IRowerCommonData)Rower.c2RowerData : (IRowerCommonData)Rower.rowerData) : null;
private void HandleStartOrPause() private void HandleStartOrPause()
@ -462,7 +485,7 @@ public class RowerHomeScript : PFUIPanel
if (rowerType.type == 1) if (rowerType.type == 1)
{ {
bottom.Find("Time/Value").GetComponent<Text>().text = "---"; bottom.Find("Time/Value").GetComponent<Text>().text = "---";
bottom.Find("KM/Value").GetComponent<Text>().text = $"{rowerType.value}M"; bottom.Find("KM/Value").GetComponent<Text>().text = $"{rowerType.value}";
} }
else else
{ {
@ -511,14 +534,18 @@ public class RowerHomeScript : PFUIPanel
private void ResChanged(object sender, EventArgs e) private void ResChanged(object sender, EventArgs e)
{ {
print("收到阻力" + sender); print("收到阻力" + sender);
slider.GetComponent<PFUISlider>().SetValue((Convert.ToSingle(sender) - 50) / 300f); if ((Convert.ToSingle(sender) > 50))
{
slider.GetComponent<PFUISlider>().SetValue((Convert.ToSingle(sender) - 50) / 300f);
}
} }
public bool checkRowing() public bool checkRowing()
{ {
if (seconds > 0) 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 true;
} }
return false; return false;
@ -627,42 +654,16 @@ public class RowerHomeScript : PFUIPanel
totalDistance = (uint)distance; totalDistance = (uint)distance;
var pace = RowerData.InstantaneousPace; var pace = RowerData.InstantaneousPace;
if (rowerType.type == 2)
{
var remainTime = rowerType.value - (seconds++); mid.Find("W/Value").GetComponent<Text>().text = power.ToString();
if (remainTime == 0) bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToPFString();
{ bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString();
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}"); left.Find("Times/Value").GetComponent<Text>().text = strokeCount.ToString();
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy }; left.Find("Calories/Value").GetComponent<Text>().text = energy.ToString();
values.Add(tmpdata); mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0");
SendDataToRace(tmpdata); mid.Find("PeakForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0");
HandleSaveDirect();
return;
}
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(remainTime).ToPFString();
}
else
{
bottom.Find("Time/Value").GetComponent<Text>().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>().text = remainDistance.ToString();
}
else
{
bottom.Find("KM/Value").GetComponent<Text>().text = totalDistance.ToString();
}
if (pace != 0) if (pace != 0)
{ {
if (rowerType.type == 1) if (rowerType.type == 1)
@ -694,28 +695,43 @@ public class RowerHomeScript : PFUIPanel
bottom.Find("Expected/Value").GetComponent<Text>().text = $"{dis.ToString("#0")}"; bottom.Find("Expected/Value").GetComponent<Text>().text = $"{dis.ToString("#0")}";
} }
} }
if (rowerType.type == 2)
//RowerPanel/Rower/Bottom/Expected/Value {
var remainTime = rowerType.value - (seconds++);
mid.Find("W/Value").GetComponent<Text>().text = power.ToString(); bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(remainTime).ToPFString();
//bottom.Find("W/AvgValue").GetComponent<Text>().text = RowerData.AveragePower.ToString(); if (remainTime == 0)
{
bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToPFString(); records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}");
//bottom.Find("500/AvgValue").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.AveragePace).ToString(@"mm\:ss"); tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
values.Add(tmpdata);
bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString(); SendDataToRace(tmpdata);
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = RowerData.AverageStrokeRate.ToString(); HandleSaveDirect();
//if (ushort.TryParse(left.Find("Times/Value").GetComponent<Text>().text, out ushort originStroke)) return;
//{ }
// if (strokeCount != originStroke) }
// { else
// left.Find("Rower").GetComponent<RowerAnimation>().StartAnimation(); {
// } bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(seconds++).ToPFString();
//} }
left.Find("Times/Value").GetComponent<Text>().text = strokeCount.ToString(); if (rowerType.type == 1)
left.Find("Calories/Value").GetComponent<Text>().text = energy.ToString(); {
mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0"); var remainDistance = rowerType.value - totalDistance;
mid.Find("PeakForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0"); if (remainDistance < 0)
{
bottom.Find("KM/Value").GetComponent<Text>().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>().text = remainDistance.ToString();
}
else
{
bottom.Find("KM/Value").GetComponent<Text>().text = totalDistance.ToString();
}
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}"); 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 }; tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
values.Add(tmpdata); values.Add(tmpdata);
@ -748,7 +764,7 @@ public class RowerHomeScript : PFUIPanel
#if !UNITY_EDITOR #if !UNITY_EDITOR
if (!openTimer) if (!openTimer)
{ {
if (y > 0) if (y > 0 && !isPause)
{ {
//RowerCommonDataInstance.PullChanged -= PaintPullCurve; //RowerCommonDataInstance.PullChanged -= PaintPullCurve;
//RowerCommonDataInstance.PullChanged += PaintPullCurve; //RowerCommonDataInstance.PullChanged += PaintPullCurve;
@ -852,5 +868,13 @@ public class RowerHomeScript : PFUIPanel
transform.Find("Ready/Text").gameObject.SetActive(flag); transform.Find("Ready/Text").gameObject.SetActive(flag);
transform.Find("Ready/DeviceStatusConnect").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();
}
}
} }
} }

View File

@ -176,7 +176,7 @@ namespace Assets.Scripts
/// <param name="showSeconds"></param> /// <param name="showSeconds"></param>
/// <param name="endCallback"></param> /// <param name="endCallback"></param>
/// <param name="_parent"></param> /// <param name="_parent"></param>
public static void showToast(GameObject p, string text, int duration = 2, int type = 0, Func<bool> 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<bool> stopFunc = null, bool isLowest = false,bool showSeconds = false,Action endCallback = null,PFUIPanel _parent = null,bool isOnly = false)
{ {
var parent = UIManager.Instance.ModalsPanel; var parent = UIManager.Instance.ModalsPanel;
if (parent == null) if (parent == null)
@ -194,6 +194,7 @@ namespace Assets.Scripts
var toast = parent.transform.Find("ToastContainer"); var toast = parent.transform.Find("ToastContainer");
if (toast != null) if (toast != null)
{ {
if (isOnly) return;
MonoBehaviour.DestroyImmediate(toast.gameObject); MonoBehaviour.DestroyImmediate(toast.gameObject);
} }
#if UNITY_IOS || UNITY_ANDROID #if UNITY_IOS || UNITY_ANDROID