Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
DisplayManager.cpp
Go to the documentation of this file.
1
19
20#include "DisplayManager.hpp"
21#include <QDebug>
22#include <QPushButton>
23
31DisplayManager::DisplayManager(Ui::CarManager *ui, QObject *parent)
32 : QObject(parent), m_ui(ui) {
33 // Ensure the labels are initialized
34 if (!m_ui->speedLabel || !m_ui->rpmLabel || !m_ui->directionLabel ||
35 !m_ui->timeLabel || !m_ui->wifiLabel || !m_ui->temperatureLabel ||
36 !m_ui->batteryLabel) {
37 qDebug() << "Error: Labels not initialized in the UI form!";
38 return;
39 }
40
41 // Set initial values for the labels
42 m_ui->speedLabel->setText("0");
43 m_ui->rpmLabel->setText("0.00");
44 m_ui->directionLabel->setText("D");
45 m_ui->timeLabel->setText("--:--:--");
46 m_ui->wifiLabel->setText("đŸ“ļ Disconnected");
47 m_ui->temperatureLabel->setText("đŸŒĄī¸ N/A");
48 m_ui->batteryLabel->setText("--% 🔋");
49 m_ui->speedMetricsLabel->setText("KM/H");
50 m_ui->leftBlinkerLabel->setVisible(false);
51 m_ui->rightBlinkerLabel->setVisible(false);
52 m_ui->lowBatteryLabel->setVisible(false);
53
54 // Directly connect button clicks to signals
55 connect(m_ui->toggleDrivingModeButton, &QPushButton::clicked, this,
57 connect(m_ui->toggleMetricsButton, &QPushButton::clicked, this,
59}
60
68void DisplayManager::updateCanBusData(float speed, int rpm) {
69 m_ui->speedLabel->setText(QString::number(static_cast<int>(speed)));
70 m_ui->rpmLabel->setText(
71 QString::number(static_cast<double>(rpm) / 1000, 'f', 2));
72}
73
82 int steeringAngle) {
83 QString directionText;
84 switch (direction) {
86 directionText = "D";
87 break;
89 directionText = "R";
90 break;
92 default:
93 directionText = "D";
94 break;
95 }
96
97 m_ui->directionLabel->setText(directionText);
98 if (steeringAngle > 0) {
99 m_ui->leftBlinkerLabel->setVisible(false);
100 m_ui->rightBlinkerLabel->setVisible(true);
101 } else if (steeringAngle < 0) {
102 m_ui->rightBlinkerLabel->setVisible(false);
103 m_ui->leftBlinkerLabel->setVisible(true);
104 } else {
105 m_ui->leftBlinkerLabel->setVisible(false);
106 m_ui->rightBlinkerLabel->setVisible(false);
107 }
108}
109
118void DisplayManager::updateSystemTime(const QString &currentDate,
119 const QString &currentTime,
120 const QString &currentDay) {
121 m_ui->dateLabel->setText(currentDate);
122 m_ui->timeLabel->setText(currentTime);
123 m_ui->weekDayLabel->setText(currentDay);
124}
125
133void DisplayManager::updateWifiStatus(const QString &status,
134 const QString &wifiName) {
135 QString wifiDisplay = status;
136 if (!wifiName.isEmpty()) {
137 wifiDisplay += " (" + wifiName + ")";
138 }
139 m_ui->wifiLabel->setText("đŸ“ļ " + wifiName);
140}
141
148void DisplayManager::updateTemperature(const QString &temperature) {
149 m_ui->temperatureLabel->setText("đŸŒĄī¸ " + temperature);
150}
151
158void DisplayManager::updateBatteryPercentage(float batteryPercentage) {
159 if (batteryPercentage < 20.0) {
160 m_ui->lowBatteryLabel->setVisible(true);
161 }
162 m_ui->batteryLabel->setText(QString::number(batteryPercentage, 'f', 1) +
163 "% " + (batteryPercentage > 20.0 ? "🔋" : "đŸĒĢ"));
164}
165
172void DisplayManager::updateMileage(double mileage) {
173 m_ui->mileageLabel->setText(QString::number(static_cast<int>(mileage)) +
174 " m");
175}
176
183void DisplayManager::updateIpAddress(const QString &ipAddress) {
184 m_ui->ipAddressLabel->setText("IP " + ipAddress);
185}
186
194 QString modeText;
195 switch (newMode) {
197 modeText = "manual";
198 break;
200 modeText = "automatic";
201 break;
202 }
203 m_ui->drivingModeLabel->setText("Mode: " + modeText);
204}
205
213 QString themeText;
214 switch (newTheme) {
216 themeText = "Dark";
217 break;
219 themeText = "Light";
220 break;
221 }
222 m_ui->clusterThemeLabel->setText("Theme: " + themeText);
223}
224
232 QString metricsText;
233 switch (newMetrics) {
235 metricsText = "km/h";
236 break;
238 metricsText = "mph";
239 break;
240 }
241 m_ui->clusterMetricsLabel->setText("Metrics: " + metricsText);
242 m_ui->speedMetricsLabel->setText(metricsText.toUpper());
243}
Definition of the DisplayManager class.
DrivingMode
Enum class for the driving mode.
Definition enums.hpp:24
CarDirection
Enum class for the car direction.
Definition enums.hpp:30
ClusterTheme
Enum class for the cluster theme.
Definition enums.hpp:26
ClusterMetrics
Enum class for the cluster metrics.
Definition enums.hpp:28
void updateTemperature(const QString &temperature)
Updates the temperature on the display.
void updateDrivingMode(DrivingMode newMode)
Updates the driving mode on the display.
void updateClusterTheme(ClusterTheme newTheme)
Updates the cluster theme on the display.
void updateIpAddress(const QString &ipAddress)
Updates the IP address on the display.
void clusterMetricsToggled()
Signal emitted when the cluster metrics are toggled.
void drivingModeToggled()
Signal emitted when the driving mode is toggled.
Ui::CarManager * m_ui
Pointer to the UI object.
void updateSystemTime(const QString &currentDate, const QString &currentTime, const QString &currentDay)
Updates the system time on the display.
void updateBatteryPercentage(float batteryPercentage)
Updates the battery percentage on the display.
void updateCanBusData(float speed, int rpm)
Updates the CAN bus data on the display.
void updateClusterMetrics(ClusterMetrics newMetrics)
Updates the cluster metrics on the display.
void updateEngineData(CarDirection direction, int steeringAngle)
Updates the engine data on the display.
DisplayManager(Ui::CarManager *ui, QObject *parent=nullptr)
Construct a new DisplayManager object.
void updateMileage(double mileage)
Updates the mileage on the display.
void updateWifiStatus(const QString &status, const QString &wifiName)
Updates the WiFi status on the display.