2023-02-15 01:12:19 +01:00
|
|
|
#include "dmxcontroller.h"
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
DmxController::DmxController(QObject *parent) :
|
|
|
|
|
QObject{parent},
|
|
|
|
|
m_thread{*this},
|
|
|
|
|
m_lastInfo{QDateTime::currentDateTime()},
|
|
|
|
|
m_counter{},
|
|
|
|
|
m_lightProject {
|
2023-02-15 22:45:18 +01:00
|
|
|
.deviceTypes {
|
2023-02-15 21:54:26 +01:00
|
|
|
{
|
|
|
|
|
.id=0,
|
2023-02-18 23:48:28 +01:00
|
|
|
.name="Stairville MH-X50+",
|
|
|
|
|
.iconName="movinghead"
|
2023-02-15 21:54:26 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.id=1,
|
2023-02-18 15:55:40 +01:00
|
|
|
.name="RGBW Strahler Klein",
|
2023-02-18 23:48:28 +01:00
|
|
|
.iconName="rgbstrahler",
|
2023-02-15 21:54:26 +01:00
|
|
|
.registers {
|
2023-02-15 22:45:18 +01:00
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dimmer },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Red },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Green },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Blue },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::White },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Strobo },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dummy }
|
2023-02-15 21:54:26 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.id=2,
|
2023-02-16 00:47:00 +01:00
|
|
|
.name="RGB Strahler",
|
2023-02-18 23:48:28 +01:00
|
|
|
.iconName="rgbstrahler",
|
2023-02-16 00:47:00 +01:00
|
|
|
.registers {
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Red },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Green },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Blue }
|
|
|
|
|
}
|
2023-02-15 21:54:26 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.id=3,
|
2023-02-16 00:47:00 +01:00
|
|
|
.name="Nebelmaschine",
|
2023-02-18 23:48:28 +01:00
|
|
|
.iconName="nebelmaschine",
|
2023-02-16 00:47:00 +01:00
|
|
|
.registers {
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dimmer }
|
|
|
|
|
}
|
2023-02-18 15:55:40 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.id=4,
|
|
|
|
|
.name="RGBW Strahler Groß",
|
2023-02-18 23:48:28 +01:00
|
|
|
.iconName="rgbstrahler",
|
2023-02-18 15:55:40 +01:00
|
|
|
.registers {
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dimmer },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Red },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Green },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Blue },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::White },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Dummy },
|
|
|
|
|
DeviceTypeRegisterConfig { .type = DeviceTypeRegisterType::Strobo }
|
|
|
|
|
}
|
2023-02-15 21:54:26 +01:00
|
|
|
}
|
2023-02-15 01:12:19 +01:00
|
|
|
},
|
2023-02-15 22:45:18 +01:00
|
|
|
.devices {
|
2023-02-18 22:55:51 +01:00
|
|
|
{ .id=1, .name="Lampe 1", .deviceTypeId=4, .address=1 },
|
|
|
|
|
{ .id=1, .name="Lampe 2", .deviceTypeId=4, .address=8 },
|
|
|
|
|
{ .id=2, .name="Lampe 3", .deviceTypeId=4, .address=15 },
|
|
|
|
|
{ .id=3, .name="Lampe 4", .deviceTypeId=4, .address=22 },
|
|
|
|
|
{ .id=4, .name="Lampe 5", .deviceTypeId=4, .address=29 },
|
|
|
|
|
{ .id=5, .name="Lampe 6", .deviceTypeId=4, .address=36 },
|
|
|
|
|
{ .id=6, .name="Lampe 7", .deviceTypeId=4, .address=43 },
|
|
|
|
|
{ .id=7, .name="Lampe 8", .deviceTypeId=4, .address=50 },
|
|
|
|
|
{ .id=8, .name="Lampe 9", .deviceTypeId=4, .address=57 },
|
|
|
|
|
{ .id=9, .name="Lampe 10", .deviceTypeId=4, .address=64 },
|
|
|
|
|
{ .id=1, .name="Lampe 11", .deviceTypeId=4, .address=71 },
|
|
|
|
|
{ .id=1, .name="Lampe 12", .deviceTypeId=4, .address=78 },
|
|
|
|
|
{ .id=2, .name="Lampe 13", .deviceTypeId=4, .address=85 },
|
|
|
|
|
{ .id=0, .name="Test 1", .deviceTypeId=1, .address=95 },
|
|
|
|
|
{ .id=15, .name="Test 2", .deviceTypeId=2, .address=120 },
|
|
|
|
|
{ .id=11, .name="Moving Head 1", .deviceTypeId=0, .address=150 },
|
|
|
|
|
{ .id=12, .name="Moving Head 2", .deviceTypeId=0, .address=160 },
|
|
|
|
|
{ .id=13, .name="Moving Head 3", .deviceTypeId=0, .address=170 },
|
|
|
|
|
{ .id=14, .name="Moving Head 4", .deviceTypeId=0, .address=180 },
|
|
|
|
|
{ .id=0, .name="Nebelmaschine", .deviceTypeId=3, .address=200 }
|
2023-02-15 01:12:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
std::fill(std::begin(buf), std::end(buf), 0);
|
|
|
|
|
|
|
|
|
|
buf[32] = 255;
|
|
|
|
|
buf[33] = 255;
|
|
|
|
|
buf[34] = 0;
|
|
|
|
|
buf[35] = 0;
|
|
|
|
|
// buf[36] = 255;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DmxController::start()
|
|
|
|
|
{
|
|
|
|
|
m_serialPort.setPortName("/dev/ttyAMA0");
|
|
|
|
|
if (!m_serialPort.setBaudRate(250000))
|
|
|
|
|
{
|
|
|
|
|
qCritical("setBaudRate() failed %s", qPrintable(m_serialPort.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!m_serialPort.setDataBits(QSerialPort::Data8))
|
|
|
|
|
{
|
|
|
|
|
qCritical("setDataBits() failed %s", qPrintable(m_serialPort.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!m_serialPort.setParity(QSerialPort::NoParity))
|
|
|
|
|
{
|
|
|
|
|
qCritical("setParity() failed %s", qPrintable(m_serialPort.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!m_serialPort.setStopBits(QSerialPort::TwoStop))
|
|
|
|
|
{
|
|
|
|
|
qCritical("setStopBits() failed %s", qPrintable(m_serialPort.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!m_serialPort.setFlowControl(QSerialPort::NoFlowControl))
|
|
|
|
|
{
|
|
|
|
|
qCritical("setFlowControl() failed %s", qPrintable(m_serialPort.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!m_serialPort.open(QIODevice::WriteOnly))
|
|
|
|
|
{
|
|
|
|
|
qCritical("open() failed %s", qPrintable(m_serialPort.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_thread.start(QThread::TimeCriticalPriority);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DmxController::setChannel(int channel, int value)
|
|
|
|
|
{
|
2023-02-15 23:14:22 +01:00
|
|
|
//qDebug() << channel << value;
|
|
|
|
|
Q_ASSERT(channel >= 0 && channel < std::size(buf));
|
2023-02-15 01:12:19 +01:00
|
|
|
buf[channel] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DmxController::sendDmxBuffer()
|
|
|
|
|
{
|
|
|
|
|
const auto now = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
|
|
m_serialPort.setBreakEnabled(true);
|
|
|
|
|
QThread::usleep(88);
|
|
|
|
|
m_serialPort.setBreakEnabled(false);
|
|
|
|
|
|
|
|
|
|
// const auto written = write(m_serialPort.handle(), buf, std::size(buf));
|
|
|
|
|
const auto written = m_serialPort.write(buf, std::size(buf));
|
|
|
|
|
m_serialPort.flush();
|
|
|
|
|
// qDebug("%lli written", written);
|
|
|
|
|
|
|
|
|
|
m_counter++;
|
|
|
|
|
|
|
|
|
|
if (m_lastInfo.msecsTo(now) >= 1000)
|
|
|
|
|
{
|
2023-02-15 20:17:58 +01:00
|
|
|
qInfo("%i per second", m_counter);
|
2023-02-18 15:55:25 +01:00
|
|
|
m_lastCounter = m_counter;
|
|
|
|
|
emit performanceChanged(m_counter);
|
2023-02-15 01:12:19 +01:00
|
|
|
m_counter = 0;
|
|
|
|
|
m_lastInfo = now;
|
|
|
|
|
}
|
|
|
|
|
}
|