Skip to content

Commit

Permalink
resolved crashing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Feb 15, 2019
1 parent 36520a3 commit 89a36ab
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 81 deletions.
13 changes: 13 additions & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ install(FILES
DESTINATION "."
)

add_custom_command(
TARGET qmsgpack
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${install_dir}/bin/qmsgpackd.dll ${CMAKE_BINARY_DIR}
)


SET(QUAZIP_LIB_VERSION_SUFFIX 5)
ExternalProject_Add(quazip
GIT_REPOSITORY https://github.com/stachenov/quazip.git
Expand All @@ -48,6 +55,12 @@ install(FILES
DESTINATION "."
)

add_custom_command(
TARGET quazip
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${install_dir}/lib/quazip${QUAZIP_LIB_VERSION_SUFFIX}d.dll ${CMAKE_BINARY_DIR}
)

add_dependencies(quazip_extern quazip)
add_dependencies(qmsgpack_extern qmsgpack)

Expand Down
29 changes: 14 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ set (SOURCES
forms/sensorpanel.cpp
forms/profiledialog.cpp
forms/mbientconfigpanel.cpp
forms/deviceloadingdialog.cpp

common/main.cpp
common/metawearwrapperbase.cpp
common/util.cpp
common/BluetoothAddress.cpp)
common/BluetoothAddress.cpp
common/BaseDiscoveryAgent.cpp)

set(HEADERS
qcustomplot.h
Expand All @@ -36,6 +38,7 @@ set(HEADERS
forms/mainwindow.h
forms/profiledialog.h
forms/mbientconfigpanel.h
forms/deviceloadingdialog.h

common/metawearwrapperbase.h
common/util.h
Expand All @@ -48,8 +51,7 @@ set ( UIS
forms/sensorpanel.ui
forms/deviceselectdialog.ui
forms/mbientconfigpanel.ui
forms/profiledialog.ui
)
forms/profiledialog.ui )

set ( RESOURCES
qml.qrc
Expand All @@ -75,7 +77,6 @@ if (UNIX)
endif (UNIX)

if (MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
include_directories(platform/windows)

set (PLATFORM_SOURCE
Expand Down Expand Up @@ -126,6 +127,11 @@ if (MSVC)
COMMAND ${WINDEPLOYQT_EXECUTABLE} --compiler-runtime --dir ${CMAKE_BINARY_DIR}/windeployqt_stuff $<TARGET_FILE:SMART>
)

add_custom_command(
TARGET SMART POST_BUILD
COMMAND ${WINDEPLOYQT_EXECUTABLE} --compiler-runtime $<TARGET_FILE:SMART>
)

install(
DIRECTORY ${CMAKE_BINARY_DIR}/windeployqt_stuff/
DESTINATION .
Expand All @@ -134,20 +140,11 @@ if (MSVC)
target_link_libraries(SMART wsock32 ws2_32)

set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
set(CMAKE_INSTALL_DEBUG_LIBRARIES TRUE)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ./)
include(InstallRequiredSystemLibraries)
endif(MSVC)


install(FILES
$<TARGET_FILE:Qt5::Widgets>
$<TARGET_FILE:Qt5::Core>
$<TARGET_FILE:Qt5::Gui>
$<TARGET_FILE:Qt5::Quick>
$<TARGET_FILE:Qt5::PrintSupport>
DESTINATION "."
)

install(TARGETS SMART
DESTINATION "."
)
Expand Down Expand Up @@ -178,7 +175,9 @@ set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
set(CPACK_PACKAGE_EXECUTABLES "SMART" "SMART")
set(CPACK_CREATE_DESKTOP_LINKS "SMART")
set(CPACK_NSIS_MODIFY_PATH "ON")
set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/icon.ico")

set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/icons\\\\gait-icon.bmp")
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/icons/gait-icon.ico")
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/icons/gait-icon.ico")

INCLUDE(CPack)
8 changes: 8 additions & 0 deletions common/BaseDiscoveryAgent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <common/BaseDiscoveryAgent.h>

void BaseDiscoveryAgent::query() {
QMap<QString, BluetoothAddress>::iterator i;
for (i = _agentCache.begin(); i != _agentCache.end(); ++i) {
emit deviceDiscovered(i.value());
}
}
9 changes: 7 additions & 2 deletions common/BaseDiscoveryAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@

#include <QtCore/QObject>
#include "BluetoothAddress.h"
#include <QMap>

class BaseDiscoveryAgent : public QObject{
Q_OBJECT
private:
QMap<QString, BluetoothAddress> _agentCache;
public:
BaseDiscoveryAgent(){

BaseDiscoveryAgent(QObject *parent = nullptr) : QObject(parent), BaseDiscoveryAgent::_agentCache(QMap<QString, BluetoothAddress>()) {
connect(this, &BaseDiscoveryAgent::deviceDiscovered, [=](BluetoothAddress addr) {
_agentCache.insert(addr.getMac(), addr);
});
}
~BaseDiscoveryAgent(){

}

virtual void start() = 0;
void query();
virtual void stop() = 0;
signals:
void deviceDiscovered(BluetoothAddress address);
Expand Down
14 changes: 14 additions & 0 deletions forms/deviceloadingdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <forms/deviceloadingdialog.h>
#include <forms/mbientconfigpanel.h>
#include <QVBoxLayout>

DeviceLoadingDialog::DeviceLoadingDialog(const QList<MbientConfigPanel*>& payload, QWidget *parent ) :
QDialog(parent), m_payloads(payload){
QVBoxLayout* verticalLayout = new QVBoxLayout(this);


}

DeviceLoadingDialog::~DeviceLoadingDialog() {

}
39 changes: 39 additions & 0 deletions forms/deviceloadingdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2019 GaitRehabilitation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef DEVICE_LOADING_DIALOG_H
#define DEVICE_LOADING_DIALOG_H

#include <QDialog>
#include <QList>
#include <QMap>

class MetawearWrapperBase;
class MbientConfigPanel;
class DeviceLoadingDialog : public QDialog {
Q_OBJECT
private:
QList<MbientConfigPanel*> m_payloads;
QMap<QString, MbientConfigPanel*> m_mappings;

public:
explicit DeviceLoadingDialog(const QList<MbientConfigPanel*>& payload,QWidget *parent = nullptr);
~DeviceLoadingDialog();
signals:
void OnConfigured(MetawearWrapperBase* result);

};
#endif
103 changes: 54 additions & 49 deletions forms/deviceselectdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,67 @@
#include <QListView>
#include "common/DiscoveryAgent.h"

DeviceSelectDialog::DeviceSelectDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::DeviceSelectDialog),
m_deviceInfo(),
m_deviceBlackList(),
m_discoveryAgent(new DiscoveryAgent()){
ui->setupUi(this);

connect(ui->scan, &QPushButton::clicked, this,[=](){
ui->scan->setEnabled(false);
m_discoveryAgent->start();
});
connect(ui->clear, &QPushButton::clicked,this,[=](){
ui->deviceList->clear();
m_discoveryAgent->stop();
});
// connect(m_discoveryAgent,&QBluetoothDeviceDiscoveryAgent::finished, this, [=](){ui->scan->setEnabled(true); });

// An entry is added for every device connected
qRegisterMetaType<BluetoothAddress>("BluetoothAddress");
connect(m_discoveryAgent, &DiscoveryAgent::deviceDiscovered, this,[=](BluetoothAddress info){
//if(info.name() != "MetaWear")
// return;
if(m_deviceBlackList.contains(info.getMac()))
return;


QString label = QString("%1 %2").arg(info.getMac()).arg(info.getTitle());
m_deviceInfo.insert(label, info);

QList<QListWidgetItem *> items = ui->deviceList->findItems(label, Qt::MatchExactly);
if (items.empty()) {
QListWidgetItem *item = new QListWidgetItem(label);
//QBluetoothLocalDevice::Pairing lpairingStatus = localDevice->pairingStatus(info.address());
//if (lpairingStatus == QBluetoothLocalDevice::Paired || lpairingStatus == QBluetoothLocalDevice::AuthorizedPaired) {
// item->setTextColor(QColor(Qt::green));
//} else {
item->setTextColor(QColor(Qt::black));
//}
ui->deviceList->addItem(item);
}
});

connect(ui->deviceList, &QListWidget::itemSelectionChanged, this,[=](){
ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(!(ui->deviceList->selectedItems().count() > 0));
});

ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
DeviceSelectDialog::DeviceSelectDialog(QWidget * parent):
m_discoveryAgent(new DiscoveryAgent()),
QDialog(parent),
ui(new Ui::DeviceSelectDialog),
m_deviceInfo(),
m_deviceBlackList()
{
ui->setupUi(this);

connect(ui->scan, &QPushButton::clicked, this, [=]() {
ui->scan->setEnabled(false);
m_discoveryAgent->start();
});
connect(ui->clear, &QPushButton::clicked, this, [=]() {
ui->deviceList->clear();
m_discoveryAgent->stop();
});
// connect(m_discoveryAgent,&QBluetoothDeviceDiscoveryAgent::finished, this, [=](){ui->scan->setEnabled(true); });

// An entry is added for every device connected
qRegisterMetaType<BluetoothAddress>("BluetoothAddress");
connect(m_discoveryAgent, &DiscoveryAgent::deviceDiscovered, this, [=](BluetoothAddress info) {
//if(info.name() != "MetaWear")
// return;
if (m_deviceBlackList.contains(info.getMac()))
return;


QString label = QString("%1 %2").arg(info.getMac()).arg(info.getTitle());
m_deviceInfo.insert(label, info);

QList<QListWidgetItem *> items = ui->deviceList->findItems(label, Qt::MatchExactly);
if (items.empty()) {
QListWidgetItem *item = new QListWidgetItem(label);
//QBluetoothLocalDevice::Pairing lpairingStatus = localDevice->pairingStatus(info.address());
//if (lpairingStatus == QBluetoothLocalDevice::Paired || lpairingStatus == QBluetoothLocalDevice::AuthorizedPaired) {
// item->setTextColor(QColor(Qt::green));
//} else {
item->setTextColor(QColor(Qt::black));
//}
ui->deviceList->addItem(item);
}
});

connect(ui->deviceList, &QListWidget::itemSelectionChanged, this, [=]() {
ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(!(ui->deviceList->selectedItems().count() > 0));
});

ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
m_discoveryAgent->query();
}

DeviceSelectDialog::~DeviceSelectDialog() { delete ui; }
DeviceSelectDialog::~DeviceSelectDialog() {
delete ui;
delete m_discoveryAgent;
}

void DeviceSelectDialog::accept() {
if (ui->deviceList->count() == 0)
return;


m_discoveryAgent->stop();
ui->scan->setEnabled(true);

Expand Down
1 change: 1 addition & 0 deletions forms/deviceselectdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DeviceSelectDialog : public QDialog {
QList<QString> m_deviceBlackList;

public:

explicit DeviceSelectDialog(QWidget *parent = nullptr);
~DeviceSelectDialog() override;

Expand Down
17 changes: 11 additions & 6 deletions forms/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "forms/mainwindow.h"
#include "forms/profiledialog.h"

#include <common/DiscoveryAgent.h>

#include "forms/sensorpanel.h"
#include <QFileDialog>
#include <QtDebug>
Expand All @@ -30,21 +32,24 @@
#include <common/metawearwrapperbase.h>
#include <forms/profiledialog.h>
#include <forms/mbientconfigpanel.h>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow),m_temporaryData(new QTemporaryDir()),m_triggerSingleShot(),m_triggerTime(0),m_updateTriggerTimer(),m_deviceIndex(0){
ui->setupUi(this);

// connect(this,&MainWindow::onConnectedDevices,m_deviceSelectDialog,&DeviceSelectDialog::updateDeviceBlackList);

connect(ui->actionAddDevice, &QAction::triggered, this,[=](){
ProfileDialog profileDialog(this);
connect(&profileDialog,&ProfileDialog::onProfileSelected,this,[=](const QList<MbientConfigPanel*>& payload){
for (int i = 0; i < payload.length(); ++i) {
DiscoveryAgent agent;
for (int i = 0; i < payload.length(); ++i) {
MbientConfigPanel* panel = payload.at(i);
MetawearWrapperBase* wrapper = panel->buildWrapper();

auto devicePanel = registerDevice(wrapper);
devicePanel->setName(panel->getName());
MetawearWrapperBase* wrapper = panel->buildWrapper(agent);
if (wrapper) {
auto devicePanel = registerDevice(wrapper);
devicePanel->setName(panel->getName());
}
}
});
profileDialog.exec();
Expand Down
Loading

0 comments on commit 89a36ab

Please sign in to comment.