-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatmolight.cpp
More file actions
80 lines (64 loc) · 1.78 KB
/
atmolight.cpp
File metadata and controls
80 lines (64 loc) · 1.78 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
#include "atmolight.h"
#include <QDebug>
#include <QtDBus/QtDBus>
AtmoLight::AtmoLight(QString portName, QList<int> order, QObject *parent) :
QObject(parent),
m_serialPortName(portName),
m_ledAreaOrderList(order)
{
this->setObjectName(m_serialPortName);
m_serialPort.setPortName(m_serialPortName);
m_serialPort.setBaudRate(38400);
m_serialPort.setParity(QSerialPort::NoParity);
m_serialPort.setDataBits(QSerialPort::Data8);
m_serialPort.setStopBits(QSerialPort::OneStop);
for(int i = 0; i < m_ledAreaOrderList.size(); i++){
LEDArea *ledarea = new LEDArea(i, this);
m_ledAreaList.append(ledarea);
}
connectToBoard();
}
AtmoLight::~AtmoLight()
{
qDebug() << this << "Quitting";
m_serialPort.close();
}
void AtmoLight::connectToBoard()
{
if(m_serialPort.open(QIODevice::WriteOnly)){
qDebug() << this << "Opened port";
}
else qWarning() << this << "Could not open port";
}
void AtmoLight::sendLightState()
{
QByteArray command = QByteArray::fromHex("FF 00 00 0F 00 00 00");
foreach (LEDArea *led, m_ledAreaList) {
QByteArray color;
// R
color.append((char)led->red());
// G
color.append((char)led->green());
// B
color.append((char)led->blue());
command.append(color);
}
//qDebug() << this << "Sending" << command.toHex();
m_serialPort.write(command);
}
QList<LEDArea *> AtmoLight::ledAreaList() const
{
return m_ledAreaList;
}
void AtmoLight::setLedAreaList(const QList<LEDArea *> &ledAreaList)
{
m_ledAreaList = ledAreaList;
}
QList<int> AtmoLight::ledAreaOrderList() const
{
return m_ledAreaOrderList;
}
void AtmoLight::setLedAreaOrderList(const QList<int> &ledAreaOrderList)
{
m_ledAreaOrderList = ledAreaOrderList;
}