适配速度计和踏频计

This commit is contained in:
suntao committed 2021-08-31 09:09:49 +08:00
1 parent f14a071179
commit 29aef943b9
8 files changed
+84 -12

No files matched your search

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ANT_Managed_Library;
using UnityEngine;
namespace Assets.Scripts.Devices.Ant
{
@@ -86,6 +87,7 @@ namespace Assets.Scripts.Devices.Ant
deviceList.Add(new CadenceDevice(""));
deviceList.Add(new HeartRateDevice(""));
deviceList.Add(new BikeSpdCadDevice(""));
deviceList.Add(new SpeedDevice(""));
var timer = new System.Timers.Timer(1000);
timer.AutoReset = true;
@@ -343,6 +345,7 @@ namespace Assets.Scripts.Devices.Ant
case SensorType.None:
break;
case SensorType.Cadence:
Debug.LogError("发现踏频设备"+id);
device = new CadenceDevice(id);
break;
case SensorType.HeartRate:
@@ -352,6 +355,7 @@ namespace Assets.Scripts.Devices.Ant
device = new PowerDevice(id);
break;
case SensorType.Speed:
device = new SpeedDevice(id);
break;
case SensorType.SpeedCadence:
device = new BikeSpdCadDevice(id);
+1 -1
View File
@@ -29,7 +29,7 @@ namespace Assets.Scripts.Devices.Ant
private RotationData _rotationData = new RotationData();
public CadenceDevice(string id)
: base(id, "Ant+ Cadence", racerSportType.Biking, SensorType.Cadence)
: base(id, "Ant+ Cadence", racerSportType.Unknown, SensorType.Cadence)
{
Priority = 2;
//if (speedSensor.isInUse)
+59
View File
@@ -0,0 +1,59 @@
using ANT_Managed_Library;
using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.Devices.Ant.LegacyPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant
{
public class SpeedDevice : AbstractAntDevice, ISpeedDevice
{
public double Speed { get; set; }
private DateTime now = DateTime.Now;
public const double DEFAULT_WHEEL_CIRCUMFERENCE_m = 2096; //Average 700cx23mm road tire
public readonly double wheelCircumfrence_m;
private RotationData _rotationData = new RotationData();
public SpeedDevice(string id, double wheelCircumfrence_m = DEFAULT_WHEEL_CIRCUMFERENCE_m)
: base(id, "Ant+ Speed", racerSportType.Unknown, SensorType.Speed)
{
Priority = 2;
this.wheelCircumfrence_m = wheelCircumfrence_m;
}
public override void handleChannelResponse(ANT_Response response)
{
//throw new NotImplementedException();
var page = response.messageContents.Skip(1).ToArray();
int? value = _rotationData.CalculateRpm(now, page[4] | page[5] << 8, page[6] | page[7] << 8);
if (value.HasValue)
{
Speed = DoubleExtensions.CalculateSpeed(value.Value, wheelCircumfrence_m);
}
else
{
Speed = 0;
}
Console.WriteLine(Math.Round(Speed, 1));
}
protected override AntChannelProfile getDefaultSearchProfile()
{
//throw new NotImplementedException();
return new AntChannelProfile()
{
rfOffset = 57,
transType = 0,
deviceType = 123,
deviceNumber = 0,
messagePeriod = 8118,
pairingEnabled = false
};
}
}
}