Skip to content

Commit 095e418

Browse files
committed
qt: replaced chip info lookup by id to lookup by name
1 parent 2f5f2df commit 095e418

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

qt/chip_db.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "chip_db.h"
2+
#include <cstring>
23

34
static ChipInfo chipDB[] =
45
{
@@ -13,10 +14,13 @@ uint32_t getChipDB(ChipInfo *&db)
1314
return CHIP_ID_LAST;
1415
}
1516

16-
ChipInfo *getChiInfo(uint32_t id)
17+
ChipInfo *getChipInfoByName(char *name)
1718
{
18-
if (id >= CHIP_ID_LAST)
19-
return 0;
19+
for (int id = 0; id < CHIP_ID_LAST; id++)
20+
{
21+
if (!strcmp(name, chipDB[id].name))
22+
return &chipDB[id];
23+
}
2024

21-
return &chipDB[id];
25+
return 0;
2226
}

qt/chip_db.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typedef struct
2020
} ChipInfo;
2121

2222
uint32_t getChipDB(ChipInfo *&db);
23-
ChipInfo *getChiInfo(uint32_t id);
23+
ChipInfo *getChipInfoByName(char *name);
2424

2525
#endif // CHIP_DB_H
2626

qt/main_window.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ void MainWindow::slotProgReadDeviceId()
178178
void MainWindow::slotProgErase()
179179
{
180180
const uint32_t addr = 0x00000000;
181-
ChipInfo *chipInfo = getChiInfo(ui->chipSelectComboBox->currentIndex());
181+
QByteArray ba = ui->chipSelectComboBox->currentText().toLatin1();
182+
ChipInfo *chipInfo = getChipInfoByName(ba.data());
182183

183184
if (prog->eraseChip(addr, chipInfo->size))
184185
log(tr("Failed to erase chip\n"));

0 commit comments

Comments
 (0)