适配C2划船机课程和menu
This commit is contained in:
parent
e0649f7ea1
commit
06aefb93c4
@ -13,5 +13,6 @@ namespace Assets.Scripts.Devices.Ant.Interfaces
|
||||
FtmsRowerData rowerData { get; }
|
||||
void Reset();
|
||||
void SetResistanceLevel(ushort v);
|
||||
void C2GetStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<ushort> r = new List<ushort>();
|
||||
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()
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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<Image>().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>().text = "---";
|
||||
bottom.Find("KM/Value").GetComponent<Text>().text = $"{rowerType.value}M";
|
||||
bottom.Find("KM/Value").GetComponent<Text>().text = $"{rowerType.value}";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -511,14 +534,18 @@ public class RowerHomeScript : PFUIPanel
|
||||
private void ResChanged(object sender, EventArgs e)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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>().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)
|
||||
|
||||
|
||||
mid.Find("W/Value").GetComponent<Text>().text = power.ToString();
|
||||
bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToPFString();
|
||||
bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString();
|
||||
left.Find("Times/Value").GetComponent<Text>().text = strokeCount.ToString();
|
||||
left.Find("Calories/Value").GetComponent<Text>().text = energy.ToString();
|
||||
mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0");
|
||||
mid.Find("PeakForce/Value").GetComponent<Text>().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>().text = $"{dis.ToString("#0")}";
|
||||
}
|
||||
}
|
||||
|
||||
//RowerPanel/Rower/Bottom/Expected/Value
|
||||
|
||||
mid.Find("W/Value").GetComponent<Text>().text = power.ToString();
|
||||
//bottom.Find("W/AvgValue").GetComponent<Text>().text = RowerData.AveragePower.ToString();
|
||||
|
||||
bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToPFString();
|
||||
//bottom.Find("500/AvgValue").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.AveragePace).ToString(@"mm\:ss");
|
||||
|
||||
bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString();
|
||||
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = RowerData.AverageStrokeRate.ToString();
|
||||
//if (ushort.TryParse(left.Find("Times/Value").GetComponent<Text>().text, out ushort originStroke))
|
||||
//{
|
||||
// if (strokeCount != originStroke)
|
||||
// {
|
||||
// left.Find("Rower").GetComponent<RowerAnimation>().StartAnimation();
|
||||
// }
|
||||
//}
|
||||
left.Find("Times/Value").GetComponent<Text>().text = strokeCount.ToString();
|
||||
left.Find("Calories/Value").GetComponent<Text>().text = energy.ToString();
|
||||
mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0");
|
||||
mid.Find("PeakForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0");
|
||||
if (rowerType.type == 2)
|
||||
{
|
||||
var remainTime = rowerType.value - (seconds++);
|
||||
bottom.Find("Time/Value").GetComponent<Text>().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>().text = TimeSpan.FromSeconds(seconds++).ToPFString();
|
||||
}
|
||||
if (rowerType.type == 1)
|
||||
{
|
||||
var remainDistance = rowerType.value - totalDistance;
|
||||
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}");
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ namespace Assets.Scripts
|
||||
/// <param name="showSeconds"></param>
|
||||
/// <param name="endCallback"></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;
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user