Skip to content

Commit 0d1e941

Browse files
committed
Implemented progress indication for write operation
1 parent 4290938 commit 0d1e941

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

qt/main_window.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,24 @@ void MainWindow::slotProgRead()
355355

356356
void MainWindow::slotProgWriteCompleted(int status)
357357
{
358+
disconnect(prog, SIGNAL(writeChipProgress(unsigned int)), this,
359+
SLOT(slotProgWriteProgress(unsigned int)));
358360
disconnect(prog, SIGNAL(writeChipCompleted(int)), this,
359361
SLOT(slotProgWriteCompleted(int)));
360362

361363
if (!status)
362364
qInfo() << "Data has been successfully written";
365+
366+
setProgress(100);
367+
}
368+
369+
void MainWindow::slotProgWriteProgress(unsigned int progress)
370+
{
371+
uint32_t progressPercent;
372+
uint32_t bufferSize = static_cast<uint32_t>(buffer.size());
373+
374+
progressPercent = progress * 100ULL / bufferSize;
375+
setProgress(progressPercent);
363376
}
364377

365378
void MainWindow::slotProgWrite()
@@ -399,6 +412,8 @@ void MainWindow::slotProgWrite()
399412

400413
connect(prog, SIGNAL(writeChipCompleted(int)), this,
401414
SLOT(slotProgWriteCompleted(int)));
415+
connect(prog, SIGNAL(writeChipProgress(unsigned int)), this,
416+
SLOT(slotProgWriteProgress(unsigned int)));
402417

403418
prog->writeChip(buffer.data(), START_ADDRESS, bufferSize, pageSize);
404419
}

qt/main_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private slots:
4444
void slotProgReadCompleted(int status);
4545
void slotProgReadProgress(unsigned int progress);
4646
void slotProgWriteCompleted(int status);
47+
void slotProgWriteProgress(unsigned int progress);
4748
void slotProgEraseCompleted(int status);
4849
void slotProgEraseProgress(unsigned int progress);
4950
void slotProgReadBadBlocksCompleted(int status);

qt/programmer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,23 @@ void Programmer::readChip(uint8_t *buf, uint32_t addr, uint32_t len,
228228

229229
void Programmer::writeCb(int ret)
230230
{
231+
QObject::disconnect(&writer, SIGNAL(progress(unsigned int)), this,
232+
SLOT(writeProgressCb(unsigned int)));
231233
QObject::disconnect(&writer, SIGNAL(result(int)), this, SLOT(writeCb(int)));
232234
emit writeChipCompleted(ret);
233235
}
234236

237+
void Programmer::writeProgressCb(unsigned int progress)
238+
{
239+
emit writeChipProgress(progress);
240+
}
241+
235242
void Programmer::writeChip(uint8_t *buf, uint32_t addr, uint32_t len,
236243
uint32_t pageSize)
237244
{
238245
QObject::connect(&writer, SIGNAL(result(int)), this, SLOT(writeCb(int)));
246+
QObject::connect(&writer, SIGNAL(progress(unsigned int)), this,
247+
SLOT(writeProgressCb(unsigned int)));
239248

240249
writer.init(usbDevName, SERIAL_PORT_SPEED, buf, addr, len, pageSize,
241250
skipBB);

qt/programmer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Programmer : public QObject
5757
void connectCompleted(int ret);
5858
void readChipIdCompleted(int ret);
5959
void writeChipCompleted(int ret);
60+
void writeChipProgress(unsigned int progress);
6061
void readChipCompleted(int ret);
6162
void readChipProgress(unsigned int ret);
6263
void eraseChipCompleted(int ret);
@@ -67,6 +68,7 @@ class Programmer : public QObject
6768
private slots:
6869
void readChipIdCb(int ret);
6970
void writeCb(int ret);
71+
void writeProgressCb(unsigned int progress);
7072
void readCb(int ret);
7173
void readProgressCb(unsigned int progress);
7274
void eraseChipCb(int ret);

qt/writer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ int Writer::handleWriteAck(RespHeader *header, uint32_t len)
8787
return -1;
8888
}
8989

90+
emit progress(bytesAcked);
91+
9092
return size;
9193
}
9294

qt/writer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Writer : public QThread
4747
uint32_t addr, uint32_t len, uint32_t pageSize, bool skipBB);
4848
signals:
4949
void result(int ret);
50+
void progress(unsigned int progress);
5051
void log(QtMsgType msgType, QString msg);
5152
};
5253

0 commit comments

Comments
 (0)