12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using Controller;
- using Controller.Bicycle;
- using Display;
- using Sensors.ANT;
- using Sensors.Polar;
- using TMPro;
- using Tracking;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using Valve.VR;
- namespace Sensors
- {
- public class SensorStatus : MonoBehaviour
- {
- public TextMeshProUGUI speedStatusText;
- public TextMeshProUGUI hrStatusText;
- public TextMeshProUGUI powerStatusText;
- //TODO: add polar text
- public SensorBikeController sensorBikeController;
- public FrontWheelTracker fwTracker;
- public KineticLegTracker legTracker;
-
- public bool waitForTrackers = true;
- public bool waitForSpeed = true;
- public bool waitForHr = true;
- public bool waitForPolar = true;
- public bool waitForPower = true;
- private SteamVR_TrackedObject fwObject;
- private SteamVR_TrackedObject legObject;
- private void OnEnable()
- {
- sensorBikeController.enabled = false;
- }
- private void Start()
- {
- fwObject = fwTracker.GetComponent<SteamVR_TrackedObject>();
- legObject = legTracker.GetComponent<SteamVR_TrackedObject>();
- }
- private void Update()
- {
- var hrData = BikeSensorData.Instance.HrData;
- var speedData = BikeSensorData.Instance.SpeedData;
- var powerData = BikeSensorData.Instance.PowermeterData;
- var polarData = BikeSensorData.Instance.PolarData;
- hrStatusText.text = hrData.HasValue
- ? $"Heart Rate: Connected ({hrData?.HeartRate})"
- : "Heart Rate: Disconnected";
- speedStatusText.text =
- speedData.HasValue ? $"Speed: Connected ({speedData?.SpeedKmh}) " : "Speed: Disconnected";
- powerStatusText.text = powerData.HasValue
- ? $"Power/Cadence: Connected ({powerData?.InstantaneousPower})"
- : "Power/Cadence: Disconnected";
- if (!(waitForTrackers && (!fwObject.isValid || !legObject.isValid)
- || waitForSpeed && !speedData.HasValue
- || waitForHr && !hrData.HasValue
- || waitForPower && !powerData.HasValue
- || waitForPolar && !polarData.HasValue) //TODO: check if this works for polar
- )
- {
- //TODO: show text, that we are ready and start on button press
- Destroy(gameObject);
- }
- }
- private void OnDestroy()
- {
- sensorBikeController.enabled = true;
- }
- }
- }
|