12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Sensors;
- using TMPro;
- using UnityEngine;
- namespace Display
- {
- public class BikeDataDisplay : MonoBehaviour
- {
- public TextMeshProUGUI cadenceDisplay;
- private bool cadenceDisplayAvailable;
- public TextMeshProUGUI heartRateDisplay;
- private bool heartRateDisplayAvailable;
- [Header("Heart Rate")] public int hrAntId = 0;
- public TextMeshProUGUI powerDisplay;
- private bool powerDisplayAvailable;
- [Header("Powermeter")] public int powerMeterId = 0;
- private BikeSensorData sensorData;
- [Header("Speed")] public TextMeshProUGUI speedDisplay;
- private bool speedDisplayAvailable;
- public TextMeshProUGUI torqueDisplay;
- private bool torqueDisplayAvailable;
- // Start is called before the first frame update
- private async void Start()
- {
- sensorData = BikeSensorData.Instance;
- //powermeter and ANT hr only for displaying for now TODO: move to controller if used for controlling
- await sensorData.StartListening(powermeterId: powerMeterId, hrAntId: hrAntId);
- speedDisplayAvailable = speedDisplay != null;
- powerDisplayAvailable = powerDisplay != null;
- torqueDisplayAvailable = torqueDisplay != null;
- cadenceDisplayAvailable = cadenceDisplay != null;
- heartRateDisplayAvailable = heartRateDisplay != null;
- }
- // Update is called once per frame
- private void Update()
- {
- //transform.Translate(Vector3.forward * (Time.deltaTime * (speedSensorReceiver?.Speed ?? 0)));
- //bicycleController.SetSpeed(speedSensorReceiver?.Speed ?? 0);
- //bicycleController.SetTorque(powerMeterReceiver?.CrankTorque ?? 0); //TODO crank to wheel torque;
- if (speedDisplayAvailable) speedDisplay.text = $"{sensorData.SpeedData?.SpeedKmh ?? 0f: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 = $"{sensorData.HrData?.HeartRate ?? 0:0} bpm";
- }
- }
- }
|