-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
144 lines (127 loc) · 3.95 KB
/
Copy pathmainwindow.cpp
File metadata and controls
144 lines (127 loc) · 3.95 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QResource>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Instanciating the threads
t1=new DFUThread();
t2=new PortThread();
//Starting the PortThread
t2->start();
this->centralWidget()->setLayout(ui->verticalLayout);
//Get the firmware full path
QDir hexFiles = QDir("./Firmware/","*.hex", QDir::Name,QDir::Files);
QFileInfoList file=hexFiles.entryInfoList();
filePath=file.at(0).absoluteFilePath();
//Get the dfu_programmer full path
hexFiles = QDir("./DFU Programmer/","*.exe",QDir::Name,QDir::Files);
file = hexFiles.entryInfoList();
dfuPath = file.at(0).absoluteFilePath();
//filePath=filePath.replace(" ","\\ ");
qDebug() << filePath;
qDebug() << dfuPath;
ui->display->setVisible(false);
this->resize(260,100);
flashing=false;
//To avoid clicking the button before the first iteration in the PortThread
lockUi(true);
//Prepare the ui for the chosen mode
debuggerMode=DEBUGGER_MODE;
if (debuggerMode)
{
ui->display->setVisible(debuggerMode);
this->resize(260,300);
}
//All the connection
connect(ui->update,SIGNAL(clicked()),this,SLOT(on_clicked()));
connect(this,SIGNAL(FlashFirmware(QString,QString,QString)),t1,SLOT(FlashFirmware(QString,QString,QString)));
connect(t1,SIGNAL(response(QString)),this,SLOT(updateOutput(QString)));
connect(t2,SIGNAL(isPlugged(bool)),this,SLOT(connectedAirbox(bool)));
connect(t2,SIGNAL(updateName(QString)),this,SLOT(updatePortName(QString)));
connect(t1,SIGNAL(updatePB(int)),this,SLOT(updateProgressBar(int)));
connect(t1,SIGNAL(debugResponse(QString)),this,SLOT(updateDebug(QString)));
connect(t1,SIGNAL(error(QString)),this,SLOT(displayError(QString)));
}
MainWindow::~MainWindow()
{
delete ui;
}
//Display error from the DFU Thread
void MainWindow::displayError(QString errorMsg)
{
int ret=QMessageBox::information(this, "Result",errorMsg);
//If we are not in debug mode, clicking ok in the final popup will close app
if( ret == QMessageBox::Ok && !debuggerMode) qApp->quit();
}
//Update the display with debug response from dfu-programmer
void MainWindow::updateDebug(QString output)
{
ui->display->append(output);
}
//Update the status bar and the display with messages about the current state of the operation
void MainWindow::updateOutput(QString output)
{
qDebug() << "update : "+output;
ui->display->append("<html><b>"+output+"</html></b>");
ui->statusBar->showMessage(output);
//If everything worked
if (output=="Flash successful")
{
qDebug()<< "ok";
//Flash finished
flashing=false;
int ret=QMessageBox::information(this, "Result","Flashed successfully");
//If we are not in debug mode, clicking ok in the final popup will close app
if( ret == QMessageBox::Ok && !debuggerMode) qApp->quit();
}
}
//Start the flashing process
void MainWindow::on_clicked()
{
ui->display->clear();
if (!t1->isRunning())
{
t1->start();
}
lockUi(true);
t2->quit();
flashing=true;
qDebug() << "before sending "+filePath;
emit FlashFirmware(filePath,portName,dfuPath);
}
//if not in flashing mode, lock the ui
//b=true-> airboxlab connected
void MainWindow::connectedAirbox(bool b)
{
if (!flashing)
{
lockUi(!b);
if (b)
{
ui->statusBar->showMessage("Airboxlab detected");
//enabled=false;
}
else
{
ui->statusBar->showMessage("Airboxlab not detected : Please plug it");
}
}
}
//Update portName
void MainWindow::updatePortName(QString q)
{
portName=q;
}
//Lock the ui
void MainWindow::lockUi(bool locked)
{
ui->update->setDisabled(locked);
}
//Update the progress bar
void MainWindow::updateProgressBar(int p)
{
ui->progressBar->setValue(p);
}