12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using Sensors;
- using TMPro;
- using UnityEngine;
- namespace Display
- {
- 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";
- }
- }
- }
- }
|