Skip to content

Commit

Permalink
Monitor address has concept of ownership
Browse files Browse the repository at this point in the history
Big display uses new spinbox widget
Resolves #241
  • Loading branch information
marcusbirkin committed Jun 5, 2021
1 parent ef723bd commit e9da470
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 161 deletions.
2 changes: 2 additions & 0 deletions sACNView.pro
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ INCLUDEPATH += src \
## Sources

SOURCES += src/main.cpp\
src/widgets/monitorspinbox.cpp \
src/widgets/qspinbox_resizetocontent.cpp \
src/qt56.cpp \
src/ui/newversiondialog.cpp \
Expand Down Expand Up @@ -134,6 +135,7 @@ SOURCES += src/main.cpp\
src/widgets/grideditwidget.cpp

HEADERS += src/ui/mdimainwindow.h \
src/widgets/monitorspinbox.h \
src/widgets/qspinbox_resizetocontent.h \
src/ui/newversiondialog.h \
src/ui/scopewindow.h \
Expand Down
5 changes: 3 additions & 2 deletions src/sacn/sacnlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void sACNListener::startReception()

if (Preferences::getInstance()->GetNetworkListenAll() & !Preferences::getInstance()->networkInterface().flags().testFlag(QNetworkInterface::IsLoopBack)) {
// Listen on ALL interfaces and not working offline
for (auto interface : QNetworkInterface::allInterfaces())
for (const auto &interface : QNetworkInterface::allInterfaces())
{
// If the interface is ok for use...
if(Preferences::getInstance()->interfaceSuitable(interface))
Expand Down Expand Up @@ -603,7 +603,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 @@ -96,13 +96,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 @@ -137,7 +141,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 = 0;
int m_mergeCounter;
Expand Down
169 changes: 41 additions & 128 deletions src/ui/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/ui/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
6 changes: 3 additions & 3 deletions src/ui/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 e9da470

Please sign in to comment.