From 4d625a0494f46dc28ea13c212b477c01d0081403 Mon Sep 17 00:00:00 2001 From: cidadao Date: Wed, 9 Nov 2016 00:54:16 +0000 Subject: [PATCH] Bootloader detection bug fixed. Initial update-over-BLE support added. --- gecko_loader.pro | 8 ++++---- geckoloader.cpp | 4 ++-- mainwindow.cpp | 34 +++++++++++++++++++++++++++++----- mainwindow.h | 7 +++++++ mainwindow.ui | 48 ++++++++++++++++++++++++++++++++---------------- 5 files changed, 74 insertions(+), 27 deletions(-) diff --git a/gecko_loader.pro b/gecko_loader.pro index 126eb48..d958e2e 100644 --- a/gecko_loader.pro +++ b/gecko_loader.pro @@ -7,15 +7,15 @@ QT += core QT += gui -CONFIG += console +#CONFIG += console -greaterThan(QT_MAJOR_VERSION, 4): QT += serialport widgets bluetooth +greaterThan(QT_MAJOR_VERSION, 4): QT += serialport widgets TARGET = gecko_loader TEMPLATE = app -#DEFINES += QT_NO_DEBUG_OUTPUT -DEFINES += EFM32_LOADER_GUI EFM32LOADER_SERIAL=1 EFM32LOADER_BLE=1 +DEFINES += QT_NO_DEBUG_OUTPUT +DEFINES += EFM32_LOADER_GUI EFM32LOADER_SERIAL=1 EFM32LOADER_BLE=0 SOURCES += main.cpp\ mainwindow.cpp \ diff --git a/geckoloader.cpp b/geckoloader.cpp index 3883440..78192d8 100644 --- a/geckoloader.cpp +++ b/geckoloader.cpp @@ -231,8 +231,8 @@ bool GeckoLoader::waitForChipID() } else { - QString line = QString(_serialPort->readLine()); - if(line.contains("ChipID")) + QString line = QString(_serialPort->readLine()).toLower(); + if(line.contains("chip")) { emit output(tr("Bootloader detected")); return true; diff --git a/mainwindow.cpp b/mainwindow.cpp index dd61d59..2d80b79 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,12 +21,24 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + + ui->comboTransport->addItem("UART"); + ui->comboTransport->addItem("USB"); +#if EFM32LOADER_BLE + ui->comboTransport->addItem("BLE"); +#endif + //ui->lineASCII->hide(); ui->textLog->setFont(QFont("Courier New", 9)); loader = new GeckoLoader(this); serialPort = loader->serialPort(); + + +#if EFM32LOADER_BLE bleDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); +#endif + _connected = false; readSettings(); @@ -34,23 +46,26 @@ MainWindow::MainWindow(QWidget *parent) : connect(loader, SIGNAL(output(QString)), this, SLOT(log(QString))); connect(serialPort, SIGNAL(readyRead()), this, SLOT(slotDataReady())); - connect(ui->buttonScanBLE, SIGNAL(clicked(bool)), this, SLOT(slotScanBLE())); - connect(ui->buttonConnectBLE, SIGNAL(clicked(bool)), this, SLOT(slotConnectBLE())); connect(ui->buttonHelp, SIGNAL(clicked()), this, SLOT(slotHelp())); connect(ui->buttonReload, SIGNAL(clicked()), this, SLOT(slotReloadSerialPorts())); connect(ui->buttonBrowse, SIGNAL(clicked()), this, SLOT(slotBrowse())); connect(ui->buttonUpload, SIGNAL(clicked()), this, SLOT(slotUpload())); connect(ui->buttonConnect, SIGNAL(clicked()), this, SLOT(slotConnect())); connect(ui->comboTransport, SIGNAL(currentIndexChanged(int)), this, SLOT(slotTransport())); + connect(ui->buttonSendASCII, SIGNAL(clicked(bool)), this, SLOT(slotSendASCII())); - connect(ui->lineASCII, SIGNAL(returnPressed()), this, SLOT(slotSendASCII())); - +#if EFM32LOADER_BLE + connect(ui->buttonScanBLE, SIGNAL(clicked(bool)), this, SLOT(slotScanBLE())); + connect(ui->buttonConnectBLE, SIGNAL(clicked(bool)), this, SLOT(slotConnectBLE())); connect(bleDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), this, SLOT(slotDeviceDiscovered(QBluetoothDeviceInfo))); connect(bleDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(slotDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error))); connect(bleDiscoveryAgent, SIGNAL(finished()), this, SLOT(slotDeviceScanFinished())); +#endif + + connect(ui->lineASCII, SIGNAL(returnPressed()), this, SLOT(slotSendASCII())); updateInterface(); } @@ -141,6 +156,7 @@ void MainWindow::slotTransport() } +#if EFM32LOADER_BLE void MainWindow::slotScanBLE() { log("BLE scanning..."); @@ -175,6 +191,7 @@ void MainWindow::slotDeviceScanFinished() { log("BLE scan finished"); } +#endif void MainWindow::slotUpload() { @@ -191,7 +208,8 @@ void MainWindow::slotUpload() void MainWindow::slotSendASCII() { QString text = ui->lineASCII->text(); - serialPort->write(text.toLatin1()); + if(serialPort->isOpen()) + serialPort->write(text.toLatin1()); } void MainWindow::slotDataReady() @@ -239,6 +257,12 @@ void MainWindow::updateInterface() { ui->stackedWidget->setCurrentIndex(0); } + + ui->labelASCII->setVisible(!transportIsBLE); + ui->lineASCII->setVisible(!transportIsBLE); + ui->buttonSendASCII->setVisible(!transportIsBLE); + + ui->buttonSendASCII->setEnabled(_connected); } #endif //EFM32_LOADER_GUI diff --git a/mainwindow.h b/mainwindow.h index 62557b5..e32c569 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -22,7 +22,10 @@ #ifdef EFM32_LOADER_GUI #include + +#if EFM32LOADER_BLE #include +#endif namespace Ui { class MainWindow; @@ -49,12 +52,14 @@ private slots: void slotSendASCII(); void slotDataReady(); +#if EFM32LOADER_BLE void slotScanBLE(); void slotConnectBLE(); void slotTestBLE(); void slotDeviceDiscovered(QBluetoothDeviceInfo info); void slotDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error err); void slotDeviceScanFinished(); +#endif void log(const QString &text); void updateInterface(); @@ -64,7 +69,9 @@ private slots: GeckoLoader *loader; QSerialPort *serialPort; +#if EFM32LOADER_BLE QBluetoothDeviceDiscoveryAgent *bleDiscoveryAgent; +#endif bool _connected; void readSettings(); diff --git a/mainwindow.ui b/mainwindow.ui index 1a5cfd7..24a1f4d 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -75,21 +75,6 @@ 0 - - - UART - - - - - USB - - - - - BLE - - @@ -285,6 +270,12 @@ + + + 80 + 0 + + Service UUID @@ -295,6 +286,12 @@ + + + 80 + 0 + + Char UUID @@ -346,7 +343,25 @@ - + + + + + ASCII + + + + + + + + + + Send + + + + textLog @@ -356,6 +371,7 @@ buttonHelp stackedWidget widgetBLE + labelASCII