-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgaia.cpp
More file actions
172 lines (145 loc) · 4.71 KB
/
gaia.cpp
File metadata and controls
172 lines (145 loc) · 4.71 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//Core
#include "gaia.h"
#include "./ui_gaia.h"
#include <QTextBrowser>
#include <QString>
#include <QTimer>
Gaia::Gaia(QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::Gaia)
{
minervaOut = new Minerva();
minervaOut->serverMode();
minervaIn = new Minerva();
minervaIn->clientMode();
ui->setupUi(this);
ui->minervaStatus->setText("Welcome to PiBoard");
ui->minervaStatus->append(minervaIn->testPins());
//Start thread and worker
epimetheusThread = new EpimetheusThread();
prometheusThread = new PrometheusThread();
epimetheus = new Epimetheus(minervaIn);
prometheus = new Prometheus(minervaOut);
//move respective to their places
minervaOut->moveToThread(prometheusThread);
minervaIn->moveToThread(epimetheusThread);
QObject::connect(ui->exitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
}
Gaia::~Gaia()
{
delete epimetheus;
delete prometheus;
delete epimetheusThread;
delete prometheusThread;
delete senderWindow;
delete receiverWindow;
delete minervaOut;
delete minervaIn;
delete ui;
}
//TODO
//Display Minerva's status
//https://stackoverflow.com/questions/24470519/how-to-auto-scroll-qt-text-field-widget\
//https://doc.qt.io/qt-5/qtextedit.html#append
void Gaia::on_senderButton_clicked()
{
startServer("Center",1);
}
void Gaia::on_receiverButton_clicked()
{
startClient("Center",1);
}
void Gaia::on_allButton_clicked()
{
startServer("Left",0);
startClient("Right",0);
}
QString Gaia::testDMA(){
ui->minervaStatus->append("DMA Test Sent");
return minervaIn->testDMA();
}
QString Gaia::testPins(){
return minervaIn->testPins();
}
void Gaia::startServer(const QString& position,int localMode){
prometheus->moveToThread(prometheusThread);
QObject::connect(prometheusThread, &QThread::started, prometheus, &Prometheus::sendDataUsingThread);
prometheusThread->start();
QIcon server(":/assets/server.png");
senderWindow = new Hermes(minervaOut);
senderWindow->moveToThread(prometheusThread);
senderWindow->show();
senderWindow->setWindowTitle("Server");
senderWindow->setWindowIcon(server);
movePosition(senderWindow,position);
//localMode ? minerva->serverMode() : ui->minervaStatus->append("PiBoard Server is running locally");
if (localMode) {
minervaOut->serverMode();
ui->minervaStatus->append("PiBoard Server has started");
}
else {
ui->minervaStatus->append("PiBoard Server is running locally");
}
};
void Gaia::startClient(const QString& position, int localMode){
epimetheus->moveToThread(epimetheusThread);
QObject::connect(epimetheusThread, &QThread::started, epimetheus, &Epimetheus::receiveDataUsingThread);
epimetheusThread->start();
QIcon client(":/assets/client.png");
minervaIn->sendDataPacket->drawMode=0;
minervaIn->decodeData();
receiverWindow = new Hephaestus(minervaIn);
receiverWindow->moveToThread(epimetheusThread);
receiverWindow->show();
receiverWindow->setWindowIcon(client);
receiverWindow->setWindowTitle("Reciever");
movePosition(receiverWindow,position);
//localMode ? minerva->serverMode() : ui->minervaStatus->append("PiBoard Client is running locally");
if (localMode) {
minervaIn->clientMode();
ui->minervaStatus->append("PiBoard Client has started");
}
else {
ui->minervaStatus->append("PiBoard Client is running locally");
}
};
void Gaia::movePosition(QMainWindow* window,const QString& position){
QRect screenRect = QGuiApplication::primaryScreen()->availableGeometry();
int x, y;
if (position == "Left") {
x = 0;
y = (screenRect.height() - window->height()) / 2;
} else if (position == "Right") {
x = screenRect.right() - window->width();
y = (screenRect.height() - window->height()) / 2;
} else if (position == "Center"){
x = (screenRect.width() - window->width()) / 2;
y = (screenRect.height() - window->height()) / 2;
}
window->move(x, y);
};
void Gaia::selectDataPinCount(int pincount){
//TODO
// Add loginc for selecting the number of pins for data transfer sacrificing speed for idk anything else
// minerva->selectDataPin(pincount);
}
void Gaia::on_testDMAbutton_clicked()
{
testDMA();
int pinNumber = 8;
bool sent = true;
bool rec = false;
minervaOut->sendBitUnclocked(22,sent);
ui->minervaStatus->append("Data has been sent on pin");
ui->minervaStatus->append(testDMA());
}
void Gaia::on_pinTestButton_clicked()
{
ui->minervaStatus->append(testPins());
}
void Gaia::on_dataSendTest_clicked()
{
QByteArray test(10, 0xE3);
minervaOut->sendData(test,0);
qDebug() << minervaIn->receiveData(4);
}