-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsa_radio_window.cpp
executable file
·365 lines (309 loc) · 10 KB
/
psa_radio_window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#include "psa_radio_window.h"
#include "qicon.h"
#include "ui_psa_radio_window.h"
#include <QPixmap>
#include <iostream>
static int clock_state = 0;
static int old_signal_str = 0;
static enum psa_radio_source radio_source = PSA_RADIO_NONE;
static QPixmap* signal_0, *signal_1, *signal_2, *signal_3, *signal_4;
psa_radio_window::psa_radio_window(QWidget *parent) :
QWidget(parent),
ui(new Ui::psa_radio_window)
{
ui->setupUi(this);
this->preset_labels.resize(6);
this->preset_labels[0] = ui->preset_1;
this->preset_labels[1] = ui->preset_2;
this->preset_labels[2] = ui->preset_3;
this->preset_labels[3] = ui->preset_4;
this->preset_labels[4] = ui->preset_5;
this->preset_labels[5] = ui->preset_6;
this->preset_list.resize(6);
for(int i = 0; i< 6;++i)
{
this->preset_list[i] = "";
}
this->ui->big_clock_label->hide();
this->ui->big_date_label->hide();
this->ui->curr_band->hide();
this->ui->presets_window->hide();
this->ui->radio_freq->hide();
this->ui->station_name->hide();
this->ui->signal_icon->hide();
this->ui->cd_icon->hide();
this->ui->cd_tracks->hide();
this->clock_timer = new QTimer(this);
signal_0 = new QPixmap(QIcon(":/symbols/icons/signal-0.svg").pixmap(QSize(37,37)));
signal_1 = new QPixmap(QIcon(":/symbols/icons/signal-1.svg").pixmap(QSize(37,37)));
signal_2 = new QPixmap(QIcon(":/symbols/icons/signal-2.svg").pixmap(QSize(37,37)));
signal_3 = new QPixmap(QIcon(":/symbols/icons/signal-3.svg").pixmap(QSize(37,37)));
signal_4 = new QPixmap(QIcon(":/symbols/icons/signal-4.svg").pixmap(QSize(37,37)));
this->ui->signal_icon->setPixmap(*signal_0);
//connect(this->clock_timer, &QTimer::timeout, this, &psa_radio_window::change_clock_state);
//this->clock_timer->start(1000);
}
void psa_radio_window::receive_radio_data(psa_radio_data_t radio_data)
{
if(radio_source == PSA_RADIO_TUNER)
{
QString stat_name = QString::fromLocal8Bit(radio_data.station);
change_station(stat_name);
//#ifdef PSA_SIMULATE
change_freq((float)radio_data.freq/100);
//#else
// change_freq((float)radio_data.freq * 0.05 + 50);
//#endif
change_preset(radio_data.preset);
change_band((enum psa_radio_band)radio_data.band);
uint8_t new_signal_str = radio_data.signal_strength;
if(new_signal_str != old_signal_str)
{
switch(new_signal_str)
{
default:
case 0:
case 1:
case 2:
this->ui->signal_icon->setPixmap(*signal_0);
break;
case 3:
case 4:
case 5:
this->ui->signal_icon->setPixmap(*signal_1);
break;
case 6:
case 7:
case 8:
this->ui->signal_icon->setPixmap(*signal_2);
break;
case 9:
case 10:
case 11:
this->ui->signal_icon->setPixmap(*signal_3);
break;
case 12:
case 13:
case 14:
case 15:
this->ui->signal_icon->setPixmap(*signal_4);
break;
}
old_signal_str = new_signal_str;
}
}
}
void psa_radio_window::receive_cd_player_data(psa_cd_player_data_t cd_data)
{
if(radio_source == PSA_RADIO_INTERNAL)
{
if(cd_data.status & PSA_CD_PLAYER_ERROR)
{
this->ui->cd_tracks->setText("CD Error!");
}
else if(cd_data.status & PSA_CD_PLAYER_LOADING)
{
this->ui->cd_tracks->setText("CD Loading...");
}
else if(cd_data.status & PSA_CD_PLAYER_EJECTING)
{
this->ui->cd_tracks->setText("Ejecting...");
}
else{
this->ui->radio_freq->setText(QString::asprintf("%02d:%02d", cd_data.current_minute, cd_data.current_second));
this->ui->cd_tracks->setText(QString::asprintf("Track %d/%d", cd_data.current_track, cd_data.total_tracks));
}
}
}
void psa_radio_window::change_clock_state()
{
if(clock_state)
{
clock_state = 0;
}
else{
clock_state = 1;
}
}
void psa_radio_window::receive_time_data(psa_time_data_t time_data)
{
if(time_data.valid_time)
{
this->ui->big_clock_label->setText(QString::asprintf("%02d:%02d:%02d", time_data.hour, time_data.minutes, time_data.seconds));
this->ui->big_date_label->setText(QString::asprintf("%02d. %02d. %4d", time_data.day, time_data.month + 1, time_data.year + 1900));
}
else{
this->ui->big_clock_label->setText("");
this->ui->big_date_label->setText("");
}
}
void psa_radio_window::receive_headunit_data(psa_headunit_data_t headunit_data)
{
if(headunit_data.unit_powered_on == 0)
{
change_source(PSA_RADIO_NONE);
}
else{
change_source((enum psa_radio_source)headunit_data.source);
}
if(headunit_data.cd_present)
{
ui->cd_icon->show();
}
else{
ui->cd_icon->hide();
}
}
void psa_radio_window::change_band(enum psa_radio_band band)
{
// <html><head/><body><p><span style=" font-size:14pt;">FM 2</span></p></body></html>
if(radio_source == PSA_RADIO_TUNER)
{
switch(band)
{
case PSA_AM_1:
ui->curr_band->setText("AM 1");
break;
case PSA_AM_2:
ui->curr_band->setText("AM 2");
break;
case PSA_AM_3:
ui->curr_band->setText("AM 3");
break;
case PSA_FM_1:
ui->curr_band->setText("FM 1");
break;
case PSA_FM_2:
ui->curr_band->setText("FM 2");
break;
case PSA_FM_3:
ui->curr_band->setText("FM 3");
break;
case PSA_FM_AST:
ui->curr_band->setText("FMast");
break;
}
}
}
void psa_radio_window::change_station(QString name)
{
// this->station_name = name;
// name.prepend("<html><head/><body><p align=\"center\"><span style=\" font-size:55pt; font-weight:600;\">");
// name.append("</span></p></body></html>");
ui->station_name->setText(name);
}
void psa_radio_window::change_freq(float freq)
{
ui->radio_freq->setText(QString::asprintf("%.2f", freq));
}
void psa_radio_window::change_radio_state(bool state)
{
if(state)
{
this->ui->big_clock_label->hide();
this->ui->big_date_label->hide();
this->ui->curr_band->show();
this->ui->presets_window->show();
this->ui->radio_freq->show();
this->ui->station_name->show();
}
else{
this->ui->big_clock_label->show();
this->ui->big_date_label->show();
this->ui->curr_band->hide();
this->ui->presets_window->hide();
this->ui->radio_freq->hide();
this->ui->station_name->hide();
}
}
void psa_radio_window::change_source(enum psa_radio_source new_source)
{
radio_source = new_source;
switch(new_source)
{
case PSA_RADIO_NONE:
default:
change_station(QString::fromStdString("Radio OFF"));
this->ui->big_clock_label->show();
this->ui->big_date_label->show();
this->ui->station_name->show();
this->ui->curr_band->hide();
this->ui->presets_window->hide();
this->ui->radio_freq->hide();
this->ui->signal_icon->hide();
this->ui->cd_tracks->hide();
break;
case PSA_RADIO_TUNER:
this->ui->big_clock_label->hide();
this->ui->big_date_label->hide();
this->ui->cd_tracks->hide();
this->ui->signal_icon->show();
this->ui->curr_band->show();
this->ui->presets_window->show();
this->ui->radio_freq->show();
this->ui->station_name->show();
break;
case PSA_RADIO_INTERNAL:
this->ui->big_clock_label->hide();
this->ui->big_date_label->hide();
this->ui->curr_band->hide();
this->ui->presets_window->hide();
this->ui->signal_icon->hide();
this->ui->cd_tracks->show();
this->ui->radio_freq->show();
this->ui->station_name->show();
change_station(QString::fromStdString("CD"));
break;
case PSA_RADIO_EXTERNAL:
this->ui->big_clock_label->hide();
this->ui->big_date_label->hide();
this->ui->curr_band->hide();
this->ui->presets_window->hide();
this->ui->signal_icon->hide();
this->ui->cd_tracks->hide();
this->ui->radio_freq->hide();
this->ui->station_name->show();
change_station(QString::fromStdString("USB"));
break;
case PSA_RADIO_NAVIGATION:
this->ui->big_clock_label->hide();
this->ui->big_date_label->hide();
this->ui->curr_band->hide();
this->ui->presets_window->hide();
this->ui->signal_icon->hide();
this->ui->cd_tracks->hide();
this->ui->radio_freq->hide();
this->ui->station_name->show();
change_station(QString::fromStdString("NAVI"));
break;
}
}
void psa_radio_window::change_preset(int preset)
{
if(this->last_preset != 0)
{
preset_labels[last_preset-1]->setStyleSheet("QLabel{\n margin: 5px;\n color: rgb(255, 255, 255);\n}");
}
if(preset != 0)
{
preset_labels[preset-1]->setStyleSheet("QLabel{\n margin: 5px;\n border: 2px solid white;\nborder-radius: 10px;\n color: rgb(255, 255, 255);\n}");
preset_labels[preset-1]->setText((QString::asprintf("%d - ", preset)) + this->ui->station_name->text());
}
this->last_preset = preset;
}
void psa_radio_window::receive_presets_data(psa_preset_data_t preset_data)
{
for(int i = 0; i< 6;++i)
{
QString temp_name = QString(preset_data.presets[i].preset_name);
if(this->preset_list[i] != temp_name)
{
this->preset_list[i] = temp_name;
preset_labels[i]->setText((QString::asprintf("%d - ", i+1)) + temp_name);
}
}
}
psa_radio_window::~psa_radio_window()
{
delete ui;
}