commit 86570aa76824bf9b78c5d4cc11aebe27df2bf0fa Author: Rodrigo Mendez Date: Tue Jun 28 00:26:27 2016 -0500 Initial commit diff --git a/esptool-gui.pro b/esptool-gui.pro new file mode 100644 index 0000000..82b4321 --- /dev/null +++ b/esptool-gui.pro @@ -0,0 +1,20 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-05-27T10:58:03 +# +#------------------------------------------------- + +QT += core gui serialport + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = esptool-gui +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp + +HEADERS += mainwindow.h + +FORMS += mainwindow.ui diff --git a/esptool-gui.pro.user b/esptool-gui.pro.user new file mode 100644 index 0000000..b309062 --- /dev/null +++ b/esptool-gui.pro.user @@ -0,0 +1,347 @@ + + + + + + EnvironmentId + {d21aff1d-6fb6-4e42-a32d-f7d1ac8054b9} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.6.0 clang 64bit + Desktop Qt 5.6.0 clang 64bit + qt.56.clang_64_kit + 1 + 0 + 0 + + /Users/rod/sandbox/build-esptool-gui-Desktop_Qt_5_6_0_clang_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /Users/rod/sandbox/build-esptool-gui-Desktop_Qt_5_6_0_clang_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + + true + -r %{sourceDir}/tool-esptool %{buildDir}/esptool-gui.app/Contents/MacOS/ + cp + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 3 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /Users/rod/sandbox/build-esptool-gui-Desktop_Qt_5_6_0_clang_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + esptool-gui + esptool-gui2 + Qt4ProjectManager.Qt4RunConfiguration:/Users/rod/sandbox/esptool-gui-public/esptool-gui.pro + true + + esptool-gui.pro + false + + /Users/rod/sandbox/build-esptool-gui-Desktop_Qt_5_6_0_clang_64bit-Release/esptool-gui.app/Contents/MacOS + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..a391f4f --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,275 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + serial = new QSerialPort(this); + + // Fill baud box + ui->baudBox->clear(); + ui->baudBox->addItem(QStringLiteral("1200"), QSerialPort::Baud1200); + ui->baudBox->addItem(QStringLiteral("2400"), QSerialPort::Baud2400); + ui->baudBox->addItem(QStringLiteral("4800"), QSerialPort::Baud4800); + ui->baudBox->addItem(QStringLiteral("9600"), QSerialPort::Baud9600); + ui->baudBox->addItem(QStringLiteral("19200"), QSerialPort::Baud19200); + ui->baudBox->addItem(QStringLiteral("38400"), QSerialPort::Baud38400); + ui->baudBox->addItem(QStringLiteral("57600"), QSerialPort::Baud57600); + ui->baudBox->addItem(QStringLiteral("115200"), QSerialPort::Baud115200); + ui->baudBox->setCurrentIndex(7); // Default 115200 + + ui->filePathText->setDisabled(true); + ui->testPathText->setDisabled(true); + ui->closeSerialBtn->setDisabled(true); + ui->outputText->setReadOnly(true); + + loadPorts(); + + filePath = ""; + testFilePath = ""; + + connect(ui->reloadBtn, &QPushButton::clicked, + this, &MainWindow::loadPorts); + connect(ui->browseBtn, &QPushButton::clicked, + this, &MainWindow::browseFile); + connect(ui->browseTestBtn, &QPushButton::clicked, + this, &MainWindow::browseTestFile); + connect(ui->uploadBtn, &QPushButton::clicked, + this, &MainWindow::doUpload); + connect(ui->testBtn, &QPushButton::clicked, + this, &MainWindow::doTest); + + // Serial port setup + connect(serial, static_cast(&QSerialPort::error), + this, &MainWindow::handleSerialError); + connect(serial, &QSerialPort::readyRead, this, &MainWindow::readData); + + connect(ui->openSerialBtn, &QPushButton::clicked, + this, &MainWindow::openSerialPort); + connect(ui->closeSerialBtn, &QPushButton::clicked, + this, &MainWindow::closeSerialPort); + + // Fetch previous settings + QCoreApplication::setOrganizationName("makerlab.mx"); + QCoreApplication::setOrganizationDomain("makerlab.mx"); + QCoreApplication::setApplicationName("esptool-gui"); + QSettings settings; + + if(settings.contains("settings/port")) + { + int portIndex = settings.value("settings/port").toInt(); + ui->portBox->setCurrentIndex(portIndex); + } + + if(settings.contains("settings/baud")) + { + int baudIndex = settings.value("settings/baud").toInt(); + ui->baudBox->setCurrentIndex(baudIndex); + } + + if(settings.contains("settings/file")) + { + filePath = settings.value("settings/file").toString(); + ui->filePathText->setText(filePath); + } + + if(settings.contains("settings/testFile")) + { + testFilePath = settings.value("settings/testFile").toString(); + ui->testPathText->setText(testFilePath); + } + + connect(ui->portBox, static_cast(&QComboBox::currentIndexChanged), + [=](int index) + { + QSettings settings; + settings.setValue("settings/port", index); + }); + + connect(ui->baudBox, static_cast(&QComboBox::currentIndexChanged), + [=](int index) + { + QSettings settings; + settings.setValue("settings/baud", index); + }); + +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::loadPorts() +{ + ui->portBox->clear(); + + foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) + { + ui->portBox->addItem(info.portName(), info.systemLocation()); + } +} + +void MainWindow::browseFile() +{ + QSettings settings; + const QString fileName = QFileDialog::getOpenFileName(this); + if (!fileName.isEmpty()) + { + filePath = fileName; + ui->filePathText->setText(filePath); + settings.setValue("settings/file", filePath); + } +} + +void MainWindow::browseTestFile() +{ + QSettings settings; + const QString fileName = QFileDialog::getOpenFileName(this); + if (!fileName.isEmpty()) + { + testFilePath = fileName; + ui->testPathText->setText(testFilePath); + settings.setValue("settings/testFile", testFilePath); + } +} + +void MainWindow::doUpload() +{ + closeSerialPort(); + ui->outputText->clear(); + ui->outputText->appendPlainText("Uploading...\n"); + QString appPath = QCoreApplication::applicationDirPath(); + QString program = appPath + "/tool-esptool/esptool"; + QStringList arguments; + arguments << "-vv" << "-cd" << "ck" << "-cb" << ui->baudBox->currentText() << "-cp" << ui->portBox->currentData().toString() << "-cf" << filePath; + + startProcess(program, arguments); +} + +// Get ESP8266 MAC only works with esptool.py, not esptool-ck +void MainWindow::doGetMac() +{ + closeSerialPort(); + ui->outputText->clear(); + ui->outputText->appendPlainText("Getting MAC...\n"); + QString program = "/usr/local/bin/esptool.py"; + QStringList arguments; + arguments << "-b" << ui->baudBox->currentText() << "-p" << ui->portBox->currentData().toString() << "read_mac"; + + startProcess(program, arguments); +} + +void MainWindow::doTest() +{ + closeSerialPort(); + ui->outputText->clear(); + ui->outputText->appendPlainText("Uploading Test Firmware...\n"); + QString appPath = QCoreApplication::applicationDirPath(); + QString program = appPath + "/tool-esptool/esptool"; + QStringList arguments; + arguments << "-vv" << "-cd" << "ck" << "-cb" << ui->baudBox->currentText() << "-cp" << ui->portBox->currentData().toString() << "-cf" << testFilePath; + + startProcess(program, arguments, true); +} + +void MainWindow::setInputsDisabled(bool disabled) +{ + ui->baudBox->setDisabled(disabled); + ui->portBox->setDisabled(disabled); + ui->reloadBtn->setDisabled(disabled); + ui->uploadBtn->setDisabled(disabled); + ui->browseBtn->setDisabled(disabled); + ui->browseTestBtn->setDisabled(disabled); + ui->testBtn->setDisabled(disabled); +} + +void MainWindow::startProcess(QString program, QStringList arguments, bool isTest) +{ + process = new QProcess(this); + + connect(process, &QProcess::started, this, [=]() + { + setInputsDisabled(true); + }); + + connect(process, &QProcess::readyReadStandardError, this, [=]() + { + ui->outputText->insertPlainText(process->readAllStandardError()); + ui->outputText->verticalScrollBar()->setValue(ui->outputText->verticalScrollBar()->maximum()); + }); + + connect(process, &QProcess::readyReadStandardOutput, this, [=]() + { + ui->outputText->insertPlainText(process->readAllStandardOutput()); + ui->outputText->verticalScrollBar()->setValue(ui->outputText->verticalScrollBar()->maximum()); + }); + + connect(process, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) + { + ui->outputText->appendPlainText(QString("Finished with exit code ") + QString::number(exitCode)); + setInputsDisabled(false); + if(isTest) + { + ui->outputText->appendPlainText("\nTest Firmware upload finished. Press 'Open Serial' and press the config button on the Device (if any) to start testing."); + } + }); + + connect(process, static_cast(&QProcess::errorOccurred), this, [=](QProcess::ProcessError error) + { + ui->outputText->appendPlainText( QString("An error occurred: ") + error ); + setInputsDisabled(false); + }); + + process->start(program, arguments); +} + +void MainWindow::handleSerialError(QSerialPort::SerialPortError error) +{ + if (error == QSerialPort::ResourceError) { + QMessageBox::critical(this, tr("Critical Error"), serial->errorString()); + closeSerialPort(); + } +} + +void MainWindow::closeSerialPort() +{ + if (serial->isOpen()) + { + serial->close(); + ui->openSerialBtn->setDisabled(false); + ui->closeSerialBtn->setDisabled(true); + ui->outputText->appendPlainText("__________________________________________________________\nSerial port closed."); + } +} + +void MainWindow::openSerialPort() +{ + serial->setPortName(ui->portBox->currentText()); + serial->setBaudRate(ui->baudBox->currentData().toInt()); + //serial->setDataBits(p.dataBits); + //serial->setParity(p.parity); + //serial->setStopBits(p.stopBits); + //serial->setFlowControl(p.flowControl); + if (serial->open(QIODevice::ReadWrite)) { + ui->openSerialBtn->setDisabled(true); + ui->closeSerialBtn->setDisabled(false); + ui->outputText->appendPlainText("\nSerial port open:\n__________________________________________________________\n"); + } else { + QMessageBox::critical(this, tr("Error"), serial->errorString()); + ui->outputText->appendPlainText( tr("Open error")); + } +} + +void MainWindow::readData() +{ + QByteArray data = serial->readAll(); + ui->outputText->insertPlainText(data); + ui->outputText->verticalScrollBar()->setValue(ui->outputText->verticalScrollBar()->maximum()); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..61e6766 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,46 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void loadPorts(); + void browseFile(); + void browseTestFile(); + void doUpload(); + void doGetMac(); + void doTest(); + void closeSerialPort(); + void openSerialPort(); + void readData(); + +private: + Ui::MainWindow *ui; + + void setInputsDisabled(bool disabled); + void startProcess(QString program, QStringList arguments, bool isTest = false); + + void handleSerialError(QSerialPort::SerialPortError error); + + QSerialPort *serial; + QProcess *process; + QString filePath; + QString testFilePath; +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..e3cebd5 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,283 @@ + + + MainWindow + + + + 0 + 0 + 403 + 435 + + + + esptool-gui + + + + Qt::LeftToRight + + + + + + Settings + + + false + + + false + + + + + + + 300 + + + + + 1200 + + + + + 2400 + + + + + 4800 + + + + + 9600 + + + + + 19200 + + + + + 38400 + + + + + 57600 + + + + + 74880 + + + + + 115200 + + + + + 230400 + + + + + 250000 + + + + + + + + + + + Firmware: + + + + + + + Browse + + + + + + + Reload + + + + + + + Port: + + + + + + + Baudrate: + + + + + + + + + + Test Firmware: + + + + + + + + + + Browse + + + + + portLabel + portBox + reloadBtn + baudrateLabel + baudBox + fileLabel + browseBtn + filePathText + testFileLabel + testPathText + browseTestBtn + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Test + + + + + + + Upload + + + + + + + + + Output + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Open Serial + + + + + + + Close Serial + + + + + + + Clear + + + + + + + + + + + + + + 0 + 0 + 403 + 22 + + + + + + + + + clearTextBtn + clicked() + outputText + clear() + + + 182 + 377 + + + 182 + 295 + + + + + diff --git a/tool-esptool/esptool b/tool-esptool/esptool new file mode 100755 index 0000000..2d1917a Binary files /dev/null and b/tool-esptool/esptool differ diff --git a/tool-esptool/package.json b/tool-esptool/package.json new file mode 100755 index 0000000..64e2223 --- /dev/null +++ b/tool-esptool/package.json @@ -0,0 +1,10 @@ +{ + "description": "esptool-ck", + "name": "tool-esptool", + "system": [ + "darwin_x86_64", + "darwin_i386" + ], + "url": "https://github.com/igrr/esptool-ck", + "version": "1.408.0" +} \ No newline at end of file