forked from UCR-Solar-Car/DriverInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gears.cpp
64 lines (47 loc) · 1.51 KB
/
gears.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
#include "gears.h"
#include "scaler.h"
Gears::Gears() : gear(PARK), cruise(OFF) {}
void Gears::setup(Ui::MainWindow *ui, uint16_t height, uint16_t width) {
this->ui = ui;
park = QPixmap(":/icons/parking.png");
drive = QPixmap(":/icons/drive.png");
neutral = QPixmap(":/icons/neutral.png");
reverse = QPixmap(":/icons/reverse.png");
ui->cruise_control->resize(width * 10 / 100, width * 10 / 100);
ui->cruise_control->move((width - (width * ICON_COUNT) / 10) / 2 + (ui->cruise_control->width() * CRUISE_CONTROL_ICON), 0);
cruise_control = QPixmap(":/icons/cruise.png");
ui->park_label->resize(100, 100);
ui->park_label->move(width / 2 - ui->park_label->width() / 2,
height - ui->park_label->height() - 100);
this->ui->park_label->setPixmap(park);
}
void Gears::switch_gears(gears state) {
if (state == PARK) {
gear = state;
cruise_off();
this->ui->park_label->setPixmap(park);
} else if (state == DRIVE) {
gear = state;
this->ui->park_label->setPixmap(drive);
} else if (state == NEUTRAL) {
gear = state;
cruise_off();
this->ui->park_label->setPixmap(neutral);
} else if (state == REVERSE) {
gear = state;
cruise_off();
this->ui->park_label->setPixmap(reverse);
}
}
void Gears::cruise_on() {
if (gear == DRIVE) {
this->cruise = ON;
this->ui->cruise_control->setPixmap(cruise_control);
} else {
cruise_off();
}
}
void Gears::cruise_off() {
this->cruise = OFF;
this->ui->cruise_control->setText("OFF");
}