From c5bfaa2a4a4f87342bfa1340a7246de1ba79124c Mon Sep 17 00:00:00 2001 From: Ollo Date: Thu, 17 Aug 2023 21:51:03 +0200 Subject: [PATCH] Packets are shown on screen --- simulation/VirtualLedBoard/mainwindow.cpp | 9 +-------- simulation/VirtualLedBoard/mainwindow.h | 3 +++ simulation/VirtualLedBoard/udpserver.cpp | 15 ++++++++++++--- simulation/VirtualLedBoard/udpserver.h | 6 +++++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/simulation/VirtualLedBoard/mainwindow.cpp b/simulation/VirtualLedBoard/mainwindow.cpp index 6998bf1..4593d7c 100644 --- a/simulation/VirtualLedBoard/mainwindow.cpp +++ b/simulation/VirtualLedBoard/mainwindow.cpp @@ -11,15 +11,8 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) { ui->setupUi(this); - this->server = new UdpLedServer (); - 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++) { - for(int y=0; y < PANEL_HEIGHT; y++) { - setLED(x, y); - } - } - updatePanel(); + this->server = new UdpLedServer (NULL, this); } MainWindow::~MainWindow() diff --git a/simulation/VirtualLedBoard/mainwindow.h b/simulation/VirtualLedBoard/mainwindow.h index 6eb3046..0b0617a 100644 --- a/simulation/VirtualLedBoard/mainwindow.h +++ b/simulation/VirtualLedBoard/mainwindow.h @@ -14,6 +14,9 @@ QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE +/* dummy */ +class UdpLedServer; + class MainWindow : public QMainWindow { Q_OBJECT diff --git a/simulation/VirtualLedBoard/udpserver.cpp b/simulation/VirtualLedBoard/udpserver.cpp index 2b754e2..8404ffc 100644 --- a/simulation/VirtualLedBoard/udpserver.cpp +++ b/simulation/VirtualLedBoard/udpserver.cpp @@ -6,19 +6,27 @@ #define UDP_IMAGE_PORT 4242 -UdpLedServer ::UdpLedServer (QObject *parent) +UdpLedServer::UdpLedServer (QObject *parent, MainWindow *window) : QObject(parent) { initSocket(); connect(this, &UdpLedServer::changeLEDstate, - (MainWindow*) parent, + window, &MainWindow::setLED); connect(this, &UdpLedServer::updatePanelContent, - (MainWindow*) parent, + window, &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() @@ -49,6 +57,7 @@ void UdpLedServer::processTheDatagram(QNetworkDatagram datagram) { for(int y=0; y < PANEL_HEIGHT; y++) { if (datagram.data().at(currentIndex) & mask) { this->changeLEDstate(x, y); + qDebug() << x << "x" << y << " set"; } mask = (mask << 1); if (mask >= 256) { diff --git a/simulation/VirtualLedBoard/udpserver.h b/simulation/VirtualLedBoard/udpserver.h index d36c40f..023370b 100644 --- a/simulation/VirtualLedBoard/udpserver.h +++ b/simulation/VirtualLedBoard/udpserver.h @@ -3,13 +3,17 @@ #include #include +#include "mainwindow.h" + +class MainWindow; class UdpLedServer : public QObject { Q_OBJECT public: - explicit UdpLedServer (QObject *parent = nullptr); + /*UdpLedServer (QObject *parent = nullptr); */ + UdpLedServer (QObject *parent = nullptr, MainWindow *window = nullptr); private: void initSocket();