1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 17:55:19 +03:00

Issue #757 fixed

This commit is contained in:
bsongis 2014-02-28 10:06:03 +01:00
parent 0a30595bb1
commit 1c482e7f6e
2 changed files with 92 additions and 72 deletions

View file

@ -38,7 +38,8 @@ avrOutputDialog::avrOutputDialog(QWidget *parent, QString prog, QStringList arg,
if (arg.count()<2) { if (arg.count()<2) {
closeOpt = AVR_DIALOG_FORCE_CLOSE; closeOpt = AVR_DIALOG_FORCE_CLOSE;
QTimer::singleShot(0, this, SLOT(forceClose())); QTimer::singleShot(0, this, SLOT(forceClose()));
} else { }
else {
sourceFile=arg.at(0); sourceFile=arg.at(0);
destFile=arg.at(1); destFile=arg.at(1);
if (!displayDetails) { if (!displayDetails) {
@ -68,7 +69,6 @@ avrOutputDialog::avrOutputDialog(QWidget *parent, QString prog, QStringList arg,
efuse = 0; efuse = 0;
phase=0; phase=0;
currLine.clear(); currLine.clear();
prevLine.clear();
if (!displayDetails) { if (!displayDetails) {
ui->plainTextEdit->hide(); ui->plainTextEdit->hide();
QTimer::singleShot(0, this, SLOT(shrink())); QTimer::singleShot(0, this, SLOT(shrink()));
@ -132,11 +132,12 @@ void avrOutputDialog::doCopy()
char * pointer=buf; char * pointer=buf;
QFile source(sourceFile); QFile source(sourceFile);
int blocks=(source.size()/BLKSIZE); int blocks=(source.size()/BLKSIZE);
ui->progressBar->setMaximum(blocks-1); ui->progressBar->setMaximum(blocks-1);
if (!source.open(QIODevice::ReadOnly)) { if (!source.open(QIODevice::ReadOnly)) {
QMessageBox::warning(this, tr("Error"),tr("Cannot open source file")); QMessageBox::warning(this, tr("Error"),tr("Cannot open source file"));
hasErrors=true; hasErrors=true;
} else { }
else {
source.read(buf,READBUF); source.read(buf,READBUF);
source.close(); source.close();
QFile dest(destFile); QFile dest(destFile);
@ -183,7 +184,6 @@ void avrOutputDialog::runAgain(QString prog, QStringList arg, int closeBehaviour
foreach(QString str, arg) cmdLine.append(" " + str); foreach(QString str, arg) cmdLine.append(" " + str);
closeOpt = closeBehaviour; closeOpt = closeBehaviour;
currLine.clear(); currLine.clear();
prevLine.clear();
process->start(prog,arg); process->start(prog,arg);
} }
@ -194,12 +194,18 @@ void avrOutputDialog::waitForFinish()
void avrOutputDialog::addText(const QString &text) void avrOutputDialog::addText(const QString &text)
{ {
int val = ui->plainTextEdit->verticalScrollBar()->maximum(); QTextCursor cursor(ui->plainTextEdit->textCursor());
ui->plainTextEdit->insertPlainText(text);
if(val!=ui->plainTextEdit->verticalScrollBar()->maximum())
ui->plainTextEdit->verticalScrollBar()->setValue(ui->plainTextEdit->verticalScrollBar()->maximum());
}
// is the scrollbar at the end?
bool atEnd = (ui->plainTextEdit->verticalScrollBar()->value() == ui->plainTextEdit->verticalScrollBar()->maximum());
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor, 1);
cursor.insertText(text);
if (atEnd) {
ui->plainTextEdit->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
}
}
void avrOutputDialog::doAddTextStdOut() void avrOutputDialog::doAddTextStdOut()
{ {
@ -209,31 +215,30 @@ void avrOutputDialog::doAddTextStdOut()
int nlPos, pos, size; int nlPos, pos, size;
addText(text); addText(text);
currStdLine.append(text); currStdLine.append(text);
if (currStdLine.contains("size = ")) { if (currStdLine.contains("size = ")) {
pos=currStdLine.lastIndexOf("size = "); pos = currStdLine.lastIndexOf("size = ");
temp=currStdLine.mid(pos+7); temp = currStdLine.mid(pos+7);
pos=temp.lastIndexOf("\n"); pos = temp.lastIndexOf("\n");
size=temp.left(pos).toInt(); size = temp.left(pos).toInt();
ui->progressBar->setMaximum(size/2048); ui->progressBar->setMaximum(size/2048);
} }
if (currStdLine.contains("\n")) { if (currStdLine.contains("\n")) {
nlPos=currStdLine.lastIndexOf("\n"); nlPos = currStdLine.lastIndexOf("\n");
prevStdLine=currStdLine.left(nlPos).trimmed(); currStdLine = currStdLine.mid(nlPos+1);
currStdLine=currStdLine.mid(nlPos+1);
} }
if (!currStdLine.isEmpty()) { if (!currStdLine.isEmpty()) {
if (currStdLine.at(0)==QChar('.')) { if (currStdLine.at(0) == QChar('.')) {
pos=currStdLine.lastIndexOf("."); pos = currStdLine.lastIndexOf(".");
ui->progressBar->setValue(pos); ui->progressBar->setValue(pos);
} }
} else if (currStdLine.startsWith("Starting upload: [")) {
if (!currStdLine.isEmpty()) { pos = (currStdLine.lastIndexOf("#")-19)/(MAX_FSIZE/204800.0);
if (currStdLine.startsWith("Starting upload: [")) {
pos=(currStdLine.lastIndexOf("#")-19)/(MAX_FSIZE/204800.0);
ui->progressBar->setValue(pos); ui->progressBar->setValue(pos);
} }
} }
if (text.contains("Complete ")) { if (text.contains("Complete ")) {
#if !__GNUC__ #if !__GNUC__
if (kill_timer) { if (kill_timer) {
@ -250,19 +255,15 @@ void avrOutputDialog::doAddTextStdOut()
} }
} }
//addText("\n=====\n" + text + "\n=====\n"); if (text.contains(":010000")) {
//contains fuse info
if(text.contains(":010000")) //contains fuse info QStringList stl = text.split(":01000000");
{ foreach (QString t, stl) {
QStringList stl = text.split(":01000000"); bool ok = false;
if (!lfuse) lfuse = t.left(2).toInt(&ok,16);
foreach (QString t, stl) if (!hfuse && !ok) hfuse = t.left(2).toInt(&ok,16);
{ if (!efuse && !ok) efuse = t.left(2).toInt(&ok,16);
bool ok = false; }
if(!lfuse) lfuse = t.left(2).toInt(&ok,16);
if(!hfuse && !ok) hfuse = t.left(2).toInt(&ok,16);
if(!efuse && !ok) efuse = t.left(2).toInt(&ok,16);
}
} }
if (text.contains("-E-")) { if (text.contains("-E-")) {
@ -276,9 +277,11 @@ QString avrOutputDialog::getProgrammer()
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_TARANIS(eepromInterface->getBoard())) { if (IS_TARANIS(eepromInterface->getBoard())) {
return "DFU Util"; return "DFU Util";
} else if (eepromInterface->getBoard()==BOARD_SKY9X) { }
else if (eepromInterface->getBoard()==BOARD_SKY9X) {
return "SAM-BA"; return "SAM-BA";
} else { }
else {
return "AVRDUDE"; return "AVRDUDE";
} }
} }
@ -298,25 +301,31 @@ void avrOutputDialog::errorWizard()
DeviceStr="Atmega 64"; DeviceStr="Atmega 64";
FwStr="\n"+tr("ie: OpenTX for 9X board or OpenTX for 9XR board"); FwStr="\n"+tr("ie: OpenTX for 9X board or OpenTX for 9XR board");
fwexist=true; fwexist=true;
} else if (DeviceId=="0x1e9702") { }
else if (DeviceId=="0x1e9702") {
DeviceStr="Atmega 128"; DeviceStr="Atmega 128";
FwStr="\n"+tr("ie: OpenTX for M128 / 9X board or OpenTX for 9XR board with M128 chip"); FwStr="\n"+tr("ie: OpenTX for M128 / 9X board or OpenTX for 9XR board with M128 chip");
fwexist=true; fwexist=true;
} else if (DeviceId=="0x1e9703") { }
else if (DeviceId=="0x1e9703") {
DeviceStr="Atmega 1280"; DeviceStr="Atmega 1280";
} else if (DeviceId=="0x1e9704") { }
else if (DeviceId=="0x1e9704") {
DeviceStr="Atmega 1281"; DeviceStr="Atmega 1281";
} else if (DeviceId=="0x1e9801") { }
else if (DeviceId=="0x1e9801") {
DeviceStr="Atmega 2560"; DeviceStr="Atmega 2560";
FwStr="\n"+tr("ie: OpenTX for Gruvin9X board"); FwStr="\n"+tr("ie: OpenTX for Gruvin9X board");
fwexist=true; fwexist=true;
} else if (DeviceId=="0x1e9802") { }
else if (DeviceId=="0x1e9802") {
DeviceStr="Atmega 2561"; DeviceStr="Atmega 2561";
} }
} }
if (fwexist==false) { if (fwexist==false) {
QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease check advanced burn options to set the correct cpu type.").arg(DeviceStr)); QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease check advanced burn options to set the correct cpu type.").arg(DeviceStr));
} else { }
else {
FirmwareInfo *firmware = GetCurrentFirmware(); FirmwareInfo *firmware = GetCurrentFirmware();
QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->name)); QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->name));
} }
@ -333,7 +342,7 @@ void avrOutputDialog::doAddTextStdErr()
currLine.append(text); currLine.append(text);
if (currLine.contains("#")) { if (currLine.contains("#")) {
avrphase=currLine.left(1).toLower(); avrphase = currLine.left(1).toLower();
if (avrphase=="w") { if (avrphase=="w") {
ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #ff0000; text-align:center;}:"); ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #ff0000; text-align:center;}:");
phase=1; phase=1;
@ -344,14 +353,15 @@ void avrOutputDialog::doAddTextStdErr()
pbvalue=currLine.count("#")*2; pbvalue=currLine.count("#")*2;
ui->progressBar->setValue(pbvalue); ui->progressBar->setValue(pbvalue);
} }
if (avrphase=="r") { else if (avrphase=="r") {
if (phase==0) { if (phase==0) {
ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #00ff00; text-align:center;}:"); ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #00ff00; text-align:center;}:");
if(winTitle.isEmpty()) if(winTitle.isEmpty())
setWindowTitle(getProgrammer() + " - " + tr("Reading")); setWindowTitle(getProgrammer() + " - " + tr("Reading"));
else else
setWindowTitle(getProgrammer() + " - " + winTitle + " - " + tr("Reading")); setWindowTitle(getProgrammer() + " - " + winTitle + " - " + tr("Reading"));
} else { }
else {
ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #0000ff; text-align:center;}:"); ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #0000ff; text-align:center;}:");
phase=2; phase=2;
if(winTitle.isEmpty()) if(winTitle.isEmpty())
@ -363,11 +373,12 @@ void avrOutputDialog::doAddTextStdErr()
ui->progressBar->setValue(pbvalue); ui->progressBar->setValue(pbvalue);
} }
} }
if (currLine.contains("\n")) { if (currLine.contains("\n")) {
nlPos=currLine.lastIndexOf("\n"); nlPos = currLine.lastIndexOf("\n");
prevLine=currLine.left(nlPos).trimmed(); currLine = currLine.mid(nlPos+1);
currLine=currLine.mid(nlPos+1);
} }
if (text.contains("-E-") && !text.contains("-E- No receive file name")) { if (text.contains("-E-") && !text.contains("-E- No receive file name")) {
hasErrors = true; hasErrors = true;
} }
@ -376,6 +387,7 @@ void avrOutputDialog::doAddTextStdErr()
} }
#define HLINE_SEPARATOR "=================================================================================" #define HLINE_SEPARATOR "================================================================================="
void avrOutputDialog::doFinished(int code=0) void avrOutputDialog::doFinished(int code=0)
{ {
addText("\n" HLINE_SEPARATOR); addText("\n" HLINE_SEPARATOR);
@ -385,17 +397,22 @@ void avrOutputDialog::doFinished(int code=0)
if (code) { if (code) {
ui->checkBox->setChecked(true); ui->checkBox->setChecked(true);
addText("\n" + getProgrammer() + " " + tr("done - exit code %1").arg(code)); addText("\n" + getProgrammer() + " " + tr("done - exit code %1").arg(code));
} else if (hasErrors) { }
else if (hasErrors) {
ui->checkBox->setChecked(true); ui->checkBox->setChecked(true);
addText("\n" + getProgrammer() + " " + tr("done with errors")); addText("\n" + getProgrammer() + " " + tr("done with errors"));
} else if (!cmdLine.isEmpty()) { }
else if (!cmdLine.isEmpty()) {
addText("\n" + getProgrammer() + " " + tr("done - SUCCESSFUL")); addText("\n" + getProgrammer() + " " + tr("done - SUCCESSFUL"));
} else { }
else {
addText(tr("done - SUCCESSFUL")); addText(tr("done - SUCCESSFUL"));
} }
addText("\n" HLINE_SEPARATOR "\n"); addText("\n" HLINE_SEPARATOR "\n");
if(lfuse || hfuse || efuse) addReadFuses(); if(lfuse || hfuse || efuse) {
addReadFuses();
}
switch(closeOpt) switch(closeOpt)
{ {
@ -417,7 +434,8 @@ void avrOutputDialog::doFinished(int code=0)
if (!cmdLine.isEmpty()) { if (!cmdLine.isEmpty()) {
if (getProgrammer()!="AVRDUDE") { if (getProgrammer()!="AVRDUDE") {
QMessageBox::critical(this, "Companion", getProgrammer() + " " + tr("did not finish correctly")); QMessageBox::critical(this, "Companion", getProgrammer() + " " + tr("did not finish correctly"));
} else { }
else {
int res = QMessageBox::question(this, "Companion",getProgrammer() + " " + tr("did not finish correctly!\nDo you want some help ?"),QMessageBox::Yes | QMessageBox::No); int res = QMessageBox::question(this, "Companion",getProgrammer() + " " + tr("did not finish correctly!\nDo you want some help ?"),QMessageBox::Yes | QMessageBox::No);
if (res != QMessageBox::No) { if (res != QMessageBox::No) {
errorWizard(); errorWizard();
@ -427,12 +445,14 @@ void avrOutputDialog::doFinished(int code=0)
QMessageBox::critical(this, "Companion", tr("Copy did not finish correctly")); QMessageBox::critical(this, "Companion", tr("Copy did not finish correctly"));
} }
// reject(); // reject();
} else { }
else {
if (!cmdLine.isEmpty()) { if (!cmdLine.isEmpty()) {
ui->progressBar->setValue(100); ui->progressBar->setValue(ui->progressBar->maximum());
QMessageBox::information(this, "Companion", getProgrammer() + " " + tr("finished correctly")); QMessageBox::information(this, "Companion", getProgrammer() + " " + tr("finished correctly"));
accept(); accept();
} else { }
else {
QMessageBox::information(this, "Companion", tr("Copy finished correctly")); QMessageBox::information(this, "Companion", tr("Copy finished correctly"));
accept(); accept();
} }
@ -454,8 +474,6 @@ void avrOutputDialog::doProcessStarted()
addText("\n" HLINE_SEPARATOR "\n"); addText("\n" HLINE_SEPARATOR "\n");
} }
void avrOutputDialog::addReadFuses() void avrOutputDialog::addReadFuses()
{ {
addText(HLINE_SEPARATOR "\n"); addText(HLINE_SEPARATOR "\n");
@ -463,19 +481,23 @@ void avrOutputDialog::addReadFuses()
addText("\n" HLINE_SEPARATOR "\n"); addText("\n" HLINE_SEPARATOR "\n");
} }
void avrOutputDialog::on_checkBox_toggled(bool checked) { void avrOutputDialog::on_checkBox_toggled(bool checked)
{
if (checked) { if (checked) {
ui->plainTextEdit->show(); ui->plainTextEdit->show();
} else { }
ui->plainTextEdit->hide(); else {
QTimer::singleShot(0, this, SLOT(shrink())); ui->plainTextEdit->hide();
QTimer::singleShot(0, this, SLOT(shrink()));
} }
} }
void avrOutputDialog::shrink() { void avrOutputDialog::shrink()
{
resize(0,0); resize(0,0);
} }
void avrOutputDialog::forceClose() { void avrOutputDialog::forceClose()
accept();; {
accept();
} }

View file

@ -52,9 +52,7 @@ private:
quint8 lfuse; quint8 lfuse;
quint8 hfuse; quint8 hfuse;
quint8 efuse; quint8 efuse;
QString prevLine;
QString currLine; QString currLine;
QString prevStdLine;
QString currStdLine; QString currStdLine;
int phase; int phase;
QString winTitle; QString winTitle;