From dc8ad5c03a204b1546451e15ef0be7dabe45b388 Mon Sep 17 00:00:00 2001 From: nymea Date: Wed, 7 Aug 2019 18:29:57 +0200 Subject: [PATCH 01/12] added battery interface --- senic/devicepluginsenic.cpp | 23 ++++++++++++++--------- senic/devicepluginsenic.json | 23 ++++++++++++----------- senic/nuimo.cpp | 7 ++++++- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index f47ef1cb..63241891 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -32,8 +32,7 @@ DevicePluginSenic::DevicePluginSenic() void DevicePluginSenic::init() { - m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(10); - connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout); + } Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) @@ -57,11 +56,15 @@ Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &devi Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) { + if (!m_reconnectTimer) { + m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(10); + connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout); + } + qCDebug(dcSenic()) << "Setup device" << device->name() << device->params(); - QString name = device->paramValue(nuimoDeviceNameParamTypeId).toString(); QBluetoothAddress address = QBluetoothAddress(device->paramValue(nuimoDeviceMacParamTypeId).toString()); - QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo(address, name, 0); + QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo(address, device->name(), 0); BluetoothLowEnergyDevice *bluetoothDevice = hardwareManager()->bluetoothLowEnergyManager()->registerDevice(deviceInfo, QLowEnergyController::RandomAddress); @@ -104,7 +107,7 @@ Device::DeviceError DevicePluginSenic::executeAction(Device *device, const Actio if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Stop") nuimo->showImage(Nuimo::MatrixTypeStop); if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Music") - nuimo->showImage(Nuimo::MatrixTypeStop); + nuimo->showImage(Nuimo::MatrixTypeMusic); if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Heart") nuimo->showImage(Nuimo::MatrixTypeHeart); @@ -122,6 +125,11 @@ void DevicePluginSenic::deviceRemoved(Device *device) Nuimo *nuimo = m_nuimos.key(device); m_nuimos.take(nuimo); delete nuimo; + + if (myDevices().isEmpty()) { + hardwareManager()->pluginTimerManager()->unregisterTimer(m_reconnectTimer); + m_reconnectTimer = nullptr; + } } bool DevicePluginSenic::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo) @@ -158,9 +166,8 @@ void DevicePluginSenic::onBluetoothDiscoveryFinished() foreach (const QBluetoothDeviceInfo &deviceInfo, reply->discoveredDevices()) { if (deviceInfo.name().contains("Nuimo")) { if (!verifyExistingDevices(deviceInfo)) { - DeviceDescriptor descriptor(nuimoDeviceClassId, "Nuimo", deviceInfo.address().toString()); + DeviceDescriptor descriptor(nuimoDeviceClassId, "Nuimo", deviceInfo.name() + " (" + deviceInfo.address().toString() + ")"); ParamList params; - params.append(Param(nuimoDeviceNameParamTypeId, deviceInfo.name())); params.append(Param(nuimoDeviceMacParamTypeId, deviceInfo.address().toString())); descriptor.setParams(params); deviceDescriptors.append(descriptor); @@ -212,5 +219,3 @@ void DevicePluginSenic::onRotationValueChanged(const uint &value) Device *device = m_nuimos.value(nuimo); device->setStateValue(nuimoRotationStateTypeId, value); } - - diff --git a/senic/devicepluginsenic.json b/senic/devicepluginsenic.json index 2aa6e5ba..c36ac5fc 100644 --- a/senic/devicepluginsenic.json +++ b/senic/devicepluginsenic.json @@ -13,15 +13,8 @@ "name": "nuimo", "displayName": "Nuimo", "createMethods": ["discovery"], - "interfaces": [ "simplemultibutton", "connectable"], + "interfaces": ["batterylevel", "simplemultibutton", "connectable"], "paramTypes": [ - { - "id": "db67d1e6-26fa-44ed-ad55-c6aef45ea2ea", - "name": "name", - "displayName": "name", - "type": "QString", - "inputType": "TextLine" - }, { "id": "71553f6a-2ed4-4896-bb7b-52e7dca948b2", "name": "mac", @@ -63,11 +56,19 @@ "type": "QString", "defaultValue": "-" }, + { + "id": "aabd660f-b0c5-49f6-b7b0-6ba8e0a8cfcd", + "name": "batteryCritical", + "displayName": "Battery critical", + "displayNameEvent": "Battery critical changed", + "type": "bool", + "defaultValue": true + }, { "id": "b5ee2465-7fa1-450b-8073-f115537d3409", - "name": "battery", - "displayName": "battery", - "displayNameEvent": "battery changed", + "name": "batteryLevel", + "displayName": "Battery", + "displayNameEvent": "Battery changed", "type": "int", "minValue": 0, "maxValue": 100, diff --git a/senic/nuimo.cpp b/senic/nuimo.cpp index a5e87745..b659e474 100644 --- a/senic/nuimo.cpp +++ b/senic/nuimo.cpp @@ -224,7 +224,12 @@ void Nuimo::setBatteryValue(const QByteArray &data) int batteryPercentage = data.toHex().toUInt(0, 16); qCDebug(dcSenic()) << "Battery:" << batteryPercentage << "%"; - device()->setStateValue(nuimoBatteryStateTypeId, batteryPercentage); + device()->setStateValue(nuimoBatteryLevelStateTypeId, batteryPercentage); + if (batteryPercentage < 20) { + device()->setStateValue(nuimoBatteryCriticalStateTypeId, true); + } else { + device()->setStateValue(nuimoBatteryCriticalStateTypeId, false); + } } void Nuimo::onConnectedChanged(const bool &connected) From a20c43c0e5bcd062b4438fc9b141b2bca00bbce3 Mon Sep 17 00:00:00 2001 From: nymea Date: Wed, 7 Aug 2019 19:30:07 +0200 Subject: [PATCH 02/12] added auto symbol mode --- senic/devicepluginsenic.cpp | 43 +++++++++++++++++++++++++++++ senic/devicepluginsenic.h | 2 ++ senic/devicepluginsenic.json | 15 ++++++++++- senic/nuimo.cpp | 52 +++++++++++++++++++++++++++++++++++- senic/nuimo.h | 6 ++++- 5 files changed, 115 insertions(+), 3 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index 63241891..7473d228 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -110,6 +110,14 @@ Device::DeviceError DevicePluginSenic::executeAction(Device *device, const Actio nuimo->showImage(Nuimo::MatrixTypeMusic); if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Heart") nuimo->showImage(Nuimo::MatrixTypeHeart); + if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Next") + nuimo->showImage(Nuimo::MatrixTypeNext); + if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Previous") + nuimo->showImage(Nuimo::MatrixTypePrevious); + if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Circle") + nuimo->showImage(Nuimo::MatrixTypeCircle); + if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Light") + nuimo->showImage(Nuimo::MatrixTypeLight); return Device::DeviceErrorNoError; } @@ -185,8 +193,13 @@ void DevicePluginSenic::onButtonPressed() Nuimo *nuimo = static_cast(sender()); Device *device = m_nuimos.value(nuimo); emitEvent(Event(nuimoPressedEventTypeId, device->id(), ParamList() << Param(nuimoPressedEventButtonNameParamTypeId, "•"))); + + if(m_autoSymbolMode) { + nuimo->showImage(Nuimo::MatrixType::MatrixTypeCircle); + } } + void DevicePluginSenic::onButtonReleased() { // TODO: user timer for detekt long pressed (if needed) @@ -197,6 +210,7 @@ void DevicePluginSenic::onSwipeDetected(const Nuimo::SwipeDirection &direction) Nuimo *nuimo = static_cast(sender()); Device *device = m_nuimos.value(nuimo); + switch (direction) { case Nuimo::SwipeDirectionLeft: emitEvent(Event(nuimoPressedEventTypeId, device->id(), ParamList() << Param(nuimoPressedEventButtonNameParamTypeId, "←"))); @@ -211,6 +225,23 @@ void DevicePluginSenic::onSwipeDetected(const Nuimo::SwipeDirection &direction) emitEvent(Event(nuimoPressedEventTypeId, device->id(), ParamList() << Param(nuimoPressedEventButtonNameParamTypeId, "↓"))); break; } + + if (m_autoSymbolMode) { + switch (direction) { + case Nuimo::SwipeDirectionLeft: + nuimo->showImage(Nuimo::MatrixType::MatrixTypeLeft); + break; + case Nuimo::SwipeDirectionRight: + nuimo->showImage(Nuimo::MatrixType::MatrixTypeRight); + break; + case Nuimo::SwipeDirectionUp: + nuimo->showImage(Nuimo::MatrixType::MatrixTypeUp); + break; + case Nuimo::SwipeDirectionDown: + nuimo->showImage(Nuimo::MatrixType::MatrixTypeDown); + break; + } + } } void DevicePluginSenic::onRotationValueChanged(const uint &value) @@ -219,3 +250,15 @@ void DevicePluginSenic::onRotationValueChanged(const uint &value) Device *device = m_nuimos.value(nuimo); device->setStateValue(nuimoRotationStateTypeId, value); } + +void DevicePluginSenic::onPluginConfigurationChanged(const ParamTypeId ¶mTypeId, const QVariant &value) +{ + qCDebug(dcSenic()) << "Plugin configuration changed"; + + // Check auto symbol mode + if (paramTypeId == senicPluginAutoSymbolsParamTypeId) { + qCDebug(dcSenic()) << "Auto symbol mode" << (value.toBool() ? "enabled." : "disabled."); + m_autoSymbolMode = value.toBool(); + } + +} diff --git a/senic/devicepluginsenic.h b/senic/devicepluginsenic.h index 20f84dab..1ff2e7e8 100644 --- a/senic/devicepluginsenic.h +++ b/senic/devicepluginsenic.h @@ -49,10 +49,12 @@ public: private: QHash m_nuimos; PluginTimer *m_reconnectTimer = nullptr; + bool m_autoSymbolMode = true; bool verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo); private slots: + void onPluginConfigurationChanged(const ParamTypeId ¶mTypeId, const QVariant &value); void onReconnectTimeout(); void onBluetoothDiscoveryFinished(); diff --git a/senic/devicepluginsenic.json b/senic/devicepluginsenic.json index c36ac5fc..ec735948 100644 --- a/senic/devicepluginsenic.json +++ b/senic/devicepluginsenic.json @@ -2,6 +2,15 @@ "displayName": "Senic", "id": "413e9d77-335f-4ecf-abbc-8f2a8a399c39", "name": "Senic", + "paramTypes": [ + { + "id": "ba3d4269-940b-42ee-8c73-1e1bdea329c2", + "name": "autoSymbols", + "displayName": "Automatically display symbols", + "type": "bool", + "defaultValue": true + } + ], "vendors": [ { "displayName": "Senic", @@ -108,7 +117,11 @@ "Pause", "Stop", "Music", - "Heart" + "Heart", + "Next", + "Previous", + "Circle", + "Light" ] } ] diff --git a/senic/nuimo.cpp b/senic/nuimo.cpp index b659e474..441935b9 100644 --- a/senic/nuimo.cpp +++ b/senic/nuimo.cpp @@ -176,7 +176,57 @@ void Nuimo::showImage(const Nuimo::MatrixType &matrixType) " * "); time = 5; break; - default: + case MatrixTypeNext: + matrix = QByteArray( + " " + " * ** " + " ** ** " + " *** ** " + " ****** " + " *** ** " + " ** ** " + " * ** " + " "); + time = 5; + break; + case MatrixTypePrevious: + matrix = QByteArray( + " " + " ** * " + " ** ** " + " ** *** " + " ****** " + " ** *** " + " ** ** " + " ** * " + " "); + time = 5; + break; + case MatrixTypeCircle: + matrix = QByteArray( + " " + " " + " *** " + " * * " + " * * " + " * * " + " *** " + " " + " "); + time = 5; + break; + case MatrixTypeLight: + matrix = QByteArray( + " " + " *** " + " * * " + " * * " + " * * " + " *** " + " *** " + " *** " + " * "); + time = 5; break; } diff --git a/senic/nuimo.h b/senic/nuimo.h index d0928f38..fca27c8d 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -50,7 +50,11 @@ public: MatrixTypePause, MatrixTypeStop, MatrixTypeMusic, - MatrixTypeHeart + MatrixTypeHeart, + MatrixTypeNext, + MatrixTypePrevious, + MatrixTypeCircle, + MatrixTypeLight }; explicit Nuimo(Device *device, BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent = nullptr); From a2812c0810921c561a83044c0c60314e950b6af4 Mon Sep 17 00:00:00 2001 From: nymea Date: Wed, 7 Aug 2019 19:47:29 +0200 Subject: [PATCH 03/12] fixed rediscovery --- senic/devicepluginsenic.cpp | 30 ++++++++++++------------------ senic/devicepluginsenic.h | 2 -- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index 7473d228..224db6f4 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -140,15 +140,6 @@ void DevicePluginSenic::deviceRemoved(Device *device) } } -bool DevicePluginSenic::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo) -{ - foreach (Device *device, myDevices()) { - if (device->paramValue(nuimoDeviceMacParamTypeId).toString() == deviceInfo.address().toString()) - return true; - } - - return false; -} void DevicePluginSenic::onReconnectTimeout() { @@ -159,6 +150,7 @@ void DevicePluginSenic::onReconnectTimeout() } } + void DevicePluginSenic::onBluetoothDiscoveryFinished() { BluetoothDiscoveryReply *reply = static_cast(sender()); @@ -169,17 +161,21 @@ void DevicePluginSenic::onBluetoothDiscoveryFinished() return; } - QList deviceDescriptors; foreach (const QBluetoothDeviceInfo &deviceInfo, reply->discoveredDevices()) { if (deviceInfo.name().contains("Nuimo")) { - if (!verifyExistingDevices(deviceInfo)) { - DeviceDescriptor descriptor(nuimoDeviceClassId, "Nuimo", deviceInfo.name() + " (" + deviceInfo.address().toString() + ")"); - ParamList params; - params.append(Param(nuimoDeviceMacParamTypeId, deviceInfo.address().toString())); - descriptor.setParams(params); - deviceDescriptors.append(descriptor); + DeviceDescriptor descriptor(nuimoDeviceClassId, "Nuimo", deviceInfo.name() + " (" + deviceInfo.address().toString() + ")"); + ParamList params; + + foreach (Device *existingDevice, myDevices()) { + if (existingDevice->paramValue(nuimoDeviceMacParamTypeId).toString() == deviceInfo.address().toString()) { + descriptor.setDeviceId(existingDevice->id()); + break; + } } + params.append(Param(nuimoDeviceMacParamTypeId, deviceInfo.address().toString())); + descriptor.setParams(params); + deviceDescriptors.append(descriptor); } } @@ -210,7 +206,6 @@ void DevicePluginSenic::onSwipeDetected(const Nuimo::SwipeDirection &direction) Nuimo *nuimo = static_cast(sender()); Device *device = m_nuimos.value(nuimo); - switch (direction) { case Nuimo::SwipeDirectionLeft: emitEvent(Event(nuimoPressedEventTypeId, device->id(), ParamList() << Param(nuimoPressedEventButtonNameParamTypeId, "←"))); @@ -260,5 +255,4 @@ void DevicePluginSenic::onPluginConfigurationChanged(const ParamTypeId ¶mTyp qCDebug(dcSenic()) << "Auto symbol mode" << (value.toBool() ? "enabled." : "disabled."); m_autoSymbolMode = value.toBool(); } - } diff --git a/senic/devicepluginsenic.h b/senic/devicepluginsenic.h index 1ff2e7e8..a6593d8b 100644 --- a/senic/devicepluginsenic.h +++ b/senic/devicepluginsenic.h @@ -51,8 +51,6 @@ private: PluginTimer *m_reconnectTimer = nullptr; bool m_autoSymbolMode = true; - bool verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo); - private slots: void onPluginConfigurationChanged(const ParamTypeId ¶mTypeId, const QVariant &value); void onReconnectTimeout(); From 13e6629e8fa820a1ef092047e78bbf5727e95906 Mon Sep 17 00:00:00 2001 From: nymea Date: Wed, 7 Aug 2019 20:18:12 +0200 Subject: [PATCH 04/12] fixed auto symbol mode initialisation --- senic/devicepluginsenic.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index 224db6f4..6065d033 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -32,7 +32,8 @@ DevicePluginSenic::DevicePluginSenic() void DevicePluginSenic::init() { - + // Initialize plugin configurations + m_autoSymbolMode = configValue(senicPluginAutoSymbolsParamTypeId).toBool(); } Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) From c807790086913b6e9247f9a058c81ffcd4ca5fa1 Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 14:59:59 +0200 Subject: [PATCH 05/12] changed main interface type to button --- senic/devicepluginsenic.cpp | 1 + senic/devicepluginsenic.json | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index 6065d033..2cd3af7c 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -34,6 +34,7 @@ void DevicePluginSenic::init() { // Initialize plugin configurations m_autoSymbolMode = configValue(senicPluginAutoSymbolsParamTypeId).toBool(); + connect(this, &DevicePluginSenic::configValueChanged, this, &DevicePluginSenic::onPluginConfigurationChanged); } Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) diff --git a/senic/devicepluginsenic.json b/senic/devicepluginsenic.json index ec735948..f70fc8fa 100644 --- a/senic/devicepluginsenic.json +++ b/senic/devicepluginsenic.json @@ -22,12 +22,12 @@ "name": "nuimo", "displayName": "Nuimo", "createMethods": ["discovery"], - "interfaces": ["batterylevel", "simplemultibutton", "connectable"], + "interfaces": ["simplemultibutton", "connectable", "batterylevel"], "paramTypes": [ { "id": "71553f6a-2ed4-4896-bb7b-52e7dca948b2", "name": "mac", - "displayName": "mac address", + "displayName": "Mac address", "type": "QString", "inputType": "MacAddress" } @@ -87,8 +87,8 @@ { "id": "69a5f495-5452-434b-8fb8-b73d992c5446", "name": "rotation", - "displayName": "rotation", - "displayNameEvent": "rotation changed", + "displayName": "Rotation", + "displayNameEvent": "Rotation changed", "type": "int", "minValue": 0, "maxValue": 100, @@ -105,7 +105,7 @@ { "id": "a8f72c37-9cb5-4885-a7e4-b2b396f8e4cd", "name": "logo", - "displayName": "logo", + "displayName": "Logo", "type": "QString", "defaultValue": "Heart", "allowedValues": [ From 3bf9ca94c7cffe070d2df9c5cc468ec4fbaa055d Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 16:04:45 +0200 Subject: [PATCH 06/12] refactured nuimo class --- senic/devicepluginsenic.cpp | 50 +++++++++++++++++++++++++++++++++---- senic/devicepluginsenic.h | 4 ++- senic/nuimo.cpp | 38 +++++++++------------------- senic/nuimo.h | 14 +++-------- 4 files changed, 64 insertions(+), 42 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index 2cd3af7c..b4d9cf21 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -37,6 +37,7 @@ void DevicePluginSenic::init() connect(this, &DevicePluginSenic::configValueChanged, this, &DevicePluginSenic::onPluginConfigurationChanged); } + Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) { Q_UNUSED(params) @@ -56,6 +57,7 @@ Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &devi return Device::DeviceErrorAsync; } + Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) { if (!m_reconnectTimer) { @@ -70,11 +72,13 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) BluetoothLowEnergyDevice *bluetoothDevice = hardwareManager()->bluetoothLowEnergyManager()->registerDevice(deviceInfo, QLowEnergyController::RandomAddress); - Nuimo *nuimo = new Nuimo(device, bluetoothDevice, this); + Nuimo *nuimo = new Nuimo(bluetoothDevice, this); connect(nuimo, &Nuimo::buttonPressed, this, &DevicePluginSenic::onButtonPressed); connect(nuimo, &Nuimo::buttonReleased, this, &DevicePluginSenic::onButtonReleased); connect(nuimo, &Nuimo::swipeDetected, this, &DevicePluginSenic::onSwipeDetected); connect(nuimo, &Nuimo::rotationValueChanged, this, &DevicePluginSenic::onRotationValueChanged); + connect(nuimo, &Nuimo::connectedChanged, this, &DevicePluginSenic::onConnectedChanged); + connect(nuimo, &Nuimo::deviceInformationChanged, this, &DevicePluginSenic::onDeviceInformationChanged); m_nuimos.insert(nuimo, device); nuimo->bluetoothDevice()->connectDevice(); @@ -82,6 +86,7 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) return Device::DeviceSetupStatusSuccess; } + Device::DeviceError DevicePluginSenic::executeAction(Device *device, const Action &action) { QPointer nuimo = m_nuimos.key(device); @@ -127,6 +132,7 @@ Device::DeviceError DevicePluginSenic::executeAction(Device *device, const Actio return Device::DeviceErrorActionTypeNotFound; } + void DevicePluginSenic::deviceRemoved(Device *device) { if (!m_nuimos.values().contains(device)) @@ -156,9 +162,10 @@ void DevicePluginSenic::onReconnectTimeout() void DevicePluginSenic::onBluetoothDiscoveryFinished() { BluetoothDiscoveryReply *reply = static_cast(sender()); + reply->deleteLater(); + if (reply->error() != BluetoothDiscoveryReply::BluetoothDiscoveryReplyErrorNoError) { qCWarning(dcSenic()) << "Bluetooth discovery error:" << reply->error(); - reply->deleteLater(); emit devicesDiscovered(nuimoDeviceClassId, QList()); return; } @@ -180,11 +187,17 @@ void DevicePluginSenic::onBluetoothDiscoveryFinished() deviceDescriptors.append(descriptor); } } - - reply->deleteLater(); emit devicesDiscovered(nuimoDeviceClassId, deviceDescriptors); } +void DevicePluginSenic::onConnectedChanged(bool connected) +{ + Nuimo *nuimo = static_cast(sender()); + Device *device = m_nuimos.value(nuimo); + + device->setStateValue(nuimoConnectedStateTypeId, connected); +} + void DevicePluginSenic::onButtonPressed() { @@ -200,9 +213,10 @@ void DevicePluginSenic::onButtonPressed() void DevicePluginSenic::onButtonReleased() { - // TODO: user timer for detekt long pressed (if needed) + // ENHANCEMENT: user timer to detekt long press events } + void DevicePluginSenic::onSwipeDetected(const Nuimo::SwipeDirection &direction) { Nuimo *nuimo = static_cast(sender()); @@ -241,6 +255,7 @@ void DevicePluginSenic::onSwipeDetected(const Nuimo::SwipeDirection &direction) } } + void DevicePluginSenic::onRotationValueChanged(const uint &value) { Nuimo *nuimo = static_cast(sender()); @@ -248,6 +263,18 @@ void DevicePluginSenic::onRotationValueChanged(const uint &value) device->setStateValue(nuimoRotationStateTypeId, value); } + +void DevicePluginSenic::onDeviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision) +{ + Nuimo *nuimo = static_cast(sender()); + Device *device = m_nuimos.value(nuimo); + + device->setStateValue(nuimoFirmwareRevisionStateTypeId, firmwareRevision); + device->setStateValue(nuimoHardwareRevisionStateTypeId, hardwareRevision); + device->setStateValue(nuimoSoftwareRevisionStateTypeId, softwareRevision); +} + + void DevicePluginSenic::onPluginConfigurationChanged(const ParamTypeId ¶mTypeId, const QVariant &value) { qCDebug(dcSenic()) << "Plugin configuration changed"; @@ -258,3 +285,16 @@ void DevicePluginSenic::onPluginConfigurationChanged(const ParamTypeId ¶mTyp m_autoSymbolMode = value.toBool(); } } + +void DevicePluginSenic::onBatteryValueChanged(const uint &percentage) +{ + Nuimo *nuimo = static_cast(sender()); + Device *device = m_nuimos.value(nuimo); + + device->setStateValue(nuimoBatteryLevelStateTypeId, percentage); + if (percentage < 20) { + device->setStateValue(nuimoBatteryCriticalStateTypeId, true); + } else { + device->setStateValue(nuimoBatteryCriticalStateTypeId, false); + } +} diff --git a/senic/devicepluginsenic.h b/senic/devicepluginsenic.h index a6593d8b..2302a555 100644 --- a/senic/devicepluginsenic.h +++ b/senic/devicepluginsenic.h @@ -56,11 +56,13 @@ private slots: void onReconnectTimeout(); void onBluetoothDiscoveryFinished(); + void onConnectedChanged(bool connected); + void onBatteryValueChanged(const uint &percentage); void onButtonPressed(); void onButtonReleased(); void onSwipeDetected(const Nuimo::SwipeDirection &direction); void onRotationValueChanged(const uint &value); - + void onDeviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision); }; #endif // DEVICEPLUGINSENIC_H diff --git a/senic/nuimo.cpp b/senic/nuimo.cpp index 441935b9..6c2dabda 100644 --- a/senic/nuimo.cpp +++ b/senic/nuimo.cpp @@ -35,19 +35,14 @@ static QBluetoothUuid inputRotationCharacteristicUuid = QBluetoothUuid(QUuid(" static QBluetoothUuid inputButtonCharacteristicUuid = QBluetoothUuid(QUuid("f29b1529-cb19-40f3-be5c-7241ecb82fd2")); -Nuimo::Nuimo(Device *device, BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent) : +Nuimo::Nuimo(BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent) : QObject(parent), - m_device(device), m_bluetoothDevice(bluetoothDevice) { connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::connectedChanged, this, &Nuimo::onConnectedChanged); connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::servicesDiscoveryFinished, this, &Nuimo::onServiceDiscoveryFinished); } -Device *Nuimo::device() -{ - return m_device; -} BluetoothLowEnergyDevice *Nuimo::bluetoothDevice() { @@ -269,23 +264,12 @@ void Nuimo::printService(QLowEnergyService *service) } } -void Nuimo::setBatteryValue(const QByteArray &data) -{ - int batteryPercentage = data.toHex().toUInt(0, 16); - qCDebug(dcSenic()) << "Battery:" << batteryPercentage << "%"; - device()->setStateValue(nuimoBatteryLevelStateTypeId, batteryPercentage); - if (batteryPercentage < 20) { - device()->setStateValue(nuimoBatteryCriticalStateTypeId, true); - } else { - device()->setStateValue(nuimoBatteryCriticalStateTypeId, false); - } -} void Nuimo::onConnectedChanged(const bool &connected) { qCDebug(dcSenic()) << m_bluetoothDevice->name() << m_bluetoothDevice->address().toString() << (connected ? "connected" : "disconnected"); - m_device->setStateValue(nuimoConnectedStateTypeId, connected); + emit connectedChanged(connected); if (!connected) { // Clean up services @@ -399,11 +383,11 @@ void Nuimo::onDeviceInfoServiceStateChanged(const QLowEnergyService::ServiceStat qCDebug(dcSenic()) << "Device info service discovered."; printService(m_deviceInfoService); + QString firmware = QString::fromUtf8(m_deviceInfoService->characteristic(QBluetoothUuid::FirmwareRevisionString).value()); + QString hardware = QString::fromUtf8(m_deviceInfoService->characteristic(QBluetoothUuid::HardwareRevisionString).value()); + QString software = QString::fromUtf8(m_deviceInfoService->characteristic(QBluetoothUuid::SoftwareRevisionString).value()); - device()->setStateValue(nuimoFirmwareRevisionStateTypeId, QString::fromUtf8(m_deviceInfoService->characteristic(QBluetoothUuid::FirmwareRevisionString).value())); - device()->setStateValue(nuimoHardwareRevisionStateTypeId, QString::fromUtf8(m_deviceInfoService->characteristic(QBluetoothUuid::HardwareRevisionString).value())); - device()->setStateValue(nuimoSoftwareRevisionStateTypeId, QString::fromUtf8(m_deviceInfoService->characteristic(QBluetoothUuid::SoftwareRevisionString).value())); - + emit deviceInformationChanged(firmware, hardware, software); } void Nuimo::onBatteryServiceStateChanged(const QLowEnergyService::ServiceState &state) @@ -426,13 +410,15 @@ void Nuimo::onBatteryServiceStateChanged(const QLowEnergyService::ServiceState & QLowEnergyDescriptor notificationDescriptor = m_batteryCharacteristic.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration); m_batteryService->writeDescriptor(notificationDescriptor, QByteArray::fromHex("0100")); - setBatteryValue(m_batteryCharacteristic.value()); + uint batteryPercentage = m_batteryCharacteristic.value().toHex().toUInt(nullptr, 16); + emit batteryValueChanged(batteryPercentage); } void Nuimo::onBatteryCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) { if (characteristic.uuid() == m_batteryCharacteristic.uuid()) { - setBatteryValue(value); + uint batteryPercentage = value.toHex().toUInt(nullptr, 16); + emit batteryValueChanged(batteryPercentage); } } @@ -482,7 +468,7 @@ void Nuimo::onInputServiceStateChanged(const QLowEnergyService::ServiceState &st void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) { if (characteristic.uuid() == m_inputButtonCharacteristic.uuid()) { - bool pressed = (bool)value.toHex().toUInt(0, 16); + bool pressed = (bool)value.toHex().toUInt(nullptr, 16); qCDebug(dcSenic()) << "Button:" << (pressed ? "pressed": "released"); if (pressed) { emit buttonPressed(); @@ -493,7 +479,7 @@ void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &charact } if (characteristic.uuid() == m_inputSwipeCharacteristic.uuid()) { - quint8 swipe = (quint8)value.toHex().toUInt(0, 16); + quint8 swipe = (quint8)value.toHex().toUInt(nullptr, 16); switch (swipe) { case 0: qCDebug(dcSenic()) << "Swipe: Left"; diff --git a/senic/nuimo.h b/senic/nuimo.h index fca27c8d..8bec379e 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -27,7 +27,6 @@ #include #include "typeutils.h" -#include "devices/device.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h" class Nuimo : public QObject @@ -57,15 +56,13 @@ public: MatrixTypeLight }; - explicit Nuimo(Device *device, BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent = nullptr); + explicit Nuimo(BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent = nullptr); - Device *device(); BluetoothLowEnergyDevice *bluetoothDevice(); void showImage(const MatrixType &matrixType); private: - Device *m_device = nullptr; BluetoothLowEnergyDevice *m_bluetoothDevice = nullptr; QLowEnergyService *m_deviceInfoService = nullptr; @@ -83,19 +80,16 @@ private: uint m_rotationValue; void showMatrix(const QByteArray &matrix, const int &seconds); - void printService(QLowEnergyService *service); - // Set states - void setBatteryValue(const QByteArray &data); - signals: - void availableChanged(); + void connectedChanged(bool connected); void buttonPressed(); void buttonReleased(); - void batteryValueChaged(const uint &percentage); + void batteryValueChanged(const uint &percentage); void swipeDetected(const SwipeDirection &direction); void rotationValueChanged(const uint &value); + void deviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision); private slots: void onConnectedChanged(const bool &connected); From 9e0afd600ac5a03993a1034d2115c2282422dad5 Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 17:06:26 +0200 Subject: [PATCH 07/12] added long press events --- senic/devicepluginsenic.cpp | 25 ++++++++++++++----- senic/devicepluginsenic.h | 2 +- senic/devicepluginsenic.json | 14 ++++++++++- senic/nuimo.cpp | 48 ++++++++++++++++++++++++++++++++---- senic/nuimo.h | 10 ++++++-- 5 files changed, 84 insertions(+), 15 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index b4d9cf21..c8cfa066 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -73,8 +73,9 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) BluetoothLowEnergyDevice *bluetoothDevice = hardwareManager()->bluetoothLowEnergyManager()->registerDevice(deviceInfo, QLowEnergyController::RandomAddress); Nuimo *nuimo = new Nuimo(bluetoothDevice, this); + nuimo->setLongPressTime(configValue(senicPluginLongPressTimeParamTypeId).toInt()); connect(nuimo, &Nuimo::buttonPressed, this, &DevicePluginSenic::onButtonPressed); - connect(nuimo, &Nuimo::buttonReleased, this, &DevicePluginSenic::onButtonReleased); + connect(nuimo, &Nuimo::buttonLongPressed, this, &DevicePluginSenic::onButtonLongPressed); connect(nuimo, &Nuimo::swipeDetected, this, &DevicePluginSenic::onSwipeDetected); connect(nuimo, &Nuimo::rotationValueChanged, this, &DevicePluginSenic::onRotationValueChanged); connect(nuimo, &Nuimo::connectedChanged, this, &DevicePluginSenic::onConnectedChanged); @@ -194,7 +195,6 @@ void DevicePluginSenic::onConnectedChanged(bool connected) { Nuimo *nuimo = static_cast(sender()); Device *device = m_nuimos.value(nuimo); - device->setStateValue(nuimoConnectedStateTypeId, connected); } @@ -205,15 +205,21 @@ void DevicePluginSenic::onButtonPressed() Device *device = m_nuimos.value(nuimo); emitEvent(Event(nuimoPressedEventTypeId, device->id(), ParamList() << Param(nuimoPressedEventButtonNameParamTypeId, "•"))); - if(m_autoSymbolMode) { - nuimo->showImage(Nuimo::MatrixType::MatrixTypeCircle); + if (m_autoSymbolMode) { + nuimo->showImage(Nuimo::MatrixTypeCircle); } } -void DevicePluginSenic::onButtonReleased() +void DevicePluginSenic::onButtonLongPressed() { - // ENHANCEMENT: user timer to detekt long press events + Nuimo *nuimo = static_cast(sender()); + Device *device = m_nuimos.value(nuimo); + emitEvent(Event(nuimoLongPressedEventTypeId, device->id())); + + if (m_autoSymbolMode) { + nuimo->showImage(Nuimo::MatrixTypeFilledCircle); + } } @@ -284,6 +290,13 @@ void DevicePluginSenic::onPluginConfigurationChanged(const ParamTypeId ¶mTyp qCDebug(dcSenic()) << "Auto symbol mode" << (value.toBool() ? "enabled." : "disabled."); m_autoSymbolMode = value.toBool(); } + + if (paramTypeId == senicPluginLongPressTimeParamTypeId) { + qCDebug(dcSenic()) << "Long press time" << value.toUInt(); + foreach(Nuimo *nuimo, m_nuimos.keys()) { + nuimo->setLongPressTime(value.toInt()); + } + } } void DevicePluginSenic::onBatteryValueChanged(const uint &percentage) diff --git a/senic/devicepluginsenic.h b/senic/devicepluginsenic.h index 2302a555..5890f636 100644 --- a/senic/devicepluginsenic.h +++ b/senic/devicepluginsenic.h @@ -59,7 +59,7 @@ private slots: void onConnectedChanged(bool connected); void onBatteryValueChanged(const uint &percentage); void onButtonPressed(); - void onButtonReleased(); + void onButtonLongPressed(); void onSwipeDetected(const Nuimo::SwipeDirection &direction); void onRotationValueChanged(const uint &value); void onDeviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision); diff --git a/senic/devicepluginsenic.json b/senic/devicepluginsenic.json index f70fc8fa..cb078851 100644 --- a/senic/devicepluginsenic.json +++ b/senic/devicepluginsenic.json @@ -9,6 +9,13 @@ "displayName": "Automatically display symbols", "type": "bool", "defaultValue": true + }, + { + "id": "f9900dfe-310b-462b-b09d-a999df441075", + "name": "longPressTime", + "displayName": "Long press time", + "type": "int", + "defaultValue": 250 } ], "vendors": [ @@ -22,7 +29,7 @@ "name": "nuimo", "displayName": "Nuimo", "createMethods": ["discovery"], - "interfaces": ["simplemultibutton", "connectable", "batterylevel"], + "interfaces": ["simplemultibutton", "longpressbutton", "connectable", "batterylevel"], "paramTypes": [ { "id": "71553f6a-2ed4-4896-bb7b-52e7dca948b2", @@ -141,6 +148,11 @@ "allowedValues": ["•", "←", "↑", "→", "↓"] } ] + }, + { + "id": "a2f4add5-f76a-4dca-ae68-4107533bee0e", + "name": "longPressed", + "displayName": "Button long pressed" } ] } diff --git a/senic/nuimo.cpp b/senic/nuimo.cpp index 6c2dabda..9501471d 100644 --- a/senic/nuimo.cpp +++ b/senic/nuimo.cpp @@ -41,6 +41,12 @@ Nuimo::Nuimo(BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent) : { connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::connectedChanged, this, &Nuimo::onConnectedChanged); connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::servicesDiscoveryFinished, this, &Nuimo::onServiceDiscoveryFinished); + + if (!m_longPressTimer) { + m_longPressTimer = new QTimer(this); + m_longPressTimer->setSingleShot(true); + } + connect(m_longPressTimer, &QTimer::timeout, this, &Nuimo::onLongPressTimer); } @@ -210,6 +216,19 @@ void Nuimo::showImage(const Nuimo::MatrixType &matrixType) " "); time = 5; break; + case MatrixTypeFilledCircle: + matrix = QByteArray( + " " + " " + " *** " + " ***** " + " ***** " + " ***** " + " *** " + " " + " "); + time = 5; + break; case MatrixTypeLight: matrix = QByteArray( " " @@ -228,6 +247,11 @@ void Nuimo::showImage(const Nuimo::MatrixType &matrixType) showMatrix(matrix, time); } +void Nuimo::setLongPressTime(int milliSeconds) +{ + m_longPressTime = milliSeconds; +} + void Nuimo::showMatrix(const QByteArray &matrix, const int &seconds) { if (!m_ledMatrixService) @@ -264,11 +288,22 @@ void Nuimo::printService(QLowEnergyService *service) } } +void Nuimo::onLongPressTimer() +{ + if (m_buttonPressed) { + emit buttonLongPressed(); + } else { + emit buttonPressed(); + } +} + void Nuimo::onConnectedChanged(const bool &connected) { qCDebug(dcSenic()) << m_bluetoothDevice->name() << m_bluetoothDevice->address().toString() << (connected ? "connected" : "disconnected"); + + m_longPressTimer->stop(); emit connectedChanged(connected); if (!connected) { @@ -468,12 +503,15 @@ void Nuimo::onInputServiceStateChanged(const QLowEnergyService::ServiceState &st void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) { if (characteristic.uuid() == m_inputButtonCharacteristic.uuid()) { - bool pressed = (bool)value.toHex().toUInt(nullptr, 16); - qCDebug(dcSenic()) << "Button:" << (pressed ? "pressed": "released"); - if (pressed) { - emit buttonPressed(); + m_buttonPressed = (bool)value.toHex().toUInt(nullptr, 16); + qCDebug(dcSenic()) << "Button:" << (m_buttonPressed ? "pressed": "released"); + if (m_buttonPressed) { + //emit buttonPressed(); + m_longPressTimer->start(m_longPressTime); } else { - emit buttonReleased(); + if (!m_longPressTimer->isActive()) + m_longPressTimer->stop(); + emit buttonLongPressed(); } return; } diff --git a/senic/nuimo.h b/senic/nuimo.h index 8bec379e..b51f04f9 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -24,6 +24,7 @@ #define NUIMO_H #include +#include #include #include "typeutils.h" @@ -53,14 +54,15 @@ public: MatrixTypeNext, MatrixTypePrevious, MatrixTypeCircle, + MatrixTypeFilledCircle, MatrixTypeLight }; explicit Nuimo(BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent = nullptr); BluetoothLowEnergyDevice *bluetoothDevice(); - void showImage(const MatrixType &matrixType); + void setLongPressTime(int milliSeconds); private: BluetoothLowEnergyDevice *m_bluetoothDevice = nullptr; @@ -78,14 +80,18 @@ private: QLowEnergyCharacteristic m_inputRotationCharacteristic; uint m_rotationValue; + QTimer *m_longPressTimer = nullptr; + int m_longPressTime = 250; + bool m_buttonPressed = false; void showMatrix(const QByteArray &matrix, const int &seconds); void printService(QLowEnergyService *service); + void onLongPressTimer(); signals: void connectedChanged(bool connected); void buttonPressed(); - void buttonReleased(); + void buttonLongPressed(); void batteryValueChanged(const uint &percentage); void swipeDetected(const SwipeDirection &direction); void rotationValueChanged(const uint &value); From 575203aeaf9fd284c3b25ae2d5f1b83397c7d61d Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 17:19:48 +0200 Subject: [PATCH 08/12] fix long pressed event --- senic/devicepluginsenic.cpp | 1 + senic/nuimo.cpp | 19 ++++++++----------- senic/nuimo.h | 1 - 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index c8cfa066..da922927 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -80,6 +80,7 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) connect(nuimo, &Nuimo::rotationValueChanged, this, &DevicePluginSenic::onRotationValueChanged); connect(nuimo, &Nuimo::connectedChanged, this, &DevicePluginSenic::onConnectedChanged); connect(nuimo, &Nuimo::deviceInformationChanged, this, &DevicePluginSenic::onDeviceInformationChanged); + connect(nuimo, &Nuimo::batteryValueChanged, this, &DevicePluginSenic::onBatteryValueChanged); m_nuimos.insert(nuimo, device); nuimo->bluetoothDevice()->connectDevice(); diff --git a/senic/nuimo.cpp b/senic/nuimo.cpp index 9501471d..818e2d34 100644 --- a/senic/nuimo.cpp +++ b/senic/nuimo.cpp @@ -290,11 +290,7 @@ void Nuimo::printService(QLowEnergyService *service) void Nuimo::onLongPressTimer() { - if (m_buttonPressed) { - emit buttonLongPressed(); - } else { - emit buttonPressed(); - } + emit buttonLongPressed(); } @@ -503,15 +499,16 @@ void Nuimo::onInputServiceStateChanged(const QLowEnergyService::ServiceState &st void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) { if (characteristic.uuid() == m_inputButtonCharacteristic.uuid()) { - m_buttonPressed = (bool)value.toHex().toUInt(nullptr, 16); - qCDebug(dcSenic()) << "Button:" << (m_buttonPressed ? "pressed": "released"); - if (m_buttonPressed) { - //emit buttonPressed(); + bool pressed = (bool)value.toHex().toUInt(nullptr, 16); + qCDebug(dcSenic()) << "Button:" << (pressed ? "pressed": "released"); + if (pressed) { m_longPressTimer->start(m_longPressTime); } else { - if (!m_longPressTimer->isActive()) + if (m_longPressTimer->isActive()) { m_longPressTimer->stop(); - emit buttonLongPressed(); + emit buttonPressed(); + } + // else the time run out and has the long pressed event emittted } return; } diff --git a/senic/nuimo.h b/senic/nuimo.h index b51f04f9..71a040d0 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -82,7 +82,6 @@ private: uint m_rotationValue; QTimer *m_longPressTimer = nullptr; int m_longPressTime = 250; - bool m_buttonPressed = false; void showMatrix(const QByteArray &matrix, const int &seconds); void printService(QLowEnergyService *service); From 49dd8b067089c48c1364d6f6851fdfdaab78e0b4 Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 17:28:48 +0200 Subject: [PATCH 09/12] extend default long press timeout --- senic/devicepluginsenic.cpp | 2 +- senic/devicepluginsenic.json | 2 +- senic/nuimo.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index da922927..7d4d95cc 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -293,7 +293,7 @@ void DevicePluginSenic::onPluginConfigurationChanged(const ParamTypeId ¶mTyp } if (paramTypeId == senicPluginLongPressTimeParamTypeId) { - qCDebug(dcSenic()) << "Long press time" << value.toUInt(); + qCDebug(dcSenic()) << "Long press time" << value.toInt(); foreach(Nuimo *nuimo, m_nuimos.keys()) { nuimo->setLongPressTime(value.toInt()); } diff --git a/senic/devicepluginsenic.json b/senic/devicepluginsenic.json index cb078851..6dbde0a9 100644 --- a/senic/devicepluginsenic.json +++ b/senic/devicepluginsenic.json @@ -15,7 +15,7 @@ "name": "longPressTime", "displayName": "Long press time", "type": "int", - "defaultValue": 250 + "defaultValue": 500 } ], "vendors": [ diff --git a/senic/nuimo.h b/senic/nuimo.h index 71a040d0..e6b90c3d 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -81,7 +81,7 @@ private: uint m_rotationValue; QTimer *m_longPressTimer = nullptr; - int m_longPressTime = 250; + int m_longPressTime = 500; void showMatrix(const QByteArray &matrix, const int &seconds); void printService(QLowEnergyService *service); From 82a8f9effb8b42fc1a0c51fbb5d1af8c4f098fcb Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 17:39:53 +0200 Subject: [PATCH 10/12] bluetooth connection fix --- senic/devicepluginsenic.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index 7d4d95cc..8ab1e4b9 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -142,7 +142,9 @@ void DevicePluginSenic::deviceRemoved(Device *device) Nuimo *nuimo = m_nuimos.key(device); m_nuimos.take(nuimo); - delete nuimo; + + hardwareManager()->bluetoothLowEnergyManager()->unregisterDevice(nuimo->bluetoothDevice()); + nuimo->deleteLater(); if (myDevices().isEmpty()) { hardwareManager()->pluginTimerManager()->unregisterTimer(m_reconnectTimer); From e49607aa13a1cdc0409cbc2cab0072b3a4e92fc5 Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 17:51:15 +0200 Subject: [PATCH 11/12] made device setup async --- senic/devicepluginsenic.cpp | 13 ++++++++++++- senic/devicepluginsenic.h | 1 + senic/nuimo.cpp | 2 +- senic/nuimo.h | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index 8ab1e4b9..233a5e50 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -74,6 +74,7 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) Nuimo *nuimo = new Nuimo(bluetoothDevice, this); nuimo->setLongPressTime(configValue(senicPluginLongPressTimeParamTypeId).toInt()); + connect(nuimo, &Nuimo::deviceInitializationFinished, this, &DevicePluginSenic::onDeviceInitializationFinished); connect(nuimo, &Nuimo::buttonPressed, this, &DevicePluginSenic::onButtonPressed); connect(nuimo, &Nuimo::buttonLongPressed, this, &DevicePluginSenic::onButtonLongPressed); connect(nuimo, &Nuimo::swipeDetected, this, &DevicePluginSenic::onSwipeDetected); @@ -85,7 +86,7 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) m_nuimos.insert(nuimo, device); nuimo->bluetoothDevice()->connectDevice(); - return Device::DeviceSetupStatusSuccess; + return Device::DeviceSetupStatusAsync; } @@ -194,6 +195,16 @@ void DevicePluginSenic::onBluetoothDiscoveryFinished() emit devicesDiscovered(nuimoDeviceClassId, deviceDescriptors); } +void DevicePluginSenic::onDeviceInitializationFinished() +{ + Nuimo *nuimo = static_cast(sender()); + Device *device = m_nuimos.value(nuimo); + if (!device->setupComplete()) { + emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess); + } + +} + void DevicePluginSenic::onConnectedChanged(bool connected) { Nuimo *nuimo = static_cast(sender()); diff --git a/senic/devicepluginsenic.h b/senic/devicepluginsenic.h index 5890f636..f4d6feb0 100644 --- a/senic/devicepluginsenic.h +++ b/senic/devicepluginsenic.h @@ -56,6 +56,7 @@ private slots: void onReconnectTimeout(); void onBluetoothDiscoveryFinished(); + void onDeviceInitializationFinished(); void onConnectedChanged(bool connected); void onBatteryValueChanged(const uint &percentage); void onButtonPressed(); diff --git a/senic/nuimo.cpp b/senic/nuimo.cpp index 818e2d34..9105e918 100644 --- a/senic/nuimo.cpp +++ b/senic/nuimo.cpp @@ -402,7 +402,7 @@ void Nuimo::onServiceDiscoveryFinished() m_ledMatrixService->discoverDetails(); } } - + emit deviceInitializationFinished(); } void Nuimo::onDeviceInfoServiceStateChanged(const QLowEnergyService::ServiceState &state) diff --git a/senic/nuimo.h b/senic/nuimo.h index e6b90c3d..b863e6ac 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -95,6 +95,7 @@ signals: void swipeDetected(const SwipeDirection &direction); void rotationValueChanged(const uint &value); void deviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision); + void deviceInitializationFinished(); private slots: void onConnectedChanged(const bool &connected); From d710dc9e2c787c92a2e4579fdc3f11f0016e06aa Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 18:07:40 +0200 Subject: [PATCH 12/12] extended long press time --- senic/devicepluginsenic.json | 2 +- senic/nuimo.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/senic/devicepluginsenic.json b/senic/devicepluginsenic.json index 6dbde0a9..96791b49 100644 --- a/senic/devicepluginsenic.json +++ b/senic/devicepluginsenic.json @@ -15,7 +15,7 @@ "name": "longPressTime", "displayName": "Long press time", "type": "int", - "defaultValue": 500 + "defaultValue": 2000 } ], "vendors": [ diff --git a/senic/nuimo.h b/senic/nuimo.h index b863e6ac..0b48fe70 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -81,7 +81,7 @@ private: uint m_rotationValue; QTimer *m_longPressTimer = nullptr; - int m_longPressTime = 500; + int m_longPressTime = 2000; //default value 2 seconds void showMatrix(const QByteArray &matrix, const int &seconds); void printService(QLowEnergyService *service);