-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (56 loc) · 1.72 KB
/
main.cpp
File metadata and controls
70 lines (56 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "mainwindow.h"
#include <QUdpSocket>
#include <QApplication>
#include <QLabel>
//#include<QDebug>
class Server: public QObject {
public:
QLabel *label;
QUdpSocket *socket;
QByteArray *Buffer;
QHostAddress sender;
uint16_t senderport;
Server(QObject *parent = nullptr, QString ip = "192,168,0,100"): QObject(parent) {
label = new QLabel();
Buffer = new QByteArray();
socket = new QUdpSocket(this);
socket->bind(QHostAddress(ip), 7755);
readyRead();
}
~Server() {
delete label;
delete Buffer;
delete socket;
}
void readyRead() {
qInfo() << "waiting for a connection";
connect(socket, &QUdpSocket::readyRead, this, [&]() mutable {
while (socket->hasPendingDatagrams()) {
Buffer->resize(socket->pendingDatagramSize());
socket->readDatagram(Buffer->data(), Buffer->size(), &sender, &senderport);
uint8_t arr[1024];
memcpy(&arr, (uint8_t*)Buffer->data(), 1024);
QImage create(128, 64, QImage::Format_MonoLSB);
for (uint8_t x = 0; x < 128; ++x) {
for (uint8_t y = 0; y < 8; ++y) { // y < (64/8)
uint8_t bit = *(arr + (y * 128 + x));
for (uint8_t i = 0; i < 8; ++i, bit >>= 1) {
create.setPixel(x, (y << 3) + i, bit & 0x01); // (y / 8) + i
}
}
}
label->setPixmap(QPixmap::fromImage(create));
label->setFixedSize(128, 64);
label->show();
}
});
}
};
int32_t main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
w.setWindowTitle("ssd1306Stream");
w.setFixedSize(128, 64);
Server s(&w, "192,168,0,103");
return a.exec();
}