适配c2;新版设计稿;对战切换手势;主逻辑接通;使用think的阻力值,修改影子模式船位置

This commit is contained in:
Caiyanpeng committed 2022-03-25 18:02:34 +08:00
1 parent e6f3e2ecfa
commit ab653b994f
82 files changed
+25241 -8988

No files matched your search

@@ -0,0 +1,82 @@
using Assets.Scripts.Ble;
using Assets.Scripts.Devices.Ble.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Devices.Ble.Characteristic
{
public class C2RowerData : ICharacteristic, IRowerCommonData
{
public Guid Uuid => ServiceUuids.Characteristics.C2RowerData;
public Guid ServiceUuid => ServiceUuids.Characteristics.C2Service;
public bool IsOptional => false;
public static event EventHandler EnableChanged;
private static bool? _isEnabled;
public static bool? IsEnabled
{
get => _isEnabled;
set
{
_isEnabled = value;
if (EnableChanged != null)
{
EnableChanged(_isEnabled, new EventArgs());
}
}
}
//0.1 lbs of force, max=6553.5m 单位0.1磅
public double PeakDriveForce { get; set; }
public double AverageDriveForce { get; set; }
public event EventHandler PullChanged;
private ushort _pullValue;
public ushort PullValue
{
get { return _pullValue; }
set
{
_pullValue = value;
if (this.PullChanged != null)
{
this.PullChanged(this, new EventArgs());
}
}
}
public void HandleAttributeReceived(byte[] data)
{
Debug.Log("数据" + string.Join(",", data));
if (data[0] == 53)
{
PeakDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 13)) / 10);
AverageDriveForce = LbsToNewton(Convert.ToDouble(BitConvertHelper.ToUInt16(data, 15)) / 10);
Debug.Log($"峰力值:{PeakDriveForce} 均力值{AverageDriveForce}");
}
else if (data[0] == 61)
{
List<ushort> r = new List<ushort>();
for (int i = 3; i < data.Length; i += 2)
{
ushort pull = data[i] < 10 ? (ushort)0 : Convert.ToUInt16(Math.Round(LbsToNewton(data[i])));
r.Add(pull);
PullValue = pull;
}
Debug.Log("拉力曲线:"+ string.Join(",",r));
}
}
private double LbsToNewton(double lbs) => 4.4482216 * lbs;
public void SetUnavailable()
{
//throw new NotImplementedException();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 64ae3a6d26480b04c8fed17cc833d179
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,4 +1,5 @@
using Assets.Scripts.Ble;
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.Devices.Ble.Interfaces;
using System;
using System.Collections.Generic;
@@ -9,7 +10,7 @@ using UnityEngine;
namespace Assets.Scripts.Devices.Ble.Characteristic
{
public class FtmsRowerData : ICharacteristic
public class FtmsRowerData : ICharacteristic, IRowerCommonData
{
/// <summary>
/// 划桨频率
@@ -37,8 +38,26 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
public int InstantaneousPower { get; private set; } = 0;
public int AveragePower { get; private set; } = 0;
public int ResistanceLevel { get; private set; } = 0;
public static event EventHandler RowerResChanged;
private int commonRes = 50;
private int thinkRes = 50;
public int ResistanceLevel
{
get
{
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
if (device == null) return 0;
if (device.Name.Contains("Think"))
{
return thinkRes;
}
else
{
return commonRes;
}
}
}
/// <summary>
/// 运行时间
/// </summary>
@@ -49,6 +68,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
public int EnergyPerHour { get; private set; } = 0;
public int EnergyPerMinute { get; private set; } = 0;
public double PeakDriveForce { get; set; } = 0;
public double AverageDriveForce { get; set; } = 0;
public Guid Uuid => ServiceUuids.Characteristics.RowerData;
@@ -152,7 +173,12 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
}
if (this.Flags.HasFlag(RowerDataFlag.ResistanceLevel))
{
this.ResistanceLevel = BitConvertHelper.ToInt16(data, b);
this.commonRes = BitConvertHelper.ToInt16(data, b);
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
if (device != null && !device.Name.Contains("Think") && RowerResChanged != null)
{
RowerResChanged.Invoke(this.commonRes, null);
}
b += this.SizeOfDataForFlag(RowerDataFlag.ResistanceLevel);
}
if (this.Flags.HasFlag(RowerDataFlag.ExpendedEnergy))
@@ -184,6 +210,16 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
{
b += this.SizeOfDataForFlag(RowerDataFlag.RemainingTime);
}
if (this.Flags.HasFlag(RowerDataFlag.ThinkDragFactor))
{
this.thinkRes = BitConvertHelper.ToInt16(data, b + 1);
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
if (device != null && device.Name.Contains("Think") && RowerResChanged != null)
{
RowerResChanged.Invoke(this.thinkRes, null);
}
b += this.SizeOfDataForFlag(RowerDataFlag.ThinkDragFactor);
}
if (this.Flags.HasFlag(RowerDataFlag.Pull))
{
List<ushort> list = new List<ushort>();
@@ -194,10 +230,24 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
PullValue = val;
}
if (pullList == null) pullList = new List<ushort>();
foreach (var pull in list)
{
if (pull == 0)
{
if (pullList.Count != 0)
{
PeakDriveForce = pullList.Max();
AverageDriveForce = (double)pullList.Average(x=>x);
}
pullList.Clear();
}
pullList.Add(pull);
}
Debug.Log("拉力:" + string.Join(",",list));
}
//Debug.Log("原始数据:" + string.Join(",", data));
}
List<ushort> pullList;
public void Reset()
{
this.StrokeRate = 0;
@@ -208,7 +258,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
this.AveragePace = 0;
this.InstantaneousPower = 0;
this.AveragePower = 0;
this.ResistanceLevel = 0;
this.commonRes = 50;
this.thinkRes = 50;
//this.ResistanceLevel = 0;
this.TotalEnergy = 0;
this.EnergyPerHour = 0;
this.EnergyPerMinute = 0;
@@ -258,6 +310,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
case RowerDataFlag.RemainingTime:
num = 2;
break;
case RowerDataFlag.ThinkDragFactor:
num = 5;
break;
default:
break;
}
@@ -288,7 +343,9 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
//单周期能耗
SingleEnergy = 8192,
//拉力曲綫
Pull = 16384
Pull = 16384,
//Think 阻力
ThinkDragFactor = 32768
}