Skip to content

Commit

Permalink
Merge branch '#241' into 2.1-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusbirkin committed Jun 5, 2021
1 parent 4f5d776 commit 16a0c5c
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 160 deletions.
6 changes: 5 additions & 1 deletion sACNView.pro
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ include(libs.pri)

## Project includes

INCLUDEPATH += src src/sacn src/sacn/ACNShare
INCLUDEPATH += src \
src/sacn src/sacn/ACNShare \
src/widgets

## Sources

SOURCES += src/main.cpp\
src/widgets/monitorspinbox.cpp \
src/mdimainwindow.cpp \
src/scopewindow.cpp \
src/universeview.cpp \
Expand Down Expand Up @@ -126,6 +129,7 @@ SOURCES += src/main.cpp\
src/grideditwidget.cpp

HEADERS += src/mdimainwindow.h \
src/widgets/monitorspinbox.h \
src/scopewindow.h \
src/universeview.h \
src/sacn/ACNShare/CID.h \
Expand Down
169 changes: 41 additions & 128 deletions src/bigdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,48 @@

BigDisplay::BigDisplay(int universe, quint16 address, QWidget *parent) :
QWidget(parent),
ui(new Ui::BigDisplay),
m_universe(universe)
ui(new Ui::BigDisplay)
{
ui->setupUi(this);

// Make address human readable
address++;

// 8bit controls
ui->spinBox_8->setMinimum(MIN_DMX_ADDRESS);
ui->spinBox_8->setMaximum(MAX_DMX_ADDRESS);
ui->spinBox_8->setValue(address);
ui->spinBox_8->setWrapping(true);
ui->spinBox_8->setAddress(universe, address);
connect(ui->spinBox_8, &monitorspinbox::dataReady, this, &BigDisplay::dataReady);

// 16bit controls
ui->spinBox_16_Coarse->setMinimum(MIN_DMX_ADDRESS);
ui->spinBox_16_Coarse->setMaximum(MAX_DMX_ADDRESS);
ui->spinBox_16_Coarse->setValue(address);
ui->spinBox_16_Coarse->setWrapping(true);
ui->spinBox_16_Coarse->setAddress(universe, address);
connect(ui->spinBox_16_Coarse, &monitorspinbox::dataReady, this, &BigDisplay::dataReady);
//--
ui->spinBox_16_Fine->setMinimum(MIN_DMX_ADDRESS);
ui->spinBox_16_Fine->setMaximum(MAX_DMX_ADDRESS);
ui->spinBox_16_Fine->setValue(address + 1);
ui->spinBox_16_Fine->setWrapping(true);
ui->spinBox_16_Fine->setAddress(universe, address + 1);
connect(ui->spinBox_16_Fine, &monitorspinbox::dataReady, this, &BigDisplay::dataReady);

// Colour controls
ui->spinBox_RGB_1->setMinimum(MIN_DMX_ADDRESS);
ui->spinBox_RGB_1->setMaximum(MAX_DMX_ADDRESS);
ui->spinBox_RGB_1->setValue(address);
ui->spinBox_RGB_1->setWrapping(true);
ui->spinBox_RGB_1->setAddress(universe, address);
connect(ui->spinBox_RGB_1, &monitorspinbox::dataReady, this, &BigDisplay::dataReady);
//--
ui->spinBox_RGB_2->setMinimum(MIN_DMX_ADDRESS);
ui->spinBox_RGB_2->setMaximum(MAX_DMX_ADDRESS);
ui->spinBox_RGB_2->setValue(address + 1);
ui->spinBox_RGB_2->setWrapping(true);
ui->spinBox_RGB_2->setAddress(universe, address + 1);
connect(ui->spinBox_RGB_2, &monitorspinbox::dataReady, this, &BigDisplay::dataReady);
//--
ui->spinBox_RGB_3->setMinimum(MIN_DMX_ADDRESS);
ui->spinBox_RGB_3->setMaximum(MAX_DMX_ADDRESS);
ui->spinBox_RGB_3->setValue(address + 2);
ui->spinBox_RGB_3->setWrapping(true);
ui->spinBox_RGB_3->setAddress(universe, address + 2);
connect(ui->spinBox_RGB_3, &monitorspinbox::dataReady, this, &BigDisplay::dataReady);

// Window
this->setWindowTitle(tr("Big Display Universe %1").arg(m_universe));
this->setWindowTitle(tr("Big Display Universe %1").arg(universe));
this->setWindowIcon(parent->windowIcon());

// Listen to universe
m_listener = sACNManager::getInstance()->getListener(m_universe);
connect(m_listener.data(), SIGNAL(dataReady(int, QPointF)), this, SLOT(dataReady(int, QPointF)));

m_data = 0;

setupAddressMonitors();
m_level = 0;
displayLevel();
}

BigDisplay::~BigDisplay()
{
delete ui;
}

void BigDisplay::setupAddressMonitors()
{
m_listener->monitorAddress(ui->spinBox_8->value() - 1);

m_listener->monitorAddress(ui->spinBox_16_Coarse->value() - 1);
m_listener->monitorAddress(ui->spinBox_16_Fine->value() - 1);

m_listener->monitorAddress(ui->spinBox_RGB_1->value() - 1);
m_listener->monitorAddress(ui->spinBox_RGB_2->value() - 1);
m_listener->monitorAddress(ui->spinBox_RGB_3->value() - 1);
}

void BigDisplay::displayData()
void BigDisplay::displayLevel()
{
QPalette palette = ui->lcdNumber->palette();
QColor colour(m_data | 0xFF000000);
QColor colour(m_level | 0xFF000000);

// Display format
if((ui->tabWidget->currentIndex() == tabModes_bit8) |
Expand All @@ -94,13 +61,13 @@ void BigDisplay::displayData()
case Preferences::DECIMAL:
{
ui->lcdNumber->setMode(QLCDNumber::Dec);
ui->lcdNumber->display((int)m_data);
ui->lcdNumber->display((int)m_level);
break;
}
case Preferences::HEXADECIMAL:
{
ui->lcdNumber->setMode(QLCDNumber::Hex);
ui->lcdNumber->display((int)m_data);
ui->lcdNumber->display((int)m_level);
break;
}
case Preferences::PERCENT:
Expand All @@ -109,12 +76,12 @@ void BigDisplay::displayData()
// Display percent with an optional fraction
if(ui->tabWidget->currentIndex() == tabModes_bit8)
{
ui->lcdNumber->display(HTOPT[m_data & 0xFF]);
ui->lcdNumber->display(HTOPT[m_level & 0xFF]);
}
else
{
int percent = HTOPT[(m_data & 0xFF00) >> 8];
int fraction = m_data & 0xFF;
int percent = HTOPT[(m_level & 0xFF00) >> 8];
int fraction = m_level & 0xFF;
double value = percent + fraction/255.0;
ui->lcdNumber->display(value);
}
Expand All @@ -131,100 +98,46 @@ void BigDisplay::displayData()
ui->lcdNumber->setPalette(palette);
ui->lcdNumber->setDigitCount(6);
ui->lcdNumber->setMode(QLCDNumber::Hex);
ui->lcdNumber->display((int)m_data);
ui->lcdNumber->display((int)m_level);
}



}

void BigDisplay::dataReady(int address, QPointF data)
void BigDisplay::dataReady(int universe, quint16 address, QPointF data)
{
bool required = false;
address++;
quint32 value = data.y();

Q_UNUSED(universe);
quint8 level = data.y() > 0 ? data.y() : 0;

switch (ui->tabWidget->currentIndex())
{
case tabModes_bit8:
if (address == ui->spinBox_8->value()) {
required = true;
m_data = data.y();
}
if (address == ui->spinBox_8->address())
m_level = level;
break;

case tabModes_bit16:
if (address == ui->spinBox_16_Coarse->value()) {
required = true;
m_data = (m_data & 0x00FF) | (0xFF00 & (value << 8));
}
if (address == ui->spinBox_16_Coarse->address())
m_level = (m_level & 0x00FF) | (0xFF00 & (level << 8));

if (address == ui->spinBox_16_Fine->value()) {
required = true;
m_data = (m_data & 0xFF00) | (0x00FF & value);
}
if (address == ui->spinBox_16_Fine->address())
m_level = (m_level & 0xFF00) | (0x00FF & level);

break;

case tabModes_rgb:
if (address == ui->spinBox_RGB_1->value()) {
required = true;
m_data = (m_data & 0x00FFFFu) | (0xFF0000u & ((quint32)value << 16));
}
if (address == ui->spinBox_RGB_1->address())
m_level = (m_level & 0x00FFFFu) | (0xFF0000u & ((quint32)level << 16));

if (address == ui->spinBox_RGB_2->value()) {
required = true;
m_data = (m_data & 0xFF00FFu) | (0x00FF00u & ((quint32)value << 8));
}
if (address == ui->spinBox_RGB_2->address())
m_level = (m_level & 0xFF00FFu) | (0x00FF00u & ((quint32)level << 8));

if (address == ui->spinBox_RGB_3->value()) {
required = true;
m_data = (m_data & 0xFFFF00u) | (0x0000FFu & value);
}
if (address == ui->spinBox_RGB_3->address())
m_level = (m_level & 0xFFFF00u) | (0x0000FFu & level);
break;

default:
m_data = -1;
m_level = -1;
break;
}

// Unrequired address?
if (!required)
{
m_listener->unMonitorAddress(address);
setupAddressMonitors();
}

displayData();
}

void BigDisplay::on_spinBox_8_editingFinished()
{
setupAddressMonitors();
}

void BigDisplay::on_spinBox_16_Coarse_editingFinished()
{
setupAddressMonitors();
}

void BigDisplay::on_spinBox_16_Fine_editingFinished()
{
setupAddressMonitors();
}

void BigDisplay::on_spinBox_RGB_1_editingFinished()
{
setupAddressMonitors();
}

void BigDisplay::on_spinBox_RGB_2_editingFinished()
{
setupAddressMonitors();
}

void BigDisplay::on_spinBox_RGB_3_editingFinished()
{
setupAddressMonitors();
displayLevel();
}
18 changes: 3 additions & 15 deletions src/bigdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <QWidget>
#include "consts.h"
#include "sacnlistener.h"

namespace Ui {
class BigDisplay;
Expand All @@ -19,8 +18,6 @@ class BigDisplay : public QWidget

private:
Ui::BigDisplay *ui;
int m_universe;
sACNManager::tListener m_listener;

enum tabModes
{
Expand All @@ -29,22 +26,13 @@ class BigDisplay : public QWidget
tabModes_rgb
};

void setupAddressMonitors();

private slots:
void dataReady(int address, QPointF data);

void on_spinBox_8_editingFinished();
void on_spinBox_16_Coarse_editingFinished();
void on_spinBox_16_Fine_editingFinished();
void on_spinBox_RGB_1_editingFinished();
void on_spinBox_RGB_2_editingFinished();
void on_spinBox_RGB_3_editingFinished();
void dataReady(int universe, quint16 address, QPointF data);

private:
void displayData();
void displayLevel();

quint32 m_data;
quint32 m_level;
};

#endif // BIGDISPLAY_H
3 changes: 2 additions & 1 deletion src/sacn/sacnlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ void sACNListener::performMerge()

{
QMutexLocker locker(&m_monitoredChannelsMutex);
for(auto chan: m_monitoredChannels)
const auto uniqeChannels = m_monitoredChannels.values().toSet();
for(auto chan: uniqeChannels)
{
QPointF data;
data.setX(m_elapsedTime.nsecsElapsed()/1000000.0);
Expand Down
14 changes: 9 additions & 5 deletions src/sacn/sacnlistener.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ class sACNListener : public QObject

public slots:
void startReception();
void monitorAddress(int address) {
void monitorAddress(int address, const QObject *owner) {
QMutexLocker locker(&m_monitoredChannelsMutex);
m_monitoredChannels.insert(address);
m_monitoredChannels.insert(owner, address);
connect(owner, &QObject::destroyed, this, [this](const QObject *owner) {
QMutexLocker locker(&m_monitoredChannelsMutex);
m_monitoredChannels.remove(owner);
});
}
void unMonitorAddress(int address) {
void unMonitorAddress(int address, const QObject *owner) {
QMutexLocker locker(&m_monitoredChannelsMutex);
m_monitoredChannels.remove(address);
m_monitoredChannels.remove(owner, address);
}
signals:
void listenerStarted(int universe);
Expand Down Expand Up @@ -132,7 +136,7 @@ private slots:
QElapsedTimer m_elapsedTime;
int m_predictableTimerValue;
QMutex m_monitoredChannelsMutex;
QSet<int> m_monitoredChannels;
QMultiMap<const QObject*, int> m_monitoredChannels;
bool m_mergeAll; // A flag to initiate a complete remerge of everything
unsigned int m_mergesPerSecond;
int m_mergeCounter;
Expand Down
6 changes: 3 additions & 3 deletions src/scopewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ void ScopeWindow::on_tableWidget_itemChanged(QTableWidgetItem * item)

listener = m_universes[ch->universe()];

listener->unMonitorAddress(ch->address());
listener->unMonitorAddress(ch->address(), this);
ch->setAddress(address-1);
listener->monitorAddress(ch->address());
listener->monitorAddress(ch->address(), this);
ch->clear();
}
else
Expand All @@ -245,7 +245,7 @@ void ScopeWindow::on_tableWidget_itemChanged(QTableWidgetItem * item)
ch->setUniverse(universe);
disconnect(listener.data(), 0, this->ui->widget, 0);
connect(listener.data(), SIGNAL(dataReady(int, QPointF)), this->ui->widget, SLOT(dataReady(int, QPointF)));
listener->monitorAddress(ch->address());
listener->monitorAddress(ch->address(), this);
ch->clear();
}
else
Expand Down
Loading

0 comments on commit 16a0c5c

Please sign in to comment.