划船机优化
This commit is contained in:
1 parent
2f64aa494f
commit
87a0e7fb6d
8 files changed
+109
-80
No files matched your search
@@ -61,7 +61,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
{
|
||||
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"))
|
||||
if (device.Name.Contains("Think") || device.Name.Contains("PF"))
|
||||
{
|
||||
return thinkRes;
|
||||
}
|
||||
@@ -93,6 +93,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
public event EventHandler PullChanged;
|
||||
//开始事件
|
||||
public event EventHandler StartEvent;
|
||||
//日志事件
|
||||
public event EventHandler LogEvent;
|
||||
private ushort _pullValue;
|
||||
public ushort PullValue
|
||||
{
|
||||
@@ -114,6 +116,7 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
}
|
||||
private string[] deviceNamePool = new string[] {"Think","PF" };
|
||||
private List<ushort> tempPullList = new List<ushort>();
|
||||
|
||||
public void HandleAttributeReceived(byte[] data)
|
||||
{
|
||||
@@ -158,7 +161,8 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
output += $" 总距离{ vvv }米";
|
||||
if (vvv < 10)
|
||||
{
|
||||
App.cacheList.Add(DateTime.Now.ToString() + ":" + output);
|
||||
LogEvent?.Invoke(DateTime.Now.ToString() + ":" + output,null);
|
||||
//App.cacheList.Add(DateTime.Now.ToString() + ":" + output);
|
||||
}
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.TotalDistance);
|
||||
|
||||
@@ -190,9 +194,11 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ResistanceLevel))
|
||||
{
|
||||
this.commonRes = BitConvertHelper.ToInt16(data, b);
|
||||
var newRes = BitConvertHelper.ToInt16(data, b);
|
||||
var resChanged = newRes != this.commonRes;
|
||||
this.commonRes = newRes;
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
|
||||
if (device != null && deviceNamePool.FirstOrDefault(x => device.Name.ToLower().Contains(x.ToLower())) == null && RowerResChanged != null)
|
||||
if (resChanged && device != null && deviceNamePool.FirstOrDefault(x => device.Name.ToLower().Contains(x.ToLower())) == null && RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(this.commonRes, null);
|
||||
}
|
||||
@@ -229,9 +235,11 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ThinkDragFactor))
|
||||
{
|
||||
var originRes = BitConvertHelper.ToInt16(data, b + 1);
|
||||
var thinkResChanged = originRes != this.thinkRes;
|
||||
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 && deviceNamePool.FirstOrDefault(x=>device.Name.ToLower().Contains(x.ToLower()))!=null && RowerResChanged != null)
|
||||
if (thinkResChanged && device != null && deviceNamePool.FirstOrDefault(x=>device.Name.ToLower().Contains(x.ToLower()))!=null && RowerResChanged != null)
|
||||
{
|
||||
RowerResChanged.Invoke(this.thinkRes, null);
|
||||
}
|
||||
@@ -239,17 +247,15 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.Pull))
|
||||
{
|
||||
List<ushort> list = new List<ushort>();
|
||||
for (int pullB = 4; pullB < data.Length; pullB += 2)
|
||||
{
|
||||
var val = BitConverter.ToUInt16(data, pullB);
|
||||
val = Convert.ToUInt16(((double)val) /9.8f);
|
||||
list.Add(val);
|
||||
tempPullList.Add(val);
|
||||
PullValue = val;
|
||||
|
||||
}
|
||||
if (pullList == null) pullList = new List<ushort>();
|
||||
foreach (var pull in list)
|
||||
foreach (var pull in tempPullList)
|
||||
{
|
||||
if (pull == 0)
|
||||
{
|
||||
@@ -262,10 +268,11 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
}
|
||||
pullList.Add(pull);
|
||||
}
|
||||
tempPullList.Clear();
|
||||
//Debug.Log("拉力:" + string.Join(",",list));
|
||||
}
|
||||
}
|
||||
List<ushort> pullList;
|
||||
List<ushort> pullList { get; set; }
|
||||
public void Reset()
|
||||
{
|
||||
this.StrokeRate = 0;
|
||||
|
||||
Reference in new issue
Block a user