123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using TMPro;
- using UnityEngine;
- public class BikeDataDisplay : MonoBehaviour
- {
- [Header("Speed")]
- public TextMeshProUGUI speedDisplay;
-
- [Header("Powermeter")]
- public int powerMeterId = 0;
- public TextMeshProUGUI powerDisplay;
- public TextMeshProUGUI cadenceDisplay;
- public TextMeshProUGUI torqueDisplay;
- [Header("Heart Rate")] public int hrAntId = 0;
- public TextMeshProUGUI heartRateDisplay;
-
- private bool speedDisplayAvailable;
- private bool powerDisplayAvailable;
- private bool cadenceDisplayAvailable;
- private bool torqueDisplayAvailable;
- private bool heartRateDisplayAvailable;
- private BikeSensorData sensorData;
- // Start is called before the first frame update
- void Start()
- {
- sensorData = BikeSensorData.Instance;
- //powermeter and ANT hr only for displaying for now TODO: move to controller if used for controlling
- 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
- 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";
- }
- }
- }
|