-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainwindow.cpp
More file actions
131 lines (105 loc) · 3.21 KB
/
Mainwindow.cpp
File metadata and controls
131 lines (105 loc) · 3.21 KB
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
#include "Mainwindow.hpp"
#include "ui_Mainwindow.h"
// Rossi
// Const
const char *CommandCycleColors = "\x1C\x2C\x5C";
const char *CommandSetColor = "\x1C\x2C\x4C";
const char *CommandCrazyMode = "\x1C\x2C\x6C";
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, _ui(new Ui::MainWindow)
{
const QBluetoothAddress BluetoothAddress = QBluetoothAddress("98D331406684");
_ui->setupUi(this);
_liveColorMode = false;
_bluetoothSocket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
_bluetoothSocket->connectToService(BluetoothAddress, QBluetoothUuid::SerialPort);
}
MainWindow::~MainWindow()
{
_bluetoothSocket->disconnectFromService();
delete _bluetoothSocket;
delete _ui;
}
void MainWindow::on_pressMeButton_clicked()
{
checkForBluetoothErrors();
_bluetoothSocket->write(CommandCycleColors, qstrlen(CommandCycleColors));
}
void MainWindow::on_setLedsColorPushButton_clicked()
{
setBluetoothColor(_ui->redColorSpinBox->value(), _ui->greenColorSpinBox->value(), _ui->blueColorSpinBox->value());
}
void MainWindow::on_redColorSpinBox_valueChanged()
{
if (_liveColorMode) {
setBluetoothColor(_ui->redColorSpinBox->value(), _ui->greenColorSpinBox->value(), _ui->blueColorSpinBox->value());
}
}
void MainWindow::on_greenColorSpinBox_valueChanged()
{
if (_liveColorMode) {
setBluetoothColor(_ui->redColorSpinBox->value(), _ui->greenColorSpinBox->value(), _ui->blueColorSpinBox->value());
}
}
void MainWindow::on_blueColorSpinBox_valueChanged()
{
if (_liveColorMode) {
setBluetoothColor(_ui->redColorSpinBox->value(), _ui->greenColorSpinBox->value(), _ui->blueColorSpinBox->value());
}
}
void MainWindow::on_redHorizontalSlider_sliderMoved(int position)
{
_ui->redColorSpinBox->setValue(position);
}
void MainWindow::on_greenHorizontalSlider_sliderMoved(int position)
{
_ui->greenColorSpinBox->setValue(position);
}
void MainWindow::on_blueHorizontalSlider_sliderMoved(int position)
{
_ui->blueColorSpinBox->setValue(position);
}
void MainWindow::on_liveColorModePushButton_clicked()
{
_liveColorMode = !_liveColorMode;
_ui->actionLive_Color_Mode->setChecked(_liveColorMode);
if (_liveColorMode) {
_ui->liveColorModePushButton->setStyleSheet("QPushButton {background: green}");
} else {
_ui->liveColorModePushButton->setStyleSheet("QPushButton {background: red}");
}
}
void MainWindow::on_actionLive_Color_Mode_toggled(bool arg1)
{
_liveColorMode = arg1;
}
void MainWindow::on_actionExit_triggered()
{
QApplication::quit();
}
void MainWindow::on_actionCrazy_Mode_triggered()
{
checkForBluetoothErrors();
_bluetoothSocket->write(CommandCrazyMode, qstrlen(CommandCrazyMode));
}
void MainWindow::checkForBluetoothErrors()
{
if (_bluetoothSocket->error() != -2) {
QMessageBox messageBox;
messageBox.critical(nullptr, "BLT Error", _bluetoothSocket->errorString());
messageBox.setFixedSize(500, 200);
}
}
void MainWindow::setBluetoothColor(char redValue, char greenValue, char blueValue)
{
char *stringToSend = new char[6];
checkForBluetoothErrors();
stringToSend[0] = CommandSetColor[0];
stringToSend[1] = CommandSetColor[1];
stringToSend[2] = CommandSetColor[2];
stringToSend[3] = redValue;
stringToSend[4] = greenValue;
stringToSend[5] = blueValue;
_bluetoothSocket->write(stringToSend, 6);
}