-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathledostalker.cpp
More file actions
48 lines (38 loc) · 1.15 KB
/
ledostalker.cpp
File metadata and controls
48 lines (38 loc) · 1.15 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
#include "ledostalker.h"
#include <QThread>
#include <QDebug>
class LEDOSTalkerPrivate {
public:
LEDOSTalkerPrivate() {
serial = NULL;
}
~LEDOSTalkerPrivate() {
if( serial != NULL && serial->isOpen() )
serial->close();
}
QSerialPort *serial;
};
LEDOSTalker::LEDOSTalker(QObject *parent) : d_ptr(new LEDOSTalkerPrivate)
{
}
void LEDOSTalker::serial(QString portName)
{
if( d_ptr->serial != NULL && d_ptr->serial->portName() != portName && d_ptr->serial->isOpen() )
d_ptr->serial->close();
d_ptr->serial = new QSerialPort(portName);
d_ptr->serial->setBaudRate(115200);
d_ptr->serial->open(QSerialPort::WriteOnly);
QThread::msleep(1000);
d_ptr->serial->write("effect color\n");
d_ptr->serial->flush();
}
void LEDOSTalker::color(QColor color)
{
QString command = QString("b%1%2%3\n");
command = command.arg(color.red(), 2, 16, QChar('0'));
command = command.arg(color.green(), 2, 16, QChar('0'));
command = command.arg(color.blue(), 2, 16, QChar('0'));
// qDebug() << command;
d_ptr->serial->write( command.toStdString().c_str() );
d_ptr->serial->flush();
}