Index: denali.pro.user =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- denali.pro.user (.../denali.pro.user) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ denali.pro.user (.../denali.pro.user) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -1,6 +1,6 @@ - + EnvironmentId Index: sources/bluetooth/BLEScanner.cpp =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/bluetooth/BLEScanner.cpp (.../BLEScanner.cpp) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/bluetooth/BLEScanner.cpp (.../BLEScanner.cpp) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -114,7 +114,7 @@ for (const QString &prefix : omronDeviceNamesPrefixes) { if (deviceInfo.name().toLower().contains(prefix.toLower())) { - devices.append(deviceInfo); + devices.insert(0, deviceInfo); emit didDiscoverDevice(deviceInfo); } } @@ -200,10 +200,7 @@ ); if (!c.isValid()) { qDebug() << "Cannot read device information."; - disconnect(timer, SIGNAL(timeout()), - this, SLOT(onRequestDeviceInformation())); - connect(timer, SIGNAL(timeout()), - this, SLOT(onRetryConnectToDevice())); + updateBLECuffCheckinType(true); return; } omronDeviceInformationService->readCharacteristic(c); @@ -216,7 +213,7 @@ void BLEScanner::onRequestDeviceInformation() { qDebug() << __FUNCTION__; -// onRequestDeviceInformation(); + onRequestDeviceSerialNumber(); } @@ -436,11 +433,34 @@ */ void BLEScanner::onControllerError(const QLowEnergyController::Error &error) { - qDebug() << __FUNCTION__ << "LE controller error: " << error; emit didReceiveControllerError(error); } /*! + * \brief BLEScanner::updateBLECuffCheckinType + * Toggles the type of check we do with the BLE cuff. + * If already connected, just query it repeatedly ever 1Hz. + * Otherwise, start trying to reconnect to it. + * \param retryConnection - if true, retry connection, normal checkin otherwise. + */ +void BLEScanner::updateBLECuffCheckinType(bool retryConnection) +{ + timer->stop(); + if (retryConnection) { + disconnect(timer, SIGNAL(timeout()), + this, SLOT(onRequestDeviceInformation())); + connect(timer, SIGNAL(timeout()), + this, SLOT(onRetryConnectToDevice())); + } else{ + disconnect(timer, SIGNAL(timeout()), + this, SLOT(onRetryConnectToDevice())); + connect(timer, SIGNAL(timeout()), + this, SLOT(onRequestDeviceInformation())); + } + timer->start(); +} + +/*! * \brief BLEScanner::onDeviceConnected * Called when we successfully connect to a device. * Starts the scan for services on the device @@ -451,10 +471,7 @@ lowEnergyController->discoverServices(); - disconnect(timer, SIGNAL(timeout()), - this, SLOT(onRetryConnectToDevice())); - connect(timer, SIGNAL(timeout()), - this, SLOT(onRequestDeviceInformation())); + updateBLECuffCheckinType(false); if (!timer->isActive()) timer->start(); @@ -471,29 +488,6 @@ } /*! - * \brief BLEScanner::onControllerStateChanged - * Slot called when the low energy controller state changes - * \param state - the new state of the low energy controller - */ -void BLEScanner::onControllerStateChanged(const QLowEnergyController::ControllerState &state) -{ - qDebug() << __FUNCTION__ << state; - switch (state) { - case (QLowEnergyController::ClosingState): - emit didDisconnectFromDevice(selectedDeviceInfo); - break; - case (QLowEnergyController::UnconnectedState): - case (QLowEnergyController::ConnectingState): - case (QLowEnergyController::ConnectedState): - case (QLowEnergyController::DiscoveringState): - case (QLowEnergyController::DiscoveredState): - case (QLowEnergyController::AdvertisingState): - default: - break; - } -} - -/*! * \brief BLEScanner::connectToDevice * Creates the low energy controller object * Configures the low energy controller signals @@ -521,9 +515,6 @@ connect(lowEnergyController, SIGNAL(disconnected()), this, SLOT(onDeviceDisconnected())); - connect(lowEnergyController, SIGNAL(stateChanged(QLowEnergyController::ControllerState)), - this, SLOT(onControllerStateChanged(QLowEnergyController::ControllerState))); - emit didStartConnectingToDevice(); lowEnergyController->connectToDevice(); } Index: sources/bluetooth/BLEScanner.h =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/bluetooth/BLEScanner.h (.../BLEScanner.h) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/bluetooth/BLEScanner.h (.../BLEScanner.h) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -82,6 +82,7 @@ void onQuitThread(); void onConnectToDevice(const QBluetoothDeviceInfo& deviceInfo); void onSetMacAddress(const QString &mac); + void updateBLECuffCheckinType(bool retryConnection); signals: void didReceiveBPMeasurement(bp_measurement_t); @@ -114,7 +115,6 @@ void onControllerError(const QLowEnergyController::Error &error); void onDeviceConnected(); void onDeviceDisconnected(); - void onControllerStateChanged(const QLowEnergyController::ControllerState &state); // service slots void onServiceStateChanged(const QLowEnergyService::ServiceState &serviceState); @@ -123,6 +123,8 @@ void onServiceCharacteristicsRead(const QLowEnergyCharacteristic &c,const QByteArray &byteArray); void onQuit(); + + // device monitoring void onRequestDeviceInformation(); void onRequestDeviceSerialNumber(); void onRetryConnectToDevice(); Index: sources/gui/qml/globals/Variables.qml =================================================================== diff -u -r7249125bb71e6fab4139590ee777c64ece9cf3be -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/gui/qml/globals/Variables.qml (.../Variables.qml) (revision 7249125bb71e6fab4139590ee777c64ece9cf3be) +++ sources/gui/qml/globals/Variables.qml (.../Variables.qml) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -111,8 +111,10 @@ readonly property int notificationBarIconHeight : 30 readonly property int notificationBarIconWidth : 30 + readonly property int settingsBLEListViewWidth : 360 + readonly property int settingsBLEItemRightMargin : 20 readonly property int settingsBLEButtonWidth : 300 - readonly property int settingsBLEButtonHeight : 75 + readonly property int settingsBLEButtonHeight : 85 readonly property int settingsBLEMargin : 75 readonly property int settingsBLEListViewMargin : 25 readonly property int settingsOptionWidth : 550 Index: sources/gui/qml/pages/SettingsBluetooth.qml =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/gui/qml/pages/SettingsBluetooth.qml (.../SettingsBluetooth.qml) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/gui/qml/pages/SettingsBluetooth.qml (.../SettingsBluetooth.qml) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -15,6 +15,7 @@ // Qt import QtQuick 2.12 +import QtQuick.Controls 2.12 // Project import Gui.Actions 0.1; @@ -32,7 +33,10 @@ signal clickedBack() BackButton { id : _backButton - onClicked: _root.clickedBack() + onClicked: { + vBluetooth.doSaveMyDevices() + _root.clickedBack() + } } TitleText { id: _title @@ -62,11 +66,13 @@ color: "transparent" height: Variables.settingsBLEButtonHeight width: Variables.settingsBLEButtonWidth - Text { - id: _status_text + Text { id: _status_text + anchors.leftMargin: 10 text: qsTr("Status: " + vBluetooth.status) color: Colors.textMain font.pixelSize: Fonts.fontPixelDialogText + wrapMode: Text.WordWrap + width: parent.width } } @@ -88,15 +94,27 @@ anchors.horizontalCenter: _pairedDevicesLabel.horizontalCenter anchors.bottom: _root.bottom anchors.bottomMargin: Variables.mainMenuHeight + Variables.notificationHeight - width: Variables.settingsBLEButtonWidth + width: Variables.settingsBLEListViewWidth clip: true spacing: 10 + ScrollBar.vertical: ScrollBar { id: _scrollBarPairedDevices + anchors.right: _pairedDevices.right + anchors.rightMargin: 3 + contentItem: Rectangle { + color: Colors.backgroundRangeRect + implicitWidth: 6 + radius: width / 2 + width: 3 + } + } + delegate: TouchRect { id: _pairedDevicesRect - anchors.horizontalCenter: parent.horizontalCenter - height: 85 - width: parent.width + anchors.right: parent.right + anchors.rightMargin: Variables.settingsBLEItemRightMargin + height: Variables.settingsBLEButtonHeight + width: Variables.settingsBLEButtonWidth color: Colors.backgroundMain border.color: Colors.borderButton radius: 5 @@ -153,15 +171,27 @@ anchors.horizontalCenter: _devicesLabel.horizontalCenter anchors.bottom: _root.bottom anchors.bottomMargin: Variables.mainMenuHeight + Variables.notificationHeight - width: Variables.settingsBLEButtonWidth + width: Variables.settingsBLEListViewWidth clip: true spacing: 10 + ScrollBar.vertical: ScrollBar { id: _scrollBarOtherDevices + anchors.right: _devices.right + anchors.rightMargin: 3 + contentItem: Rectangle { + color: Colors.backgroundRangeRect + implicitWidth: 6 + radius: width / 2 + width: 3 + } + } + delegate: TouchRect { id: _devices_rect - anchors.horizontalCenter: parent.horizontalCenter - height: 85 - width: parent.width + anchors.right: parent.right + anchors.rightMargin: Variables.settingsBLEItemRightMargin + height: Variables.settingsBLEButtonHeight + width: Variables.settingsBLEButtonWidth color: Colors.backgroundMain border.color: Colors.borderButton radius: 5 Index: sources/storage/StorageGlobals.cpp =================================================================== diff -u -rcb5477be624b09e13d5fc4498634ca621722fd0e -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision cb5477be624b09e13d5fc4498634ca621722fd0e) +++ sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -26,18 +26,21 @@ namespace Storage { // USB - const char *USB_Mount_Point = "/media/usb/"; - const char *USB_File_System = "vfat"; + const char *USB_Mount_Point = "/media/usb/"; + const char *USB_File_System = "vfat"; // Log - const char *Log_Base_Path_Name = "/media/sd-card/"; - const char *Log_Base_Path_Name_Location = "/media/sd-card/log/"; - const char *Log_File_Name = "denali.log"; + const char *Log_Base_Path_Name = "/media/sd-card/"; + const char *Log_Base_Path_Name_Location = "/media/sd-card/log/"; + const char *Log_File_Name = "denali.log"; // Treatment const char *Treatment_Base_Dir = "/media/sd-card/treatment/"; const char *Treatment_Profiles_Dir = "/media/sd-card/treatment/profiles/"; const char *Treatment_Parameter_Ranges_Path_JSON = "/media/sd-card/treatment/denali.conf"; - const char *SDCard_Base_Path_Name = "/media/sd-card/"; + // Bluetooth + const char *Bluetooth_Saved_Devices_Path_JSON = "/media/sd-card/treatment/bledevices.conf"; + + const char *SDCard_Base_Path_Name = "/media/sd-card/"; } Index: sources/storage/StorageGlobals.h =================================================================== diff -u -rcb5477be624b09e13d5fc4498634ca621722fd0e -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision cb5477be624b09e13d5fc4498634ca621722fd0e) +++ sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -24,13 +24,16 @@ extern const char *USB_File_System; // Log - extern const char *Log_Base_Path_Name ; + extern const char *Log_Base_Path_Name; extern const char *Log_Base_Path_Name_Location; - extern const char *Log_File_Name ; + extern const char *Log_File_Name; // Treatment - extern const char *Treatment_Base_Dir ; - extern const char *Treatment_Profiles_Dir ; + extern const char *Treatment_Base_Dir; + extern const char *Treatment_Profiles_Dir; extern const char *Treatment_Parameter_Ranges_Path_JSON; - extern const char *SDCard_Base_Path_Name ; + extern const char *SDCard_Base_Path_Name; + + // Bluetooth + extern const char *Bluetooth_Saved_Devices_Path_JSON; } Index: sources/view/VBluetooth.cpp =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/view/VBluetooth.cpp (.../VBluetooth.cpp) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/view/VBluetooth.cpp (.../VBluetooth.cpp) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -4,8 +4,11 @@ // Qt // Project +#include "FileHandler.h" +#include "FileSaver.h" using namespace View; +using namespace Storage; VBluetooth::VBluetooth(QObject *parent) : QObject(parent) { @@ -38,7 +41,10 @@ connect(this, SIGNAL(didRequestScanForDevices()), &_BLEScanner, SLOT(doScanForDevices())); + connect(this, SIGNAL(didRequestConcurrentSave(QString,QString,bool)), + &_FileSaver, SLOT(onConcurrentSave(QString,QString,bool))); + onLoadMyDevices(); } /*! @@ -82,7 +88,7 @@ { VBluetoothDeviceInfo *info = new VBluetoothDeviceInfo(device); if (!isDeviceAlreadyPaired(device)) - bleDevices.append(info); + bleDevices.insert(0, info); qDebug() << "VBluetooth: Discovered " << device.address(); emit didDevicesChanged(); } @@ -298,3 +304,39 @@ emit didPairedDevicesChanged(); onUpdateStatus(tr("Paired, Not Connected.")); } + +/*! + * \brief VBluetooth::loadMyDevices + * Loads previously selected devices from disk + */ +void VBluetooth::onLoadMyDevices(const QString &path) +{ + pairedDevices.clear(); + QJsonObject obj; + if (!FileHandler::readJSON(path, obj)) + { + LOG_EVENT(tr("Could not load my bluetooth devices from %1").arg(path)); + return; + } + + for (const QString& key : obj.keys()) + { + VBluetoothDeviceInfo *info = new VBluetoothDeviceInfo(key, obj[key].toString()); + pairedDevices.append(info); + } +} + +/*! + * \brief VBluetooth::saveMyDevices + * Saves selected devices to disk + */ +void VBluetooth::doSaveMyDevices(const QString &path) +{ + QJsonObject obj; + + for (QList::iterator iter = pairedDevices.begin(); iter != pairedDevices.end(); ++iter) + obj[((VBluetoothDeviceInfo*)(*iter))->getAddress()] = ((VBluetoothDeviceInfo*)(*iter))->getName(); + + QJsonDocument document(obj); + emit didRequestConcurrentSave(path, document.toJson(), false); +} Index: sources/view/VBluetooth.h =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/view/VBluetooth.h (.../VBluetooth.h) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/view/VBluetooth.h (.../VBluetooth.h) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -11,6 +11,7 @@ #include "GuiController.h" using namespace Gui; +using namespace Storage; // forward declarations class tst_views; @@ -32,6 +33,7 @@ QVariant doGetDevices(); QVariant doGetPairedDevices(); void doSelectDevice(const QString &addr); + void doSaveMyDevices(const QString &path = Bluetooth_Saved_Devices_Path_JSON); signals: void didDevicesChanged(); @@ -40,6 +42,7 @@ void didStatusChanged(); void didRequestScanForDevices(); void didPairedDevicesChanged(); + void didRequestConcurrentSave(QString, QString, bool); private: QList bleDevices; @@ -61,6 +64,7 @@ void onControllerError(QLowEnergyController::Error error); void onConnectedToDevice(const QBluetoothDeviceInfo &deviceInfo); void onDisconnectedFromDevice(const QBluetoothDeviceInfo &deviceInfo); + void onLoadMyDevices(const QString &path = Bluetooth_Saved_Devices_Path_JSON); }; } #endif // VBLUETOOTH_H Index: sources/view/VBluetoothDeviceInfo.cpp =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/view/VBluetoothDeviceInfo.cpp (.../VBluetoothDeviceInfo.cpp) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/view/VBluetoothDeviceInfo.cpp (.../VBluetoothDeviceInfo.cpp) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -13,16 +13,28 @@ * Constructor for the VBluetoothDeviceInfo class * \param info - the device information */ -VBluetoothDeviceInfo::VBluetoothDeviceInfo(const QBluetoothDeviceInfo &info) : device(info), connected(false) {} +VBluetoothDeviceInfo::VBluetoothDeviceInfo(const QBluetoothDeviceInfo &info) : _connected(false) +{ + _address = info.address().toString(); + _name = info.name(); +} /*! + * \brief VBluetoothDeviceInfo::VBluetoothDeviceInfo + * Constructor for the VBluetoothDeviceInfo class + * \param address - (QString) bluetooth address of the device + * \param name - (QString) name of the bluetooth device + */ +VBluetoothDeviceInfo::VBluetoothDeviceInfo(const QString &address, const QString &name) : _address(address), _name(name), _connected(false) {} + +/*! * \brief VBluetoothDeviceInfo::getName * Gets the name of the device * \return QString - the name of the device */ QString VBluetoothDeviceInfo::getName() const { - return device.name(); + return _name; } /*! @@ -32,7 +44,7 @@ */ QString VBluetoothDeviceInfo::getAddress() const { - return device.address().toString(); + return _address; } /*! @@ -41,9 +53,9 @@ */ void VBluetoothDeviceInfo::setConnected(const bool &conn) { - if (conn != connected) + if (conn != _connected) { - connected = conn; + _connected = conn; emit deviceChanged(); } } @@ -55,5 +67,5 @@ */ bool VBluetoothDeviceInfo::isConnected() const { - return connected; + return _connected; } Index: sources/view/VBluetoothDeviceInfo.h =================================================================== diff -u -r5696b8db4628ee3143d93952c5dbdf511fa985b1 -r5220c64dd3a0fc9c322a68884e73503bb7893d12 --- sources/view/VBluetoothDeviceInfo.h (.../VBluetoothDeviceInfo.h) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) +++ sources/view/VBluetoothDeviceInfo.h (.../VBluetoothDeviceInfo.h) (revision 5220c64dd3a0fc9c322a68884e73503bb7893d12) @@ -18,7 +18,8 @@ Q_PROPERTY(bool connected READ isConnected NOTIFY deviceChanged) public: - VBluetoothDeviceInfo(const QBluetoothDeviceInfo &device); + explicit VBluetoothDeviceInfo(const QBluetoothDeviceInfo &device); + VBluetoothDeviceInfo(const QString &_address, const QString &_name); QString getName() const; QString getAddress() const; bool isConnected() const; @@ -35,8 +36,9 @@ return true; } - QBluetoothDeviceInfo device; - bool connected; + QString _address; + QString _name; + bool _connected; }; }