123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using Controller.Bicycle;
- using Sensors;
- using TMPro;
- using UnityEngine;
- namespace Display
- {
- public class BikeDataDisplay : MonoBehaviour
- {
- public bool usePolarForHeartRate = true;
- public TextMeshProUGUI cadenceDisplay;
- public TextMeshProUGUI heartRateDisplay;
- public TextMeshProUGUI powerDisplay;
- [Header("Speed")] public RbBicycleController bicycleController;
- public TextMeshProUGUI speedDisplay;
- public bool useSpeedFromBicycleController = true;
- public TextMeshProUGUI torqueDisplay;
- private bool cadenceDisplayAvailable;
- private bool heartRateDisplayAvailable;
- private bool powerDisplayAvailable;
- private BikeSensorData sensorData;
- private bool speedDisplayAvailable;
- private bool torqueDisplayAvailable;
- // Start is called before the first frame update
- private void Start()
- {
- sensorData = BikeSensorData.Instance;
- speedDisplayAvailable = speedDisplay != null;
- powerDisplayAvailable = powerDisplay != null;
- torqueDisplayAvailable = torqueDisplay != null;
- cadenceDisplayAvailable = cadenceDisplay != null;
- heartRateDisplayAvailable = heartRateDisplay != null;
- }
- // Update is called once per frame
- private void Update()
- {
- var bikeSpeed = useSpeedFromBicycleController
- ? bicycleController.CurrentSpeedKph
- : sensorData.SpeedData?.SpeedKmh ?? 0f;
- if (speedDisplayAvailable) speedDisplay.text = $"{bikeSpeed:n2} km/h";
- if (powerDisplayAvailable) powerDisplay.text = $"{sensorData.PowermeterData?.InstantaneousPower ?? 0f:0} W";
- if (cadenceDisplayAvailable)
- cadenceDisplay.text = $"{sensorData.PowermeterData?.InstantaneousCadence ?? 0f:0} rpm";
- if (torqueDisplayAvailable) torqueDisplay.text = $"{sensorData.PowermeterData?.CrankTorque ?? 0f:F2} Nm";
- if (heartRateDisplayAvailable)
- heartRateDisplay.text =
- $"{(usePolarForHeartRate ? sensorData.PolarData?.Hr : sensorData.HrData?.HeartRate) ?? 0:0} bpm";
- }
- }
- }
|