Packets are shown on screen

This commit is contained in:
Ollo 2023-08-17 21:51:03 +02:00
parent 536779910e
commit c5bfaa2a4a
4 changed files with 21 additions and 12 deletions

View File

@ -11,15 +11,8 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
this->server = new UdpLedServer ();
this->mOffscreenPanel = new QImage(DEFAULT_WIDTH + LED_DISTANCE, DEFAULT_HEIGHT + LED_DISTANCE, QImage::Format_RGB32); this->mOffscreenPanel = new QImage(DEFAULT_WIDTH + LED_DISTANCE, DEFAULT_HEIGHT + LED_DISTANCE, QImage::Format_RGB32);
for(int x=0; x < (PANEL_WIDTH * MAXIMUM_PANELSIZE); x++) { this->server = new UdpLedServer (NULL, this);
for(int y=0; y < PANEL_HEIGHT; y++) {
setLED(x, y);
}
}
updatePanel();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

View File

@ -14,6 +14,9 @@ QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
QT_END_NAMESPACE QT_END_NAMESPACE
/* dummy */
class UdpLedServer;
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT

View File

@ -6,19 +6,27 @@
#define UDP_IMAGE_PORT 4242 #define UDP_IMAGE_PORT 4242
UdpLedServer ::UdpLedServer (QObject *parent) UdpLedServer::UdpLedServer (QObject *parent, MainWindow *window)
: QObject(parent) : QObject(parent)
{ {
initSocket(); initSocket();
connect(this, connect(this,
&UdpLedServer::changeLEDstate, &UdpLedServer::changeLEDstate,
(MainWindow*) parent, window,
&MainWindow::setLED); &MainWindow::setLED);
connect(this, connect(this,
&UdpLedServer::updatePanelContent, &UdpLedServer::updatePanelContent,
(MainWindow*) parent, window,
&MainWindow::updatePanel); &MainWindow::updatePanel);
for(int x=0; x < (PANEL_WIDTH * MAXIMUM_PANELSIZE); x++) {
for(int y=0; y < PANEL_HEIGHT; y++) {
changeLEDstate(x, y);
}
}
updatePanelContent();
} }
void UdpLedServer ::initSocket() void UdpLedServer ::initSocket()
@ -49,6 +57,7 @@ void UdpLedServer::processTheDatagram(QNetworkDatagram datagram) {
for(int y=0; y < PANEL_HEIGHT; y++) { for(int y=0; y < PANEL_HEIGHT; y++) {
if (datagram.data().at(currentIndex) & mask) { if (datagram.data().at(currentIndex) & mask) {
this->changeLEDstate(x, y); this->changeLEDstate(x, y);
qDebug() << x << "x" << y << " set";
} }
mask = (mask << 1); mask = (mask << 1);
if (mask >= 256) { if (mask >= 256) {

View File

@ -3,13 +3,17 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QUdpSocket> #include <QUdpSocket>
#include "mainwindow.h"
class MainWindow;
class UdpLedServer : public QObject class UdpLedServer : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UdpLedServer (QObject *parent = nullptr); /*UdpLedServer (QObject *parent = nullptr); */
UdpLedServer (QObject *parent = nullptr, MainWindow *window = nullptr);
private: private:
void initSocket(); void initSocket();