SensorStatus.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using Controller;
  3. using Controller.Bicycle;
  4. using Display;
  5. using Sensors.ANT;
  6. using Sensors.Polar;
  7. using TMPro;
  8. using Tracking;
  9. using UnityEngine;
  10. using UnityEngine.SceneManagement;
  11. using Valve.VR;
  12. namespace Sensors
  13. {
  14. public class SensorStatus : MonoBehaviour
  15. {
  16. public TextMeshProUGUI speedStatusText;
  17. public TextMeshProUGUI hrStatusText;
  18. public TextMeshProUGUI powerStatusText;
  19. //TODO: add polar text
  20. public SensorBikeController sensorBikeController;
  21. public FrontWheelTracker fwTracker;
  22. public KineticLegTracker legTracker;
  23. public bool waitForTrackers = true;
  24. public bool waitForSpeed = true;
  25. public bool waitForHr = true;
  26. public bool waitForPolar = true;
  27. public bool waitForPower = true;
  28. private SteamVR_TrackedObject fwObject;
  29. private SteamVR_TrackedObject legObject;
  30. private void OnEnable()
  31. {
  32. sensorBikeController.enabled = false;
  33. }
  34. private void Start()
  35. {
  36. fwObject = fwTracker.GetComponent<SteamVR_TrackedObject>();
  37. legObject = legTracker.GetComponent<SteamVR_TrackedObject>();
  38. }
  39. private void Update()
  40. {
  41. var hrData = BikeSensorData.Instance.HrData;
  42. var speedData = BikeSensorData.Instance.SpeedData;
  43. var powerData = BikeSensorData.Instance.PowermeterData;
  44. var polarData = BikeSensorData.Instance.PolarData;
  45. hrStatusText.text = hrData.HasValue
  46. ? $"Heart Rate: Connected ({hrData?.HeartRate})"
  47. : "Heart Rate: Disconnected";
  48. speedStatusText.text =
  49. speedData.HasValue ? $"Speed: Connected ({speedData?.SpeedKmh}) " : "Speed: Disconnected";
  50. powerStatusText.text = powerData.HasValue
  51. ? $"Power/Cadence: Connected ({powerData?.InstantaneousPower})"
  52. : "Power/Cadence: Disconnected";
  53. if (!(waitForTrackers && (!fwObject.isValid || !legObject.isValid)
  54. || waitForSpeed && !speedData.HasValue
  55. || waitForHr && !hrData.HasValue
  56. || waitForPower && !powerData.HasValue
  57. || waitForPolar && !polarData.HasValue) //TODO: check if this works for polar
  58. )
  59. {
  60. //TODO: show text, that we are ready and start on button press
  61. Destroy(gameObject);
  62. }
  63. }
  64. private void OnDestroy()
  65. {
  66. sensorBikeController.enabled = true;
  67. }
  68. }
  69. }