diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 6db3d9fe9..5b03b1d0f 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -144,21 +144,29 @@ add_library(common ${common_SRCS}) set(companion_SRCS hexinterface.cpp - flashinterface.cpp + firmwareinterface.cpp + converteeprom.cpp # xmlinterface.cpp # ${PROJECT_BINARY_DIR}/radio.cxx helpers.cpp + helpers_html.cpp mdichild.cpp modelslist.cpp mountlist.cpp - avroutputdialog.cpp apppreferencesdialog.cpp fwpreferencesdialog.cpp burnconfigdialog.cpp comparedialog.cpp contributorsdialog.cpp customizesplashdialog.cpp - burndialog.cpp + radiointerface.cpp + progresswidget.cpp + progressdialog.cpp + process_copy.cpp + process_flash.cpp + process_sync.cpp + flashfirmwaredialog.cpp + flasheepromdialog.cpp printdialog.cpp fusesdialog.cpp logsdialog.cpp @@ -173,7 +181,6 @@ set(companion_SRCS ) set(companion_MOC_HDRS - avroutputdialog.h apppreferencesdialog.h fwpreferencesdialog.h burnconfigdialog.h @@ -185,7 +192,13 @@ set(companion_MOC_HDRS customizesplashdialog.h splashlibrary.h splashlabel.h - burndialog.h + progresswidget.h + progressdialog.h + process_copy.h + process_flash.h + process_sync.h + flashfirmwaredialog.h + flasheepromdialog.h downloaddialog.h modelslist.h mdichild.h @@ -198,7 +211,6 @@ set(companion_MOC_HDRS set(companion_UIS mdichild.ui - avroutputdialog.ui comparedialog.ui fusesdialog.ui logsdialog.ui @@ -210,7 +222,10 @@ set(companion_UIS contributorsdialog.ui customizesplashdialog.ui splashlibrary.ui - burndialog.ui + progresswidget.ui + progressdialog.ui + flashfirmwaredialog.ui + flasheepromdialog.ui radionotfound.ui ) diff --git a/companion/src/appdata.cpp b/companion/src/appdata.cpp index ddd1a89ae..f9ff82d8e 100644 --- a/companion/src/appdata.cpp +++ b/companion/src/appdata.cpp @@ -498,8 +498,6 @@ QString AppData::libDir() { return _libDir; } QString AppData::snapshotDir() { return _snapshotDir; } QString AppData::updatesDir() { return _updatesDir; } -bool AppData::enableBackup() { return _enableBackup; } -bool AppData::backupOnFlash() { return _backupOnFlash; } bool AppData::jsSupport() { return _jsSupport; } bool AppData::maximized() { return _maximized; } bool AppData::showSplash() { return _showSplash; } @@ -548,8 +546,6 @@ void AppData::libDir (const QString x) { store(x, _libDir, void AppData::snapshotDir (const QString x) { store(x, _snapshotDir, "snapshotpath" );} void AppData::updatesDir (const QString x) { store(x, _updatesDir, "lastUpdatesDir" );} -void AppData::enableBackup (const bool x) { store(x, _enableBackup, "backupEnable" );} -void AppData::backupOnFlash (const bool x) { store(x, _backupOnFlash, "backupOnFlash" );} void AppData::maximized (const bool x) { store(x, _maximized, "maximized" );} void AppData::jsSupport (const bool x) { store(x, _jsSupport, "js_support" );} void AppData::showSplash (const bool x) { store(x, _showSplash, "show_splash" );} @@ -674,6 +670,7 @@ AppData::AppData() getset( _snapshotDir, "snapshotpath" ,"" ); getset( _updatesDir, "lastUpdatesDir" ,"" ); + getset( _outputDisplayDetails, "outputDisplayDetails" ,false ); getset( _enableBackup, "backupEnable" ,false ); getset( _backupOnFlash, "backupOnFlash" ,true ); getset( _jsSupport, "js_support" ,false ); diff --git a/companion/src/appdata.h b/companion/src/appdata.h index 0633ebb92..53148bf34 100644 --- a/companion/src/appdata.h +++ b/companion/src/appdata.h @@ -188,8 +188,19 @@ class Profile: protected CompStoreObj void flush(); }; +#define BOOL_PROPERTY(name, dflt) \ + public: \ + inline bool name() { return _ ## name; } \ + void name(const bool val) { store(val, _ ## name, # name); } \ + private: \ + bool _ ## name; + class AppData: protected CompStoreObj { + BOOL_PROPERTY(enableBackup, false) + BOOL_PROPERTY(outputDisplayDetails, false) + BOOL_PROPERTY(backupOnFlash, true) + // All the global variables public: Profile profile[MAX_PROFILES]; @@ -224,8 +235,6 @@ class AppData: protected CompStoreObj QString _snapshotDir; QString _updatesDir; - bool _enableBackup; - bool _backupOnFlash; bool _maximized; bool _jsSupport; bool _showSplash; @@ -276,8 +285,6 @@ class AppData: protected CompStoreObj QString snapshotDir(); QString updatesDir(); - bool enableBackup(); - bool backupOnFlash(); bool jsSupport(); bool maximized(); bool showSplash(); @@ -327,8 +334,6 @@ class AppData: protected CompStoreObj void snapshotDir (const QString); void updatesDir (const QString); - void enableBackup (const bool); - void backupOnFlash (const bool); void maximized (const bool); void jsSupport (const bool); void showSplash (const bool); diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index 2010151d4..0232c787c 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -3,7 +3,7 @@ #include "mainwindow.h" #include "appdata.h" #include "helpers.h" -#include "flashinterface.h" +#include "firmwareinterface.h" #ifdef JOYSTICKS #include "joystick.h" #include "joystickdialog.h" @@ -182,9 +182,9 @@ void AppPreferencesDialog::initSettings() } ui->lblGeneralSettings->setText(hwSettings); - FirmwareInterface * current_firmware = GetCurrentFirmware(); + Firmware * current_firmware = GetCurrentFirmware(); - foreach(FirmwareInterface * firmware, firmwares) { + foreach(Firmware * firmware, firmwares) { ui->downloadVerCB->addItem(firmware->getName(), firmware->getId()); if (current_firmware->getFirmwareBase() == firmware) { ui->downloadVerCB->setCurrentIndex(ui->downloadVerCB->count() - 1); @@ -347,7 +347,7 @@ void AppPreferencesDialog::baseFirmwareChanged() { QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - foreach(FirmwareInterface * firmware, firmwares) { + foreach(Firmware * firmware, firmwares) { if (firmware->getId() == selected_firmware) { populateFirmwareOptions(firmware); break; @@ -355,11 +355,11 @@ void AppPreferencesDialog::baseFirmwareChanged() } } -FirmwareInterface * AppPreferencesDialog::getFirmwareVariant() +Firmware * AppPreferencesDialog::getFirmwareVariant() { QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); - foreach(FirmwareInterface * firmware, firmwares) { + foreach(Firmware * firmware, firmwares) { QString id = firmware->getId(); if (id == selected_firmware) { foreach(QCheckBox *cb, optionsCheckBoxes) { @@ -390,7 +390,7 @@ void AppPreferencesDialog::firmwareOptionChanged(bool state) if (cb == voice) { showVoice(voice->isChecked()); } - FirmwareInterface * firmware=NULL; + Firmware * firmware=NULL; if (cb && state) { QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); foreach(firmware, firmwares) { @@ -416,9 +416,9 @@ void AppPreferencesDialog::firmwareOptionChanged(bool state) } } -void AppPreferencesDialog::populateFirmwareOptions(const FirmwareInterface * firmware) +void AppPreferencesDialog::populateFirmwareOptions(const Firmware * firmware) { - const FirmwareInterface * parent = firmware->getFirmwareBase(); + const Firmware * parent = firmware->getFirmwareBase(); updateLock = true; diff --git a/companion/src/apppreferencesdialog.h b/companion/src/apppreferencesdialog.h index fd4e52ad4..2e5a3641f 100644 --- a/companion/src/apppreferencesdialog.h +++ b/companion/src/apppreferencesdialog.h @@ -27,8 +27,8 @@ class AppPreferencesDialog : public QDialog void showVoice(); void hideVoice(); void populateLocale(); - void populateFirmwareOptions(const FirmwareInterface *); - FirmwareInterface * getFirmwareVariant(); + void populateFirmwareOptions(const Firmware *); + Firmware * getFirmwareVariant(); QCheckBox * voice; Ui::AppPreferencesDialog *ui; diff --git a/companion/src/avroutputdialog.cpp b/companion/src/avroutputdialog.cpp deleted file mode 100644 index fd3862ee5..000000000 --- a/companion/src/avroutputdialog.cpp +++ /dev/null @@ -1,504 +0,0 @@ -#include "avroutputdialog.h" -#include "ui_avroutputdialog.h" -#include -#include "eeprominterface.h" -#include "flashinterface.h" - -#if defined WIN32 || !defined __GNUC__ -#include -#include -#include -#define sleep(x) Sleep(x*1000) -#else -#include -#include "mountlist.h" -#endif - -avrOutputDialog::avrOutputDialog(QWidget *parent, QString prog, QStringList arg, QString wTitle, int closeBehaviour, bool displayDetails) : - QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), - ui(new Ui::avrOutputDialog), - kill_timer(NULL), - hasErrors(false) -{ - ui->setupUi(this); - -#ifdef __APPLE__ - QFont newFont("Courier", 13); - ui->plainTextEdit->setFont(newFont); - ui->plainTextEdit->setAttribute(Qt::WA_MacNormalSize); -#endif -#if defined WIN32 || !defined __GNUC__ - QFont newFont("Courier", 9); - ui->plainTextEdit->setFont(newFont); -#endif - - cmdLine = prog; - closeOpt = closeBehaviour; - if (cmdLine.isEmpty()) { - if (arg.count()<2) { - closeOpt = AVR_DIALOG_FORCE_CLOSE; - QTimer::singleShot(0, this, SLOT(forceClose())); - } - else { - sourceFile=arg.at(0); - destFile=arg.at(1); - if (!displayDetails) { - ui->plainTextEdit->hide(); - QTimer::singleShot(0, this, SLOT(shrink())); - } else { - ui->checkBox->setChecked(true); - } - ui->progressBar->setMaximum(127); - QTimer::singleShot(500, this, SLOT(doCopy())); - } - } - else { - if (wTitle.isEmpty()) - setWindowTitle(getProgrammer() + " " + tr("result")); - else - setWindowTitle(getProgrammer() + " - " + wTitle); - QFile exec; - winTitle=wTitle; - if (!(exec.exists(prog))) { - QMessageBox::critical(this, "Companion", getProgrammer() + " " + tr("executable not found")); - closeOpt = AVR_DIALOG_FORCE_CLOSE; - QTimer::singleShot(0, this, SLOT(forceClose())); - } - else { - foreach(QString str, arg) cmdLine.append(" " + str); - lfuse = 0; - hfuse = 0; - efuse = 0; - phase=0; - currLine.clear(); - if (!displayDetails) { - ui->plainTextEdit->hide(); - QTimer::singleShot(0, this, SLOT(shrink())); - } - else { - ui->checkBox->setChecked(true); - } - process = new QProcess(this); - connect(process,SIGNAL(readyReadStandardError()), this, SLOT(doAddTextStdErr())); - connect(process,SIGNAL(started()),this,SLOT(doProcessStarted())); - connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(doAddTextStdOut())); - connect(process,SIGNAL(finished(int)),this,SLOT(doFinished(int))); - - #if !__GNUC__ - kill_timer = new QTimer(this); - connect(kill_timer, SIGNAL(timeout()), this, SLOT(killTimerElapsed())); - kill_timer->start(2000); - #endif - - process->start(prog,arg); - } - } -} - -# if !__GNUC__ -BOOL KillProcessByName(char *szProcessToKill){ - HANDLE hProcessSnap; - HANDLE hProcess; - PROCESSENTRY32 pe32; - DWORD dwPriorityClass; - - hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // Takes a snapshot of all the processes - - if(hProcessSnap == INVALID_HANDLE_VALUE){ - return( FALSE ); - } - - pe32.dwSize = sizeof(PROCESSENTRY32); - - if(!Process32First(hProcessSnap, &pe32)){ - CloseHandle(hProcessSnap); - return( FALSE ); - } - - do{ - if(!strcmp(pe32.szExeFile,szProcessToKill)){ // checks if process at current position has the name of to be killed app - hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID); // gets handle to process - TerminateProcess(hProcess,0); // Terminate process by handle - CloseHandle(hProcess); // close the handle - } - }while(Process32Next(hProcessSnap,&pe32)); // gets next member of snapshot - - CloseHandle(hProcessSnap); // closes the snapshot handle - return( TRUE ); -} -#endif - -void avrOutputDialog::doCopy() -{ - char buf[BLKSIZE]; - - QFile source(sourceFile); - int blocks = (source.size() + BLKSIZE - 1) / BLKSIZE; - ui->progressBar->setMaximum(blocks-1); - - if (source.open(QIODevice::ReadOnly)) { - QFile dest(destFile); - if (dest.open(QIODevice::WriteOnly)) { - addText(tr("Writing file: ")); - for (int i=0; iprogressBar->setValue(i); - if ((i%2) != 0) - addText("#"); - } - else { - QMessageBox::warning(this, tr("Error"), tr("Write error")); - break; - } - } - dest.close(); - } - else { - QMessageBox::warning(this, tr("Error"),tr("Cannot write destination") + ": " + dest.fileName() + ", " + tr("reason") + ": " + dest.errorString()); - } - } - else { - QMessageBox::warning(this, tr("Error"),tr("Cannot open source file") + ": " + source.fileName() + ", " + tr("reason") + ": " + source.errorString()); - } - - source.close(); - doFinished(0); -} - -void avrOutputDialog::killTimerElapsed() -{ - delete kill_timer; - kill_timer = NULL; -# if !__GNUC__ - KillProcessByName("tasklist.exe"); -#endif -} - -avrOutputDialog::~avrOutputDialog() -{ - delete ui; - delete kill_timer; -} - -void avrOutputDialog::runAgain(QString prog, QStringList arg, int closeBehaviour) -{ - cmdLine = prog; - foreach(QString str, arg) cmdLine.append(" " + str); - closeOpt = closeBehaviour; - currLine.clear(); - process->start(prog,arg); -} - -void avrOutputDialog::waitForFinish() -{ - process->waitForFinished(); -} - -void avrOutputDialog::addText(const QString &text) -{ - QTextCursor cursor(ui->plainTextEdit->textCursor()); - - // 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() -{ - QByteArray data = process->readAllStandardOutput(); - QString text = QString(data); - QString temp; - int nlPos, pos, size; - - addText(text); - - currStdLine.append(text); - if (currStdLine.contains("size = ")) { - pos = currStdLine.lastIndexOf("size = "); - temp = currStdLine.mid(pos+7); - pos = temp.lastIndexOf("\n"); - size = temp.left(pos).toInt(); - ui->progressBar->setMaximum(size/2048); - } - if (currStdLine.contains("\n")) { - nlPos = currStdLine.lastIndexOf("\n"); - currStdLine = currStdLine.mid(nlPos+1); - } - if (!currStdLine.isEmpty()) { - if (currStdLine.at(0) == QChar('.')) { - pos = currStdLine.lastIndexOf("."); - ui->progressBar->setValue(pos); - } - else if (currStdLine.startsWith("Starting upload: [")) { - pos = (currStdLine.lastIndexOf("#")-19)/(MAX_FSIZE/204800.0); - ui->progressBar->setValue(pos); - } - } - - if (text.contains("Complete ")) { -#if !__GNUC__ - delete kill_timer; - kill_timer = NULL; -#endif - int start = text.indexOf("Complete "); - int end = text.indexOf("%"); - if (start > 0) { - start += 9; - int value = text.mid(start, end-start).toInt(); - ui->progressBar->setValue(value); - } - } - - if (text.contains(":010000")) { - //contains fuse info - QStringList stl = text.split(":01000000"); - foreach (QString t, stl) { - 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-")) { - hasErrors = true; - } - -} - -QString avrOutputDialog::getProgrammer() -{ - EEPROMInterface *eepromInterface = GetEepromInterface(); - if (IS_TARANIS(eepromInterface->getBoard())) { - return "DFU Util"; - } - else if IS_SKY9X(eepromInterface->getBoard()) { - return "SAM-BA"; - } - else { - return "AVRDUDE"; - } -} - -void avrOutputDialog::errorWizard() -{ - QString output=ui->plainTextEdit->toPlainText(); - if (output.contains("avrdude: Expected signature for")) { // wrong signature - int pos=output.indexOf("avrdude: Device signature = "); - bool fwexist=false; - QString DeviceStr="Unknown"; - QString FwStr=""; - - if (pos>0) { - QString DeviceId=output.mid(pos+28,8); - if (DeviceId=="0x1e9602") { - DeviceStr="Atmega 64"; - FwStr="\n"+tr("ie: OpenTX for 9X board or OpenTX for 9XR board"); - fwexist=true; - } - else if (DeviceId=="0x1e9702") { - DeviceStr="Atmega 128"; - FwStr="\n"+tr("ie: OpenTX for M128 / 9X board or OpenTX for 9XR board with M128 chip"); - fwexist=true; - } - else if (DeviceId=="0x1e9703") { - DeviceStr="Atmega 1280"; - } - else if (DeviceId=="0x1e9704") { - DeviceStr="Atmega 1281"; - } - else if (DeviceId=="0x1e9801") { - DeviceStr="Atmega 2560"; - FwStr="\n"+tr("ie: OpenTX for Gruvin9X board"); - fwexist=true; - } - else if (DeviceId=="0x1e9802") { - DeviceStr="Atmega 2561"; - } - } - 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)); - } - else { - FirmwareInterface *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->getName())); - } - } -} - -void avrOutputDialog::doAddTextStdErr() -{ - int nlPos; - int pbvalue; - QString avrphase; - QByteArray data = process->readAllStandardError(); - QString text = QString(data); - - currLine.append(text); - if (currLine.contains("#")) { - avrphase = currLine.left(1).toLower(); - if (avrphase=="w") { - ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #ff0000; text-align:center;}:"); - phase=1; - if(winTitle.isEmpty()) - setWindowTitle(getProgrammer() + " - " + tr("Writing")); - else - setWindowTitle(getProgrammer() + " - " + winTitle + " - " + tr("Writing")); - pbvalue=currLine.count("#")*2; - ui->progressBar->setValue(pbvalue); - } - else if (avrphase=="r") { - if (phase==0) { - ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #00ff00; text-align:center;}:"); - if(winTitle.isEmpty()) - setWindowTitle(getProgrammer() + " - " + tr("Reading")); - else - setWindowTitle(getProgrammer() + " - " + winTitle + " - " + tr("Reading")); - } - else { - ui->progressBar->setStyleSheet("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: #0000ff; text-align:center;}:"); - phase=2; - if(winTitle.isEmpty()) - setWindowTitle(getProgrammer() + " - " + tr("Verifying")); - else - setWindowTitle(getProgrammer() + " - " + winTitle + " - " + tr("Verifying")); - } - pbvalue=currLine.count("#")*2; - ui->progressBar->setValue(pbvalue); - } - } - - if (currLine.contains("\n")) { - nlPos = currLine.lastIndexOf("\n"); - currLine = currLine.mid(nlPos+1); - } - - if (text.contains("-E-") && !text.contains("-E- No receive file name")) { - hasErrors = true; - } - - addText(text); -} - -#define HLINE_SEPARATOR "=================================================================================" - -void avrOutputDialog::doFinished(int code=0) -{ - addText("\n" HLINE_SEPARATOR); - if (code==1 && getProgrammer()=="SAM-BA") - code=0; - - if (code) { - ui->checkBox->setChecked(true); - addText("\n" + getProgrammer() + " " + tr("done - exit code %1").arg(code)); - } - else if (hasErrors) { - ui->checkBox->setChecked(true); - addText("\n" + getProgrammer() + " " + tr("done with errors")); - } - else if (!cmdLine.isEmpty()) { - addText("\n" + getProgrammer() + " " + tr("done - SUCCESSFUL")); - } - else { - addText(tr("done - SUCCESSFUL")); - } - addText("\n" HLINE_SEPARATOR "\n"); - - if(lfuse || hfuse || efuse) { - addReadFuses(); - } - - switch(closeOpt) - { - case AVR_DIALOG_CLOSE_IF_SUCCESSFUL: - if (!hasErrors && !code) accept(); - if (code) { - errorWizard(); - } - break; - case AVR_DIALOG_FORCE_CLOSE: - if (hasErrors || code) - reject(); - else - accept(); - break; - - case AVR_DIALOG_SHOW_DONE: - if (hasErrors || code) { - if (!cmdLine.isEmpty()) { - if (getProgrammer()!="AVRDUDE") { - QMessageBox::critical(this, "Companion", getProgrammer() + " " + tr("did not finish correctly")); - } - else { - 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) { - errorWizard(); - } - } - } - else { - QMessageBox::critical(this, "Companion", tr("Copy did not finish correctly")); - } - // reject(); - } - else { - if (!cmdLine.isEmpty()) { - ui->progressBar->setValue(ui->progressBar->maximum()); - QMessageBox::information(this, "Companion", getProgrammer() + " " + tr("finished correctly")); - accept(); - } - else { - QMessageBox::information(this, "Companion", tr("Copy finished correctly")); - accept(); - } - } - break; - - default: //AVR_DIALOG_KEEP_OPEN - break; - } -} - -void avrOutputDialog::doProcessStarted() -{ - addText(HLINE_SEPARATOR "\n"); - addText(tr("Started") + " " + getProgrammer() + "\n"); - addText(cmdLine); - addText("\n" HLINE_SEPARATOR "\n"); -} - -void avrOutputDialog::addReadFuses() -{ - addText(HLINE_SEPARATOR "\n"); - addText(tr("FUSES: Low=%1 High=%2 Ext=%3").arg(lfuse,2,16,QChar('0')).arg(hfuse,2,16,QChar('0')).arg(efuse,2,16,QChar('0'))); - addText("\n" HLINE_SEPARATOR "\n"); -} - -void avrOutputDialog::on_checkBox_toggled(bool checked) -{ - if (checked) { - ui->plainTextEdit->show(); - } - else { - ui->plainTextEdit->hide(); - QTimer::singleShot(0, this, SLOT(shrink())); - } -} - -void avrOutputDialog::shrink() -{ - resize(0,0); -} - -void avrOutputDialog::forceClose() -{ - accept(); -} diff --git a/companion/src/avroutputdialog.h b/companion/src/avroutputdialog.h deleted file mode 100644 index 52099ace7..000000000 --- a/companion/src/avroutputdialog.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef AVROUTPUTDIALOG_H -#define AVROUTPUTDIALOG_H - -#include -#include - -#define AVR_DIALOG_CLOSE_IF_SUCCESSFUL 0x00 -#define AVR_DIALOG_KEEP_OPEN 0x01 -#define AVR_DIALOG_FORCE_CLOSE 0x02 -#define AVR_DIALOG_SHOW_DONE 0x04 -#define READBUF 65536 -#define BLKSIZE 512 - - -namespace Ui { - class avrOutputDialog; -} - -class avrOutputDialog : public QDialog -{ - Q_OBJECT - - public: - explicit avrOutputDialog(QWidget *parent, QString prog, QStringList arg, QString wTitle, int closeBehaviour=AVR_DIALOG_CLOSE_IF_SUCCESSFUL, bool displayDetails=false); - ~avrOutputDialog(); - - void addText(const QString &text); - void runAgain(QString prog, QStringList arg, int closeBehaviour=AVR_DIALOG_CLOSE_IF_SUCCESSFUL); - void waitForFinish(); - void addReadFuses(); - - protected slots: - void doAddTextStdOut(); - void doAddTextStdErr(); - void doProcessStarted(); - void doCopy(); - void doFinished(int code); - void on_checkBox_toggled(bool checked); - void shrink(); - void forceClose(); - void killTimerElapsed(); - void errorWizard(); - - private: - QString getProgrammer(); - Ui::avrOutputDialog *ui; - - QProcess *process; - QTimer *kill_timer; - QString cmdLine; - int closeOpt; - quint8 lfuse; - quint8 hfuse; - quint8 efuse; - QString currLine; - QString currStdLine; - int phase; - QString winTitle; - bool hasErrors; - QString sourceFile; - QString destFile; - -}; - -#endif // AVROUTPUTDIALOG_H diff --git a/companion/src/burnconfigdialog.cpp b/companion/src/burnconfigdialog.cpp index 3c52fbecc..9c9942ffc 100644 --- a/companion/src/burnconfigdialog.cpp +++ b/companion/src/burnconfigdialog.cpp @@ -1,10 +1,10 @@ #include "burnconfigdialog.h" #include "ui_burnconfigdialog.h" -#include "avroutputdialog.h" #include "eeprominterface.h" #include "helpers.h" #include "appdata.h" -#include +#include "progressdialog.h" +#include "process_flash.h" #if !defined WIN32 && defined __GNUC__ #include @@ -123,7 +123,7 @@ void burnConfigDialog::getSettings() sambaPort = g.sambaPort(); ui->avrdude_location->setText(getAVRDUDE()); - ui->avrArgs->setText(getAVRArgs().join(" ")); + ui->avrArgs->setText(avrArgs.join(" ")); ui->samba_location->setText(getSAMBA()); ui->samba_port->setText(getSambaPort()); @@ -285,118 +285,25 @@ void burnConfigDialog::on_dfuArgs_editingFinished() dfuArgs = ui->dfuArgs->text().split(" ", QString::SkipEmptyParts); } -void burnConfigDialog::listProgrammers() +void burnConfigDialog::listAvrdudeProgrammers() { - QStringList arguments; - arguments << "-c?"; - avrOutputDialog *ad = new avrOutputDialog(this, ui->avrdude_location->text(), arguments, "List available programmers", AVR_DIALOG_KEEP_OPEN, TRUE); - ad->setWindowIcon(CompanionIcon("list.png")); - ad->show(); - delete ad; + ProgressDialog progressDialog(this, tr("List available programmers"), CompanionIcon("list.png"), true); + FlashProcess flashProcess(ui->avrdude_location->text(), QStringList() << "-c?", progressDialog.progress()); + flashProcess.run(); } +// TODO choose better name when no merge in progress.... void burnConfigDialog::on_pushButton_3_clicked() { - listProgrammers(); + listAvrdudeProgrammers(); } - - +// TODO choose better name when no merge in progress.... void burnConfigDialog::on_pushButton_4_clicked() { - QStringList arguments; - arguments << "-?"; - - avrOutputDialog *ad = new avrOutputDialog(this, ui->avrdude_location->text(), arguments, "Show help", AVR_DIALOG_KEEP_OPEN,TRUE); - ad->setWindowIcon(CompanionIcon("configure.png")); - ad->show(); - delete ad; -} - - -void burnConfigDialog::readFuses() -{ - QStringList args = avrArgs; - if(!avrPort.isEmpty()) args << "-P" << avrPort; - - QStringList str; - str << "-U" << "lfuse:r:-:i" << "-U" << "hfuse:r:-:i" << "-U" << "efuse:r:-:i"; - - QStringList arguments; - arguments << "-c" << avrProgrammer << "-p" << avrMCU << args << str; - - avrOutputDialog *ad = new avrOutputDialog(this, avrLoc, arguments, "Read Fuses",AVR_DIALOG_KEEP_OPEN,TRUE); - ad->setWindowIcon(CompanionIcon("fuses.png")); - ad->show(); - delete ad; -} - -void burnConfigDialog::restFuses(bool eeProtect) -{ - //fuses - //avrdude -c usbasp -p m64 -U lfuse:w:<0x0E>:m - //avrdude -c usbasp -p m64 -U hfuse:w:<0x89>:m 0x81 for eeprom protection - //avrdude -c usbasp -p m64 -U efuse:w:<0xFF>:m - - QMessageBox::StandardButton ret = QMessageBox::No; - ret = QMessageBox::warning(this, tr("Companion"), - tr("WARNING!
This will reset the fuses of %1 to the factory settings.
Writing fuses can mess up your radio.
Do this only if you are sure they are wrong!
Are you sure you want to continue?").arg(avrMCU), - QMessageBox::Yes | QMessageBox::No); - if (ret == QMessageBox::Yes) - { - QStringList args = avrArgs; - if(!avrPort.isEmpty()) args << "-P" << avrPort; - QStringList str; - if (avrMCU=="m2560") { - args << "-B8"; - QString erStr = eeProtect ? "hfuse:w:0x11:m" : "hfuse:w:0x19:m"; - str << "-U" << "lfuse:w:0xD7:m" << "-U" << erStr << "-U" << "efuse:w:0xFC:m"; - //use hfuse = 0x81 to prevent eeprom being erased with every flashing - } - else { - QString lfuses; - QString tempFile = generateProcessUniqueTempFileName("ftemp.bin"); - QStringList argread; - argread << "-c" << avrProgrammer << "-p" << avrMCU << args <<"-U" << "lfuse:r:"+tempFile+":r" ; - avrOutputDialog *ad = new avrOutputDialog(this, avrLoc, argread, "Reset Fuses",AVR_DIALOG_CLOSE_IF_SUCCESSFUL,FALSE); - ad->setWindowIcon(CompanionIcon("fuses.png")); - ad->exec(); - delete ad; - QFile file(tempFile); - if (file.exists() && file.size()==1) { - file.open(QIODevice::ReadOnly); - char bin_flash[1]; - file.read(bin_flash, 1); - if (bin_flash[0]==0x0E) { - lfuses="lfuse:w:0x0E:m"; - } - else { - lfuses="lfuse:w:0x3F:m"; - } - file.close(); - qunlink(tempFile); - } - else { - lfuses="lfuse:w:0x3F:m"; - } - - QString erStr = eeProtect ? "hfuse:w:0x81:m" : "hfuse:w:0x89:m"; - str << "-U" << lfuses << "-U" << erStr << "-U" << "efuse:w:0xFF:m"; - //use hfuse = 0x81 to prevent eeprom being erased with every flashing - } - QStringList arguments; - if (avrMCU=="m2560") { - arguments << "-c" << avrProgrammer << "-p" << avrMCU << args << "-u" << str; - } - else { - arguments << "-c" << avrProgrammer << "-p" << avrMCU << args << "-B" << "100" << "-u" << str; - } - avrOutputDialog *ad = new avrOutputDialog(this, avrLoc, arguments, "Reset Fuses",AVR_DIALOG_KEEP_OPEN,TRUE); - ad->setWindowIcon(CompanionIcon("fuses.png")); - ad->show(); - delete ad; - } - + ProgressDialog progressDialog(this, tr("Avrdude help"), CompanionIcon("configure.png"), true); + FlashProcess flashProcess(ui->avrdude_location->text(), QStringList() << "-?", progressDialog.progress()); + flashProcess.run(); } void burnConfigDialog::on_advCtrChkB_toggled(bool checked) diff --git a/companion/src/burnconfigdialog.h b/companion/src/burnconfigdialog.h index fd99a2925..569763fa8 100644 --- a/companion/src/burnconfigdialog.h +++ b/companion/src/burnconfigdialog.h @@ -1,5 +1,5 @@ -#ifndef BURNCONFIGDIALOG_H -#define BURNCONFIGDIALOG_H +#ifndef BURNCONFIGDIALOG_H_ +#define BURNCONFIGDIALOG_H_ #include #include @@ -23,7 +23,7 @@ public: QString getAVRDUDE() {return avrLoc;} QString getSAMBA() {return sambaLoc;} QString getDFU() {return dfuLoc;} - QStringList getAVRArgs() {return avrArgs;} + QStringList getAvrdudeArgs() { QStringList args = avrArgs; if (!avrPort.isEmpty()) args << "-P" << avrPort; return args; } QStringList getDFUArgs() {return dfuArgs;} QString getProgrammer() {return avrProgrammer;} QString getMCU() {return avrMCU;} @@ -31,9 +31,7 @@ public: QString getPort() {return avrPort;} QString getSambaPort() {return sambaPort;} - void listProgrammers(); - void restFuses(bool eeProtect); - void readFuses(); + void listAvrdudeProgrammers(); private: Ui::burnConfigDialog *ui; @@ -73,4 +71,4 @@ private slots: void putSettings(); }; -#endif // BURNCONFIGDIALOG_H +#endif // BURNCONFIGDIALOG_H_ diff --git a/companion/src/burndialog.cpp b/companion/src/burndialog.cpp deleted file mode 100644 index b868c2bbe..000000000 --- a/companion/src/burndialog.cpp +++ /dev/null @@ -1,615 +0,0 @@ -#include "burndialog.h" -#include "ui_burndialog.h" - -#include -#include "eeprominterface.h" -#include "helpers.h" -#include "splashlibrary.h" -#include "flashinterface.h" -#include "hexinterface.h" -#include "appdata.h" - -// Type 1 = Burn EEPROM, Type 2= Burn Flash -burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * backupEE, QString DocName): - QDialog(parent), - ui(new Ui::burnDialog), - hexfileName(fileName), - backup(backupEE), - hexType(Type) -{ - ui->setupUi(this); - setWindowIcon(CompanionIcon("write_flash.png")); - - if (!g.profile[g.id()].splashFile().isEmpty()){ - imageSource=PROFILE; - imageFile=g.profile[g.id()].splashFile(); - } - else { - ui->useProfileImageCB->setDisabled(true); - imageSource=FIRMWARE; - imageFile=""; - } - ui->SplashFrame->hide(); - ui->FramFWInfo->hide(); - ui->EEbackupCB->hide(); - ui->EEbackupCB->setCheckState(*backup ? Qt::Checked : Qt::Unchecked); - if (Type == FLASH_FILE_TYPE ) { - ui->EEpromCB->hide(); - ui->profile_label->hide(); - ui->patchcalib_CB->hide(); - ui->patchhw_CB->hide(); - setWindowTitle(tr("Write firmware to Radio")); - if (IS_TARANIS(GetEepromInterface()->getBoard())) { - ui->EEbackupCB->hide(); - } - } - else { - ui->FlashLoadButton->setText(tr("Browse for file")); - ui->profile_label->hide(); - ui->patchcalib_CB->hide(); - ui->patchhw_CB->hide(); - ui->EEpromCB->hide(); - ui->BurnFlashButton->setDisabled(true); - ui->FWFileName->clear(); - ui->DateField->clear(); - ui->versionField->clear(); - ui->ModField->clear(); - ui->FramFWInfo->hide(); - ui->SplashFrame->hide(); - ui->BurnFlashButton->setDisabled(true); - ui->EEbackupCB->hide(); - if (DocName.isEmpty()) { - setWindowTitle(tr("Write Backup to Radio")); - } - else { - setWindowTitle(tr("Write Backup from %1 to Radio").arg(DocName)); - } - ui->profile_label->setText(tr("Current profile")+QString(": ")+g.profile[g.id()].name()); - } - if (!hexfileName->isEmpty()) { - ui->FWFileName->setText(*hexfileName); - if (Type==FLASH_FILE_TYPE) { - checkFw(*hexfileName); - } - else { - burnraw=false; - if (checkeEprom(*hexfileName)) { - QString Name = g.profile[g.id()].name(); - QString calib = g.profile[g.id()].stickPotCalib(); - QString trainercalib = g.profile[g.id()].trainerCalib(); - QString DisplaySet = g.profile[g.id()].display(); - QString BeeperSet = g.profile[g.id()].beeper(); - QString HapticSet = g.profile[g.id()].haptic(); - QString SpeakerSet = g.profile[g.id()].speaker(); - if (!Name.isEmpty()) { - ui->profile_label->show(); - ui->patchcalib_CB->show(); - ui->patchhw_CB->show(); - // TODO I hardcode the number of pots here, should be dependant on the board? - if (!((calib.length()==(NUM_STICKS+3)*12) && (trainercalib.length()==16))) { - ui->patchcalib_CB->setDisabled(true); - } - if (!((DisplaySet.length()==6) && (BeeperSet.length()==4) && (HapticSet.length()==6) && (SpeakerSet.length()==6))) { - ui->patchhw_CB->setDisabled(true); - } - } - else { - ui->profile_label->hide(); - } - if (!IS_TARANIS(GetEepromInterface()->getBoard())) { - ui->EEpromCB->show(); - } - else { - ui->EEpromCB->setChecked(false); - } - ui->BurnFlashButton->setEnabled(true); - } - } - ui->FWFileName->hide(); - ui->FlashLoadButton->hide(); - hexfileName->clear(); - } - else if (Type==FLASH_FILE_TYPE) { - QString FileName = g.profile[g.id()].fwName(); - QFile file(FileName); - if (file.exists()) { - checkFw(FileName); - } - } - updateUI(); - resize(0, 0); -} - -burnDialog::~burnDialog() -{ - delete ui; -} - -void burnDialog::on_FlashLoadButton_clicked() -{ - QString fileName; - - ui->BurnFlashButton->setDisabled(true); - ui->FWFileName->clear(); - ui->DateField->clear(); - ui->versionField->clear(); - ui->ModField->clear(); - ui->FramFWInfo->hide(); - ui->SplashFrame->hide(); - ui->BurnFlashButton->setDisabled(true); - ui->EEbackupCB->hide(); - QTimer::singleShot(0, this, SLOT(shrink())); - if (hexType==FLASH_FILE_TYPE) { - fileName = QFileDialog::getOpenFileName(this, tr("Open Firmware File"), g.flashDir(), FLASH_FILES_FILTER); - if(fileName.isEmpty()) - return; - checkFw(fileName); - } - else { - QString fileName = QFileDialog::getOpenFileName(this,tr("Choose Radio Backup file"), g.eepromDir(), tr(EXTERNAL_EEPROM_FILES_FILTER)); - if (checkeEprom(fileName)) { - if (burnraw==false) { - ui->BurnFlashButton->setEnabled(true); - ui->profile_label->show(); - ui->patchcalib_CB->show(); - ui->patchhw_CB->show(); - if (!IS_TARANIS(GetEepromInterface()->getBoard())) { - ui->EEpromCB->show(); - } - else { - ui->EEpromCB->setChecked(false); - } - } - else { - ui->BurnFlashButton->setEnabled(true); - ui->profile_label->hide(); - ui->patchcalib_CB->setChecked(false); - ui->patchhw_CB->setChecked(false); - ui->patchhw_CB->hide(); - ui->patchcalib_CB->hide(); - } - QTimer::singleShot(0, this, SLOT(shrink())); - } - } - updateUI(); -} - -void burnDialog::checkFw(QString fileName) -{ - if (fileName.isEmpty()) { - return; - } - - if (!IS_TARANIS(GetEepromInterface()->getBoard())) { - ui->EEbackupCB->show(); - } - else { - ui->EEbackupCB->setChecked(false); - *backup=false; - } - ui->FWFileName->setText(fileName); - FlashInterface flash(fileName); - if (flash.isValid()) { - ui->FramFWInfo->show(); - ui->DateField->setText(flash.getDate() + " " + flash.getTime()); - ui->versionField->setText(flash.getVersion()); - ui->ModField->setText(flash.getEEpromId()); - - ui->SplashFrame->hide(); - if (flash.hasSplash()) { - ui->SplashFrame->show(); - ui->imageLabel->setFixedSize(flash.getSplashWidth(), flash.getSplashHeight()); - } - } - else { - QMessageBox::warning(this, tr("Warning"), tr("%1 may not be a valid firmware file").arg(fileName)); - } - ui->BurnFlashButton->setEnabled(true); - QTimer::singleShot(0, this, SLOT(shrink())); - g.flashDir( QFileInfo(fileName).dir().absolutePath() ); -} - -bool burnDialog::checkeEprom(QString fileName) -{ - if (fileName.isEmpty()) { - return false; - } - QFile file(fileName); - if (!file.exists()) { - QMessageBox::critical(this, tr("Error"), tr("Unable to find file %1!").arg(fileName)); - return false; - } - burnraw=false; - int fileType = getFileType(fileName); -#if 0 - if (fileType==FILE_TYPE_XML) { - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file - QMessageBox::critical(this, tr("Error"),tr("Error opening file %1:\n%2.").arg(fileName).arg(file.errorString())); - return false; - } - QTextStream inputStream(&file); - XmlInterface(inputStream).load(radioData); - } - else -#endif - if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { //read HEX file - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file - QMessageBox::critical(this, tr("Error"),tr("Error opening file %1:\n%2.").arg(fileName).arg(file.errorString())); - return false; - } - QDomDocument doc(ER9X_EEPROM_FILE_TYPE); - bool xmlOK = doc.setContent(&file); - if(xmlOK) { - if (!LoadEepromXml(radioData, doc)){ - return false; - } - } - file.reset(); - - QTextStream inputStream(&file); - if (fileType==FILE_TYPE_EEPE) { // read EEPE file header - QString hline = inputStream.readLine(); - if (hline!=EEPE_EEPROM_FILE_HEADER) { - file.close(); - return false; - } - } - uint8_t eeprom[EESIZE_RLC_MAX]; - int eeprom_size = HexInterface(inputStream).load(eeprom, EESIZE_RLC_MAX); - if (!eeprom_size) { - int res = QMessageBox::question(this, "Companion",tr("Invalid binary Models and Settings File %1, Proceed anyway ?").arg(fileName),QMessageBox::Yes | QMessageBox::No); - if (res == QMessageBox::No) { - return false; - } - burnraw=true; - ui->FWFileName->setText(fileName); - return true; - } - file.close(); - if (!LoadEeprom(radioData, eeprom, eeprom_size)) { - int res = QMessageBox::question(this, "Companion",tr("Invalid binary Models and Settings File %1, Proceed anyway ?").arg(fileName),QMessageBox::Yes | QMessageBox::No); - if (res == QMessageBox::No) { - return false; - } - burnraw=true; - ui->FWFileName->setText(fileName); - return true; - } - } - else if (fileType==FILE_TYPE_BIN) { //read binary - int eeprom_size = file.size(); - if (!file.open(QFile::ReadOnly)) { //reading binary file - TODO HEX support - QMessageBox::critical(this, tr("Error"),tr("Error opening file %1:\n%2.").arg(fileName).arg(file.errorString())); - return false; - } - uint8_t *eeprom = (uint8_t *)malloc(eeprom_size); - memset(eeprom, 0, eeprom_size); - long result = file.read((char*)eeprom, eeprom_size); - file.close(); - if (result != eeprom_size) { - QMessageBox::critical(this, tr("Error"),tr("Error reading file %1:\n%2.").arg(fileName).arg(file.errorString())); - return false; - } - if (!LoadEeprom(radioData, eeprom, eeprom_size)) { - int res = QMessageBox::question(this, "Companion",tr("Invalid binary Models and Settings File %1, Proceed anyway ?").arg(fileName),QMessageBox::Yes | QMessageBox::No); - if (res == QMessageBox::No) { - return false; - } - burnraw=true; - } - } - ui->FWFileName->setText(fileName); - return true; -} - -void burnDialog::displaySplash() -{ - QImage image; - if (imageSource == FIRMWARE){ - FlashInterface flash(ui->FWFileName->text()); - image = flash.getSplash(); - } - else { - image.load(imageFile); - } - if (image.isNull()) { - return; - } - ui->imageLabel->setPixmap( makePixMap( image, g.profile[g.id()].fwType())); -} - -void burnDialog::updateUI() -{ - if (hexType==EEPROM_FILE_TYPE) - return; - - ui->useProfileImageCB->setChecked( imageSource == PROFILE ); - ui->useFwImageCB->setChecked( imageSource == FIRMWARE ); - ui->useLibraryImageCB->setChecked( imageSource == LIBRARY ); - ui->useAnotherImageCB->setChecked( imageSource == ANOTHER ); - - displaySplash(); -} - -void burnDialog::on_useFwImageCB_clicked() -{ - QString fileName = ui->FWFileName->text(); - FlashInterface flash(fileName); - if (!flash.isValid()) { - QMessageBox::critical(this, tr("Error"), tr( "The firmware file is not valid." )); - } - else { - if (!flash.hasSplash()) { - QMessageBox::critical(this, tr("Error"), tr( "There is no start screen image in the firmware file." )); - } - else{ - imageSource = FIRMWARE; - imageFile = fileName; - } - } - updateUI(); -} - -void burnDialog::on_useProfileImageCB_clicked() -{ - QString fileName = g.profile[g.id()].splashFile(); - if (!fileName.isEmpty()){ - QImage image(fileName); - if (image.isNull()) { - QMessageBox::critical(this, tr("Error"), tr("Profile image %1 is invalid.").arg(fileName)); - } - else { - imageSource = PROFILE; - imageFile = fileName; - } - } - updateUI(); -} - -void burnDialog::on_useAnotherImageCB_clicked() -{ - QString supportedImageFormats; - for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) { - supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; - } - QString fileName = QFileDialog::getOpenFileName(this, tr("Open image file to use as radio start screen"), g.imagesDir(), tr("Images (%1)").arg(supportedImageFormats)); - if (!fileName.isEmpty()){ - g.imagesDir( QFileInfo(fileName).dir().absolutePath() ); - QImage image(fileName); - if (image.isNull()) { - QMessageBox::critical(this, tr("Error"), tr("Image could not be loaded from %1").arg(fileName)); - } - else{ - imageSource = ANOTHER; - imageFile = fileName; - } - } - updateUI(); -} - -void burnDialog::on_useLibraryImageCB_clicked() -{ - QString fileName; - splashLibrary *ld = new splashLibrary(this,&fileName); - ld->exec(); - if (!fileName.isEmpty()) { - QImage image(fileName); - if (image.isNull()) { - QMessageBox::critical(this, tr("Error"), tr("The library image could not be loaded")); - } - else{ - imageSource = LIBRARY; - imageFile = fileName; - } - } - updateUI(); -} - -void burnDialog::on_BurnFlashButton_clicked() -{ - if (hexType==FLASH_FILE_TYPE) { - QString fileName=ui->FWFileName->text(); - if (!fileName.isEmpty()) { - g.flashDir( QFileInfo(fileName).dir().absolutePath() ); - if (!ui->useFwImageCB->isChecked()) { - const QPixmap * pixmap = ui->imageLabel->pixmap(); - QImage image; - if (pixmap) { - image = pixmap->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height()); - } - if (!image.isNull()) { - QString tempFile; - if (getFileType(fileName) == FILE_TYPE_HEX) - tempFile = generateProcessUniqueTempFileName("flash.hex"); - else - tempFile = generateProcessUniqueTempFileName("flash.bin"); - FlashInterface flash(fileName); - flash.setSplash(image); - if (flash.saveFlash(tempFile) > 0) { - hexfileName->clear(); - hexfileName->append(tempFile); - } - else { - hexfileName->clear(); - QMessageBox::critical(this, tr("Warning"), tr("Cannot save customized firmware")); - } - } - else { - hexfileName->clear(); - QMessageBox::critical(this, tr("Warning"), tr("Custom image not found")); - } - } - else { - hexfileName->clear(); - hexfileName->append(fileName); - } - } - else { - QMessageBox::critical(this, tr("Warning"), tr("No firmware selected")); - hexfileName->clear(); - } - } - - if (hexType==EEPROM_FILE_TYPE) { - QString calib = g.profile[g.id()].stickPotCalib(); - QString trainercalib = g.profile[g.id()].trainerCalib(); - int potsnum=GetCurrentFirmware()->getCapability(Pots); - int8_t vBatCalib=(int8_t) g.profile[g.id()].vBatCalib(); - int8_t currentCalib=(int8_t) g.profile[g.id()].currentCalib(); - int8_t PPM_Multiplier=(int8_t) g.profile[g.id()].ppmMultiplier(); - uint8_t GSStickMode=(uint8_t) g.profile[g.id()].gsStickMode(); - uint8_t vBatWarn=(uint8_t) g.profile[g.id()].vBatWarn(); - - QString DisplaySet= g.profile[g.id()].display(); - QString BeeperSet= g.profile[g.id()].beeper(); - QString HapticSet= g.profile[g.id()].haptic(); - QString SpeakerSet= g.profile[g.id()].speaker(); - bool patch=false; - if (ui->patchcalib_CB->isChecked()) { - if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) { - QString Byte; - int16_t byte16; - bool ok; - for (int i=0; i<(NUM_STICKS+potsnum); i++) { - Byte=calib.mid(i*12,4); - byte16=(int16_t)Byte.toInt(&ok,16); - if (ok) - radioData.generalSettings.calibMid[i]=byte16; - Byte=calib.mid(4+i*12,4); - byte16=(int16_t)Byte.toInt(&ok,16); - if (ok) - radioData.generalSettings.calibSpanNeg[i]=byte16; - Byte=calib.mid(8+i*12,4); - byte16=(int16_t)Byte.toInt(&ok,16); - if (ok) - radioData.generalSettings.calibSpanPos[i]=byte16; - } - for (int i=0; i<4; i++) { - Byte=trainercalib.mid(i*4,4); - byte16=(int16_t)Byte.toInt(&ok,16); - if (ok) - radioData.generalSettings.trainer.calib[i]=byte16; - } - radioData.generalSettings.currentCalib=currentCalib; - radioData.generalSettings.vBatCalib=vBatCalib; - radioData.generalSettings.PPM_Multiplier=PPM_Multiplier; - patch=true; - } - else { - QMessageBox::critical(this, tr("Warning"), tr("Wrong radio calibration data in profile, Settings not patched")); - } - } - if (ui->patchhw_CB->isChecked()) { - if ((DisplaySet.length()==6) && (BeeperSet.length()==4) && (HapticSet.length()==6) && (SpeakerSet.length()==6)) { - radioData.generalSettings.vBatWarn=vBatWarn; - radioData.generalSettings.stickMode=GSStickMode; - uint8_t byte8u; - int8_t byte8; - bool ok; - byte8=(int8_t)DisplaySet.mid(0,2).toInt(&ok,16); - if (ok) - radioData.generalSettings.optrexDisplay=(byte8==1 ? true : false); - byte8u=(uint8_t)DisplaySet.mid(2,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.contrast=byte8u; - - byte8u=(uint8_t)DisplaySet.mid(4,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.backlightBright=byte8u; - - byte8u=(uint8_t)BeeperSet.mid(0,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.beeperMode=(GeneralSettings::BeeperMode)byte8u; - - byte8=(int8_t)BeeperSet.mid(2,2).toInt(&ok,16); - if (ok) - radioData.generalSettings.beeperLength=byte8; - - byte8u=(uint8_t)HapticSet.mid(0,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.hapticMode=(GeneralSettings::BeeperMode)byte8u; - - byte8u=(uint8_t)HapticSet.mid(2,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.hapticStrength=byte8u; - - byte8=(int8_t)HapticSet.mid(4,2).toInt(&ok,16); - if (ok) - radioData.generalSettings.hapticLength=byte8; - - byte8u=(uint8_t)SpeakerSet.mid(0,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.speakerMode=byte8u; - - byte8u=(uint8_t)SpeakerSet.mid(2,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.speakerPitch=byte8u; - - byte8u=(uint8_t)SpeakerSet.mid(4,2).toUInt(&ok,16); - if (ok) - radioData.generalSettings.speakerVolume=byte8u; - patch=true; - } - else { - QMessageBox::critical(this, tr("Warning"), tr("Wrong radio setting data in profile, Settings not patched")); - } - - if (patch) { - QString fileName = generateProcessUniqueTempFileName("temp.bin"); - QFile file(fileName); - - uint8_t *eeprom = (uint8_t*)malloc(GetEepromInterface()->getEEpromSize()); - int eeprom_size = GetEepromInterface()->save(eeprom, radioData, GetCurrentFirmware()->getVariantNumber()); - if (!eeprom_size) { - QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(fileName).arg(file.errorString())); - hexfileName->clear(); - } - - if (!file.open(QIODevice::WriteOnly)) { - QMessageBox::warning(this, tr("Error"),tr("Cannot write file %1:\n%2.").arg(fileName).arg(file.errorString())); - hexfileName->clear(); - } - - QTextStream outputStream(&file); - - long result = file.write((char*)eeprom, eeprom_size); - if (result != eeprom_size) { - QMessageBox::warning(this, tr("Error"),tr("Error writing file %1:\n%2.").arg(fileName).arg(file.errorString())); - } - - hexfileName->clear(); - hexfileName->append(fileName); - } - else { - hexfileName->clear(); - hexfileName->append(ui->FWFileName->text()); - } - } - else { - hexfileName->clear(); - hexfileName->append(ui->FWFileName->text()); - } - } - this->close(); -} - -void burnDialog::on_cancelButton_clicked() -{ - hexfileName->clear(); - this->close(); -} - -void burnDialog::on_EEpromCB_toggled(bool checked) -{ - *backup = ui->EEpromCB->isChecked(); -} - -void burnDialog::shrink() -{ - resize(0,0); -} - -void burnDialog::on_EEbackupCB_clicked() -{ - *backup = ui->EEbackupCB->isChecked(); -} diff --git a/companion/src/burndialog.h b/companion/src/burndialog.h deleted file mode 100644 index 28e568d3b..000000000 --- a/companion/src/burndialog.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef BURNDIALOG_H -#define BURNDIALOG_H - -#include -#include -#include "eeprominterface.h" -#include "flashinterface.h" -#include "xmlinterface.h" - -#define HEX_FILES_FILTER "HEX files (*.hex);;" -#define BIN_FILES_FILTER "BIN files (*.bin);;" -#define EEPE_FILES_FILTER "EEPE EEPROM files (*.eepe);;" -#define EEPROM_FILES_FILTER "EEPE files (*.eepe *.bin *.hex);;" EEPE_FILES_FILTER BIN_FILES_FILTER HEX_FILES_FILTER -#define FLASH_FILES_FILTER "FLASH files (*.bin *.hex);;" BIN_FILES_FILTER HEX_FILES_FILTER -#define EXTERNAL_EEPROM_FILES_FILTER "EEPROM files (*.bin *.hex);;" BIN_FILES_FILTER HEX_FILES_FILTER -#define ER9X_EEPROM_FILE_TYPE "ER9X_EEPROM_FILE" -#define EEPE_EEPROM_FILE_HEADER "EEPE EEPROM FILE" -#define EEPE_MODEL_FILE_HEADER "EEPE MODEL FILE" -#define EEPROM_FILE_TYPE 1 -#define FLASH_FILE_TYPE 2 - - -namespace Ui -{ - class burnDialog; -} - -class burnDialog : public QDialog -{ - Q_OBJECT - -public: - explicit burnDialog(QWidget *parent = 0, int Type = 2, QString * fileName = NULL, bool * backupEE=NULL, QString docname=""); - ~burnDialog(); - -private slots: - void on_FlashLoadButton_clicked(); - void on_BurnFlashButton_clicked(); - void on_cancelButton_clicked(); - void on_EEbackupCB_clicked(); - void on_EEpromCB_toggled(bool checked); - bool checkeEprom(QString fileName); - void on_useProfileImageCB_clicked(); - void on_useFwImageCB_clicked(); - void on_useLibraryImageCB_clicked(); - void on_useAnotherImageCB_clicked(); - - void checkFw(QString fileName); - void displaySplash(); - void updateUI(); - void shrink(); - - -private: - Ui::burnDialog *ui; - QString * hexfileName; - bool * backup; - int hexType; - RadioData radioData; - bool burnraw; - enum ImageSource {FIRMWARE, PROFILE, LIBRARY, ANOTHER}; - ImageSource imageSource; - QString imageFile; -}; - -#endif // BURNDIALOG_H diff --git a/companion/src/burndialog.ui b/companion/src/burndialog.ui deleted file mode 100644 index 208bc4527..000000000 --- a/companion/src/burndialog.ui +++ /dev/null @@ -1,379 +0,0 @@ - - - burnDialog - - - - 0 - 0 - 399 - 564 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Customize Splash - - - - :/icon.png:/icon.png - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 90 - 0 - - - - Cancel - - - - - - - false - - - - 90 - 0 - - - - Write to TX - - - - - - - - - - - <html><head/><body><p>Modify calibration parameters using settings from current profile</p></body></html> - - - Patch calibration setting from profile - - - - - - - <html><head/><body><p>Modify HW parameters using settings from current profile</p></body></html> - - - Patch HW setting from profile - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Date & Time - - - - - - - true - - - - - - - Variant - - - - - - - true - - - - - - - Version - - - - - - - true - - - - - - - - - - - - true - - - - 0 - 0 - - - - - 250 - 0 - - - - true - - - - - - - - 0 - 0 - - - - Browse for file - - - - - - - - - - 0 - 0 - - - - Allows Companion to write to older version of the firmware - - - Check Firmware compatibility - - - - - - - true - - - Backup and restore Models and Settings - - - false - - - - - - - - 75 - true - - - - Current Profile - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - - - 0 - 0 - - - - - 128 - 64 - - - - - 214 - 66 - - - - QFrame::Panel - - - QFrame::Plain - - - 0 - - - - - - true - - - - - - - - - Use firmware start screen - - - - - - - Use another start screen - - - - - - - - 0 - 0 - - - - Use profile start screen - - - - - - - Use library start screen - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - BurnFlashButton - FWFileName - FlashLoadButton - versionField - ModField - useProfileImageCB - useFwImageCB - useLibraryImageCB - useAnotherImageCB - EEbackupCB - patchcalib_CB - patchhw_CB - EEpromCB - cancelButton - - - - - - diff --git a/companion/src/companion.cpp b/companion/src/companion.cpp index 50c5c311e..0a9d9ec63 100644 --- a/companion/src/companion.cpp +++ b/companion/src/companion.cpp @@ -96,8 +96,8 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - RegisterEepromInterfaces(); - registerOpenTxFirmwares(); + registerEEpromInterfaces(); + registerOpenTxFirmwares(); if (g.profile[g.id()].fwType().isEmpty()){ g.profile[g.id()].fwType(default_firmware_variant->getId()); @@ -130,8 +130,8 @@ int main(int argc, char *argv[]) delete splash; delete mainWin; - UnregisterFirmwares(); - UnregisterEepromInterfaces(); + unregisterFirmwares(); + unregisterEEpromInterfaces(); return result; } diff --git a/companion/src/comparedialog.cpp b/companion/src/comparedialog.cpp index 720e3598b..f02168b5c 100644 --- a/companion/src/comparedialog.cpp +++ b/companion/src/comparedialog.cpp @@ -1,6 +1,7 @@ #include "comparedialog.h" #include "ui_comparedialog.h" #include "helpers.h" +#include "helpers_html.h" #include "eeprominterface.h" #include #include @@ -165,37 +166,6 @@ CompareDialog::~CompareDialog() delete ui; } -QString CompareDialog::doTC(const QString s, const QString color="", bool bold=false) -{ - QString str = s; - if(bold) str = "" + str + ""; - if(!color.isEmpty()) str = "" + str + ""; - return "" + str + ""; -} - -QString CompareDialog::doTR(const QString s, const QString color="", bool bold=false) -{ - QString str = s; - if(bold) str = "" + str + ""; - if(!color.isEmpty()) str = "" + str + ""; - return "" + str + ""; -} - -QString CompareDialog::doTL(const QString s, const QString color="", bool bold=false) -{ - QString str = s; - if(bold) str = "" + str + ""; - if(!color.isEmpty()) str = "" + str + ""; - return "" + str + ""; -} - -QString CompareDialog::fv(const QString name, const QString value, const QString color="green") -{ - return "" + name + ": " + value + "
"; -} - - - int CompareDialog::ModelHasExpo(ExpoData * ExpoArray, ExpoData expo, bool * expoused) { for (int i=0; i< C9X_MAX_EXPOS; i++) { diff --git a/companion/src/comparedialog.h b/companion/src/comparedialog.h index ef6a5aec1..e0d45d898 100644 --- a/companion/src/comparedialog.h +++ b/companion/src/comparedialog.h @@ -29,10 +29,6 @@ class CompareDialog : public QDialog private: void closeEvent(QCloseEvent *event); Ui::CompareDialog *ui; - QString doTC(const QString s, const QString color, bool bold); - QString doTR(const QString s, const QString color, bool bold); - QString doTL(const QString s, const QString color, bool bold); - QString fv(const QString name, const QString value,const QString color); template QString getColor1(T val1, T val2) { if (val1!=val2) return "green"; diff --git a/companion/src/converteeprom.cpp b/companion/src/converteeprom.cpp new file mode 100755 index 000000000..8c75be049 --- /dev/null +++ b/companion/src/converteeprom.cpp @@ -0,0 +1,42 @@ +#include "converteeprom.h" +#include "eeprominterface.h" +#include "firmwareinterface.h" +#include + +bool convertEEprom(const QString &sourceEEprom, const QString &destinationEEprom, const QString &firmwareFilename) +{ + Firmware *currentFirmware = GetCurrentFirmware(); + FirmwareInterface firmware(firmwareFilename); + if (!firmware.isValid()) + return false; + + unsigned int version = firmware.getEEpromVersion(); + unsigned int variant = firmware.getEEpromVariant(); + + QFile sourceFile(sourceEEprom); + int eeprom_size = sourceFile.size(); + if (!eeprom_size) + return false; + + if (!sourceFile.open(QIODevice::ReadOnly)) + return false; + + QByteArray eeprom(eeprom_size, 0); + long result = sourceFile.read(eeprom.data(), eeprom_size); + sourceFile.close(); + + QSharedPointer radioData = QSharedPointer(new RadioData()); + if (!loadEEprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size) || !currentFirmware->saveEEPROM((uint8_t *)eeprom.data(), *radioData, variant, version)) + return false; + + QFile destinationFile(destinationEEprom); + if (!destinationFile.open(QIODevice::WriteOnly)) + return false; + + result = destinationFile.write(eeprom.constData(), eeprom_size); + destinationFile.close(); + if (result != eeprom_size) + return false; + + return true; +} diff --git a/companion/src/converteeprom.h b/companion/src/converteeprom.h new file mode 100755 index 000000000..3f420e692 --- /dev/null +++ b/companion/src/converteeprom.h @@ -0,0 +1,8 @@ +#ifndef CONVERTHEADER_H_ +#define CONVERTHEADER_H_ + +#include + +bool convertEEprom(const QString &sourceEEprom, const QString &destinationEEprom, const QString &firmware); + +#endif /* CONVERTHEADER_H_ */ diff --git a/companion/src/customizesplashdialog.cpp b/companion/src/customizesplashdialog.cpp index cf125d35c..f1208227e 100644 --- a/companion/src/customizesplashdialog.cpp +++ b/companion/src/customizesplashdialog.cpp @@ -1,12 +1,10 @@ #include "customizesplashdialog.h" #include "ui_customizesplashdialog.h" - -#include +#include "flashfirmwaredialog.h" #include "appdata.h" #include "helpers.h" -#include "burndialog.h" #include "splashlibrary.h" -#include "flashinterface.h" +#include "firmwareinterface.h" //*** Side Class *** @@ -44,12 +42,12 @@ bool Side::displayImage( QString fileName, Source pictSource ) // Determine which picture format to use if (pictSource == FW ){ - FlashInterface flash(fileName); - if (!flash.hasSplash()) + FirmwareInterface firmware(fileName); + if (!firmware.hasSplash()) return false; else - image = flash.getSplash(); - *format = (flash.getSplashWidth()==WIDTH_TARANIS ? LCDTARANIS : LCD9X); + image = firmware.getSplash(); + *format = (firmware.getSplashWidth()==WIDTH_TARANIS ? LCDTARANIS : LCD9X); } else { image.load(fileName); @@ -105,12 +103,12 @@ bool Side::saveImage() { if (*source == FW ) { - FlashInterface flash(*saveToFileName); - if (!flash.hasSplash()) { + FirmwareInterface firmware(*saveToFileName); + if (!firmware.hasSplash()) { return false; } - QImage image = imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight()); - if (flash.setSplash(image) && (flash.saveFlash(*saveToFileName) > 0)) { + QImage image = imageLabel->pixmap()->toImage().scaled(firmware.getSplashWidth(), firmware.getSplashHeight()); + if (firmware.setSplash(image) && (firmware.save(*saveToFileName) > 0)) { g.flashDir( QFileInfo(*saveToFileName).dir().absolutePath() ); } else { diff --git a/companion/src/customizesplashdialog.h b/companion/src/customizesplashdialog.h index c931005b2..e15ded419 100644 --- a/companion/src/customizesplashdialog.h +++ b/companion/src/customizesplashdialog.h @@ -3,7 +3,7 @@ #include #include -#include "flashinterface.h" +#include "firmwareinterface.h" namespace Ui { diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 8cad62ec1..287e5df6f 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -11,6 +11,7 @@ #include "appdata.h" #include "helpers.h" #include "wizarddata.h" +#include "firmwareinterface.h" std::list EEPROMWarnings; @@ -164,7 +165,7 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting { RawSourceRange result; - FirmwareInterface * firmware = GetCurrentFirmware(); + Firmware * firmware = GetCurrentFirmware(); int board = firmware->getBoard(); bool singleprec = (flags & RANGE_SINGLE_PRECISION); @@ -863,7 +864,7 @@ QString CustomFunctionData::funcToString() else if (func == FuncPlayScript) return QObject::tr("Play Script"); else if (func == FuncLogs) - return QObject::tr("SD Logs"); + return QObject::tr("Start Logs"); else if (func == FuncVolume) return QObject::tr("Volume"); else if (func == FuncBacklight) @@ -1456,7 +1457,7 @@ int ModelData::getChannelsMax(bool forceExtendedLimits) const } QList eepromInterfaces; -void RegisterEepromInterfaces() +void registerEEpromInterfaces() { eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_STOCK)); eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_M128)); @@ -1472,7 +1473,7 @@ void RegisterEepromInterfaces() eepromInterfaces.push_back(new Er9xInterface()); } -void UnregisterEepromInterfaces() +void unregisterEEpromInterfaces() { foreach(EEPROMInterface * intf, eepromInterfaces) { // qDebug() << "UnregisterEepromInterfaces(): deleting " << QString::number( reinterpret_cast(intf), 16 ); @@ -1481,18 +1482,18 @@ void UnregisterEepromInterfaces() OpenTxEepromCleanup(); } -QList firmwares; -FirmwareInterface * default_firmware_variant; -FirmwareInterface * current_firmware_variant; +QList firmwares; +Firmware * default_firmware_variant; +Firmware * current_firmware_variant; -void UnregisterFirmwares() +void unregisterFirmwares() { - foreach (FirmwareInterface * f, firmwares) { + foreach (Firmware * f, firmwares) { delete f; } } -bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size) +bool loadEEprom(RadioData &radioData, const uint8_t *eeprom, const int size) { foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { if (eepromInterface->load(radioData, eeprom, size)) @@ -1502,7 +1503,7 @@ bool LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size) return false; } -bool LoadBackup(RadioData &radioData, uint8_t *eeprom, int size, int index) +bool loadBackup(RadioData &radioData, uint8_t *eeprom, int size, int index) { foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { if (eepromInterface->loadBackup(radioData, eeprom, size, index)) @@ -1513,7 +1514,7 @@ bool LoadBackup(RadioData &radioData, uint8_t *eeprom, int size, int index) } -bool LoadEepromXml(RadioData &radioData, QDomDocument &doc) +bool loadEEpromXml(RadioData &radioData, QDomDocument &doc) { foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { if (eepromInterface->loadxml(radioData, doc)) @@ -1547,10 +1548,10 @@ QString getBoardName(BoardEnum board) } } -FirmwareInterface * GetFirmware(QString id) +Firmware * GetFirmware(QString id) { - foreach(FirmwareInterface * firmware, firmwares) { - FirmwareInterface * result = firmware->getFirmwareVariant(id); + foreach(Firmware * firmware, firmwares) { + Firmware * result = firmware->getFirmwareVariant(id); if (result) { return result; } @@ -1559,16 +1560,16 @@ FirmwareInterface * GetFirmware(QString id) return default_firmware_variant; } -void FirmwareInterface::addOption(const char *option, QString tooltip, uint32_t variant) +void Firmware::addOption(const char *option, QString tooltip, uint32_t variant) { Option options[] = { { option, tooltip, variant }, { NULL } }; addOptions(options); } -unsigned int FirmwareInterface::getVariantNumber() +unsigned int Firmware::getVariantNumber() { unsigned int result = 0; - const FirmwareInterface * base = getFirmwareBase(); + const Firmware * base = getFirmwareBase(); QStringList options = id.mid(base->getId().length()+1).split("-", QString::SkipEmptyParts); foreach(QString option, options) { foreach(QList