Przeglądaj źródła

added hr from polar via bluetooth

Marcel Zickler 3 lat temu
rodzic
commit
d543ae2455

Plik diff jest za duży
+ 6 - 3
Assembly-CSharp-Editor.csproj


Plik diff jest za duży
+ 6 - 3
Assembly-CSharp.csproj


+ 0 - 7
Assets/MeshCombiner/HDRP/Mesh Combiner_2019.3.2_HDRP.unitypackage.meta

@@ -1,7 +0,0 @@
-fileFormatVersion: 2
-guid: 5147c378a83cc5247ba7d765c8e6b7ac
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 7
Assets/MeshCombiner/Standard/Mesh Combiner_2018.4.15_Standard.unitypackage.meta

@@ -1,7 +0,0 @@
-fileFormatVersion: 2
-guid: c14e2c1b3f66c914eadda6e37fd68cea
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 7
Assets/MeshCombiner/URP/Mesh Combiner_2019.3.2_URP.unitypackage.meta

@@ -1,7 +0,0 @@
-fileFormatVersion: 2
-guid: fd04eeb770a55ad479ca27b18678b930
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 7 - 2
Assets/Scripts/Logging/Data/BikeSensorDataLogger.cs

@@ -40,6 +40,9 @@ namespace Logging.Data
     {
         public override string Key => "bike_sensor_data";
 
+        [Tooltip("Uses Heart Rate transmitted by bluetooth instead of ANT+")]
+        public bool usePolarHeartRate;
+
         private BikeSensorData bikeSensorData;
 
         public override void Start()
@@ -50,14 +53,16 @@ namespace Logging.Data
 
         private void Update()
         {
-            var hr = (int) (bikeSensorData.HrData?.HeartRate ?? -1);
+            var hr = usePolarHeartRate
+                ? bikeSensorData.PolarData?.Hr ?? -1
+                : (int) (bikeSensorData.HrData?.HeartRate ?? -1);
             var speed = bikeSensorData.SpeedData?.SpeedKmh ?? -1f;
             var cadence = bikeSensorData.PowermeterData?.InstantaneousCadence ?? -1f;
             var power = bikeSensorData.PowermeterData?.InstantaneousPower ?? -1f;
             var torque = bikeSensorData.PowermeterData?.CrankTorque ?? -1f;
             Log(new BikeSensorDataLog(Helpers.RoundToLong(Time.time * 1000), speed, cadence, hr, torque, power));
         }
-        
+
 
         public override IEnumerable<BikeSensorDataLog> ReadLog(IEnumerable<IEnumerable<string>> lines)
         {

+ 31 - 0
Assets/Scripts/Sensors/Polar/PolarHRData.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Sensors.Polar
+{
+    public readonly struct HRData
+    {
+        public List<long> RrsMs { get; }
+        public int HeartRate { get; }
+
+        HRData(List<long> rrsMs, int heartRate)
+        {
+            RrsMs = rrsMs;
+            HeartRate = heartRate;
+        }
+
+        public static HRData FromString(string s)
+        {
+            var data = s.Split(';');
+            if (data.Length == 2)
+            {
+                var hr = int.Parse(data[0]);
+                var values = data[1].Split(',').Select(value => long.Parse(value)).ToList();
+                return new HRData(values, hr);
+            }
+
+            throw new FormatException("HRData String has wrong format");
+        }
+    }
+}

+ 3 - 0
Assets/Scripts/Sensors/Polar/PolarHRData.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: e8b61a44ea0f4ec19eeda185fb6646db
+timeCreated: 1620730121

+ 12 - 1
Assets/Scripts/Sensors/Polar/PolarReceiver.cs

@@ -25,6 +25,7 @@ namespace Sensors.Polar
     {
         public Vector3 Acc;
         public float EcgValue;
+        public int Hr;
     }
 
     public class PolarReceiver
@@ -34,9 +35,12 @@ namespace Sensors.Polar
 
         private readonly Subject<EcgData> rawEcgDataSubject = new Subject<EcgData>();
         private readonly Subject<AccData> rawAccDataSubject = new Subject<AccData>();
+        private readonly Subject<HRData> rawHRDataSubject = new Subject<HRData>();
 
         public IObservable<EcgData> RawEcgData => rawEcgDataSubject.AsObservable();
         public IObservable<AccData> RawAccData => rawAccDataSubject.AsObservable();
+        
+        public IObservable<HRData> RawHRData => rawHRDataSubject.AsObservable();
 
         public PolarSensorConfig SensorConfig { get; private set; }
         public PolarSensorData SensorData => sensorData;
@@ -48,7 +52,7 @@ namespace Sensors.Polar
 
         public void StartListening()
         {
-            connection = new UdpConnection(SensorConfig.ipAddress, SensorConfig.port, OnAccData, OnEcgData);
+            connection = new UdpConnection(SensorConfig.ipAddress, SensorConfig.port, OnAccData, OnEcgData, OnHRData);
             connection.Listen();
             Debug.Log("PolarReceiver: Listening!");
         }
@@ -57,6 +61,7 @@ namespace Sensors.Polar
         {
             rawAccDataSubject.Dispose();
             rawEcgDataSubject.Dispose();
+            rawHRDataSubject.Dispose();
             connection?.StopListening();
         }
 
@@ -80,5 +85,11 @@ namespace Sensors.Polar
             rawEcgDataSubject.OnNext(data);
             sensorData.EcgValue = data.Values[0]; //TODO
         }
+        
+        private void OnHRData(HRData data)
+        {
+            rawHRDataSubject.OnNext(data);
+            sensorData.Hr = data.HeartRate;
+        }
     }
 }

+ 4 - 2
Assets/Scripts/Sensors/Polar/UdpConnection.cs

@@ -17,11 +17,13 @@ namespace Sensors.Polar
         private bool listening = false;
         private Action<AccData> onAccData;
         private Action<EcgData> onEcgData;
+        private Action<HRData> onHRData;
 
-        public UdpConnection(String ipAddress, int port, Action<AccData> onAccData, Action<EcgData> onEcgData)
+        public UdpConnection(String ipAddress, int port, Action<AccData> onAccData, Action<EcgData> onEcgData, Action<HRData> onHrData)
         {
             this.onAccData = onAccData;
             this.onEcgData = onEcgData;
+            this.onHRData = onHrData;
             var parsedAddress = IPAddress.Parse(ipAddress);
             client = new UdpClient(new IPEndPoint(parsedAddress, port));
         }
@@ -46,7 +48,7 @@ namespace Sensors.Polar
                         onEcgData(EcgData.FromString(data[1]));
                     }else if (name.Equals("HR"))
                     {
-                        //TODO
+                        onHRData(HRData.FromString(data[1]));
                     }
                 
                 }

Plik diff jest za duży
+ 6 - 3
SteamVR.csproj


Plik diff jest za duży
+ 6 - 3
SteamVR_Editor.csproj


Plik diff jest za duży
+ 6 - 3
SteamVR_Input_Editor.csproj


Plik diff jest za duży
+ 6 - 3
SteamVR_Windows_EditorHelper.csproj


BIN
obj/Debug/Assembly-CSharp.csprojAssemblyReference.cache


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików