From aac762e8f15ba1f997bb5453c6106fbcd8ab3769 Mon Sep 17 00:00:00 2001 From: Ollo Date: Thu, 17 Aug 2023 22:19:12 +0200 Subject: [PATCH] Simulation is working --- simulation/VirtualLedBoard/mainwindow.cpp | 12 +++++++----- simulation/VirtualLedBoard/mainwindow.h | 6 ++++-- simulation/VirtualLedBoard/udpserver.cpp | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/simulation/VirtualLedBoard/mainwindow.cpp b/simulation/VirtualLedBoard/mainwindow.cpp index 4593d7c..b99fbab 100644 --- a/simulation/VirtualLedBoard/mainwindow.cpp +++ b/simulation/VirtualLedBoard/mainwindow.cpp @@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); this->mOffscreenPanel = new QImage(DEFAULT_WIDTH + LED_DISTANCE, DEFAULT_HEIGHT + LED_DISTANCE, QImage::Format_RGB32); + this->drawImage(this->mOffscreenPanel); this->server = new UdpLedServer (NULL, this); } @@ -21,12 +22,10 @@ MainWindow::~MainWindow() } void MainWindow::drawImage(QImage *target) { + this->mScene=new QGraphicsScene() ; QGraphicsView *graphicsView = new QGraphicsView(); graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QGraphicsScene* scene=new QGraphicsScene() ; - graphicsView->setScene(scene); - QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(*(target))); - scene->addItem(item); + graphicsView->setScene(this->mScene); graphicsView->show(); this->ui->ledPanel->addWidget(graphicsView); } @@ -42,7 +41,10 @@ void MainWindow::setLED(uint8_t x, uint8_t y) { } void MainWindow::updatePanel(void) { - this->drawImage(this->mOffscreenPanel); + + QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(*(this->mOffscreenPanel))); + this->mScene->clear(); + mScene->addItem(item); this->renderPanel(); } diff --git a/simulation/VirtualLedBoard/mainwindow.h b/simulation/VirtualLedBoard/mainwindow.h index 0b0617a..d32b5f4 100644 --- a/simulation/VirtualLedBoard/mainwindow.h +++ b/simulation/VirtualLedBoard/mainwindow.h @@ -3,6 +3,7 @@ #include #include +#include #include "udpserver.h" #include "settings.h" @@ -31,8 +32,9 @@ public slots: private: Ui::MainWindow *ui; - UdpLedServer *server; - QImage *mOffscreenPanel; + UdpLedServer *server = nullptr; + QImage *mOffscreenPanel = nullptr; + QGraphicsScene* mScene = nullptr; void drawImage(QImage *image); void renderPanel(void); }; diff --git a/simulation/VirtualLedBoard/udpserver.cpp b/simulation/VirtualLedBoard/udpserver.cpp index 8404ffc..0acdf06 100644 --- a/simulation/VirtualLedBoard/udpserver.cpp +++ b/simulation/VirtualLedBoard/udpserver.cpp @@ -53,8 +53,8 @@ void UdpLedServer::processTheDatagram(QNetworkDatagram datagram) { 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++) { + for(int y=0; y < PANEL_HEIGHT; y++) { + for(int x=0; x < (PANEL_WIDTH * MAXIMUM_PANELSIZE); x++) { if (datagram.data().at(currentIndex) & mask) { this->changeLEDstate(x, y); qDebug() << x << "x" << y << " set";