Signals and slots prepared to update content, received from UDP packet

This commit is contained in:
Ollo
2023-08-15 14:38:39 +02:00
parent 3a71ee786e
commit 536779910e
4 changed files with 55 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
#include "settings.h"
#include <QUdpSocket>
#include <QNetworkDatagram>
#include "mainwindow.h"
#define UDP_IMAGE_PORT 4242
@@ -9,6 +10,15 @@ UdpLedServer ::UdpLedServer (QObject *parent)
: QObject(parent)
{
initSocket();
connect(this,
&UdpLedServer::changeLEDstate,
(MainWindow*) parent,
&MainWindow::setLED);
connect(this,
&UdpLedServer::updatePanelContent,
(MainWindow*) parent,
&MainWindow::updatePanel);
}
void UdpLedServer ::initSocket()
@@ -31,6 +41,25 @@ void UdpLedServer ::readPendingDatagrams()
void UdpLedServer::processTheDatagram(QNetworkDatagram datagram) {
if (datagram.isValid() && datagram.data().length() == PACKET_LENGTH) {
qDebug() << "Received datagram:" << datagram.data().size();
uint8_t brightness = datagram.data().at(PACKET_INDEX_BRIGHTNESS);
int currentIndex = PACKET_INDEX_PANEL0;
uint16_t mask = 1;
for(int x=0; x < (PANEL_WIDTH * MAXIMUM_PANELSIZE); x++) {
for(int y=0; y < PANEL_HEIGHT; y++) {
if (datagram.data().at(currentIndex) & mask) {
this->changeLEDstate(x, y);
}
mask = (mask << 1);
if (mask >= 256) {
mask = 1;
currentIndex++;
}
}
}
this->updatePanelContent();
qDebug() << "Received datagram:" << brightness;
}
}