Skip to content

Commit 18f32b8

Browse files
committed
qt: Disable chip operations before programmer is connected and chip selected
1 parent 08f2e25 commit 18f32b8

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

qt/main_window.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
7171
SLOT(slotFileOpen()));
7272
connect(ui->actionConnect, SIGNAL(triggered()), this,
7373
SLOT(slotProgConnect()));
74-
connect(ui->actionDetect_Device, SIGNAL(triggered()), this,
74+
connect(ui->actionReadId, SIGNAL(triggered()), this,
7575
SLOT(slotProgReadDeviceId()));
7676
connect(ui->actionErase, SIGNAL(triggered()), this,
7777
SLOT(slotProgErase()));
@@ -137,6 +137,21 @@ void MainWindow::slotFileOpen()
137137
file.close();
138138
}
139139

140+
void MainWindow::setUiStateConnected(bool isConnected)
141+
{
142+
ui->chipSelectComboBox->setEnabled(isConnected);
143+
if (!isConnected)
144+
ui->chipSelectComboBox->setCurrentIndex(CHIP_ID_NONE);
145+
}
146+
147+
void MainWindow::setUiStateSelected(bool isSelected)
148+
{
149+
ui->actionReadId->setEnabled(isSelected);
150+
ui->actionErase->setEnabled(isSelected);
151+
ui->actionRead->setEnabled(isSelected);
152+
ui->actionWrite->setEnabled(isSelected);
153+
}
154+
140155
void MainWindow::slotProgConnect()
141156
{
142157
if (!prog->isConnected())
@@ -146,11 +161,13 @@ void MainWindow::slotProgConnect()
146161
else
147162
return;
148163

164+
setUiStateConnected(true);
149165
ui->actionConnect->setText(tr("Disconnect"));
150166
}
151167
else
152168
{
153169
prog->disconnect();
170+
setUiStateConnected(false);
154171
ui->actionConnect->setText(tr("Connect"));
155172
qInfo() << "Disconnected from programmer";
156173
}
@@ -280,13 +297,24 @@ void MainWindow::slotProgSelectCompleted(int status)
280297
SLOT(slotProgSelectCompleted(int)));
281298

282299
if (!status)
300+
{
301+
setUiStateSelected(true);
283302
qInfo() << "Chip has been selected successfully";
303+
}
304+
else
305+
setUiStateSelected(false);
284306
}
285307

286308
void MainWindow::slotSelectChip(int selectedChipNum)
287309
{
288310
this->selectedChipNum = selectedChipNum;
289311

312+
if (selectedChipNum == CHIP_ID_NONE)
313+
{
314+
setUiStateSelected(false);
315+
return;
316+
}
317+
290318
connect(prog, SIGNAL(selectChipCompleted(int)), this,
291319
SLOT(slotProgSelectCompleted(int)));
292320

qt/main_window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class MainWindow : public QMainWindow
3333

3434
void initBufTable();
3535
void resetBufTable();
36+
void setUiStateConnected(bool isConnected);
37+
void setUiStateSelected(bool isSelected);
3638

3739
private slots:
3840
void slotProgReadDeviceIdCompleted(int status);

qt/main_window.ui

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>570</width>
9+
<width>580</width>
1010
<height>532</height>
1111
</rect>
1212
</property>
@@ -24,6 +24,9 @@
2424
<layout class="QGridLayout" name="gridLayout_3">
2525
<item row="2" column="1">
2626
<widget class="QComboBox" name="chipSelectComboBox">
27+
<property name="enabled">
28+
<bool>false</bool>
29+
</property>
2730
<property name="sizePolicy">
2831
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
2932
<horstretch>0</horstretch>
@@ -199,15 +202,15 @@
199202
<rect>
200203
<x>0</x>
201204
<y>0</y>
202-
<width>570</width>
205+
<width>580</width>
203206
<height>19</height>
204207
</rect>
205208
</property>
206209
<widget class="QMenu" name="menuDevice">
207210
<property name="title">
208211
<string>Device</string>
209212
</property>
210-
<addaction name="actionDetect_Device"/>
213+
<addaction name="actionReadId"/>
211214
<addaction name="actionErase"/>
212215
<addaction name="actionRead"/>
213216
<addaction name="actionWrite"/>
@@ -256,7 +259,10 @@
256259
<bool>false</bool>
257260
</attribute>
258261
</widget>
259-
<action name="actionDetect_Device">
262+
<action name="actionReadId">
263+
<property name="enabled">
264+
<bool>false</bool>
265+
</property>
260266
<property name="text">
261267
<string>Read ID</string>
262268
</property>
@@ -277,16 +283,25 @@
277283
</property>
278284
</action>
279285
<action name="actionRead">
286+
<property name="enabled">
287+
<bool>false</bool>
288+
</property>
280289
<property name="text">
281290
<string>Read</string>
282291
</property>
283292
</action>
284293
<action name="actionWrite">
294+
<property name="enabled">
295+
<bool>false</bool>
296+
</property>
285297
<property name="text">
286298
<string>Write</string>
287299
</property>
288300
</action>
289301
<action name="actionErase">
302+
<property name="enabled">
303+
<bool>false</bool>
304+
</property>
290305
<property name="text">
291306
<string>Erase</string>
292307
</property>

0 commit comments

Comments
 (0)