From 6baa7584ad91b0633a889e93856dd265d84ad096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 7 Apr 2015 16:28:46 +0200 Subject: [PATCH] allow only one mood enabled (tune side) --- .../deviceplugins/tune/deviceplugintune.cpp | 33 ++++++++++++++----- plugins/deviceplugins/tune/deviceplugintune.h | 3 +- .../deviceplugins/tune/deviceplugintune.json | 9 +++-- plugins/deviceplugins/tune/tunemanager.cpp | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/plugins/deviceplugins/tune/deviceplugintune.cpp b/plugins/deviceplugins/tune/deviceplugintune.cpp index d26d9baf..9b15abdb 100644 --- a/plugins/deviceplugins/tune/deviceplugintune.cpp +++ b/plugins/deviceplugins/tune/deviceplugintune.cpp @@ -46,13 +46,13 @@ DeviceManager::DeviceSetupStatus DevicePluginTune::setupDevice(Device *device) { // tune - if (device->deviceClassId() == tuneDeviceClassId && !tuneAdded()) { + if (device->deviceClassId() == tuneDeviceClassId && !tuneAlreadyAdded()) { m_tuneDeviceId = device->id(); return DeviceManager::DeviceSetupStatusSuccess; } // mood - if ((device->deviceClassId() == moodDeviceClassId) && tuneAdded()) { + if ((device->deviceClassId() == moodDeviceClassId) && tuneAlreadyAdded()) { // check index position int position = device->paramValue("position").toInt(); @@ -143,7 +143,7 @@ bool DevicePluginTune::sync() QJsonDocument jsonDoc = QJsonDocument::fromVariant(message); QByteArray data = jsonDoc.toJson(QJsonDocument::Compact); - //qDebug() << jsonDoc.toJson(); + qDebug() << jsonDoc.toJson(); m_manager->sendData(data); return true; @@ -182,7 +182,7 @@ void DevicePluginTune::syncStates(Device *device) } -bool DevicePluginTune::tuneAdded() +bool DevicePluginTune::tuneAlreadyAdded() { foreach (Device *device, myDevices()) { if (device->deviceClassId() == tuneDeviceClassId) { @@ -203,10 +203,24 @@ void DevicePluginTune::tuneAutodetected() metaObject()->invokeMethod(this, "autoDevicesAppeared", Qt::QueuedConnection, Q_ARG(DeviceClassId, tuneDeviceClassId), Q_ARG(QList, descriptorList)); } +void DevicePluginTune::activateMood(Device *device) +{ + foreach (Device* d, myDevices()) { + if (d->deviceClassId() == moodDeviceClassId) { + if (d->id() == device->id()) { + d->setStateValue(activeStateTypeId, true); + } else { + d->setStateValue(activeStateTypeId, false); + } + } + } + sync(); +} + void DevicePluginTune::tuneConnectionStatusChanged(const bool &connected) { if (connected) { - if (!tuneAdded()) { + if (!tuneAlreadyAdded()) { tuneAutodetected(); } else { Device *device = deviceManager()->findConfiguredDevice(m_tuneDeviceId); @@ -241,9 +255,12 @@ void DevicePluginTune::tuneDataAvailable(const QByteArray &data) bool activeValue = states.value("active").toBool(); int value = states.value("value").toInt(); - // TODO: disable other mood befor enabling this one... - - device->setStateValue(activeStateTypeId, activeValue); + if (activeValue) { + // disable any active mood + activateMood(device); + } else { + device->setStateValue(activeStateTypeId, activeValue); + } device->setStateValue(valueStateTypeId, value); } } else if (message.contains("tune")) { diff --git a/plugins/deviceplugins/tune/deviceplugintune.h b/plugins/deviceplugins/tune/deviceplugintune.h index 3a721ef8..6157dd74 100644 --- a/plugins/deviceplugins/tune/deviceplugintune.h +++ b/plugins/deviceplugins/tune/deviceplugintune.h @@ -44,8 +44,9 @@ private: bool sync(); void syncStates(Device *device); - bool tuneAdded(); + bool tuneAlreadyAdded(); void tuneAutodetected(); + void activateMood(Device* device); private slots: void tuneConnectionStatusChanged(const bool &connected); diff --git a/plugins/deviceplugins/tune/deviceplugintune.json b/plugins/deviceplugins/tune/deviceplugintune.json index 7b23387b..c3008562 100644 --- a/plugins/deviceplugins/tune/deviceplugintune.json +++ b/plugins/deviceplugins/tune/deviceplugintune.json @@ -60,9 +60,9 @@ "idName": "value", "name": "value", "type": "int", - "minimumValue": 0, - "maximumValue": 100, - "defaultValue": 50, + "minValue": 0, + "maxValue": 100, + "defaultValue": 100, "writable": true } ] @@ -123,6 +123,9 @@ "idName": "brightness", "name": "brightness", "type": "int", + "minValue": 0, + "maxValue": 100, + "defaultValue": 100, "writable": true } ] diff --git a/plugins/deviceplugins/tune/tunemanager.cpp b/plugins/deviceplugins/tune/tunemanager.cpp index bd8a973d..aa3ae3b2 100644 --- a/plugins/deviceplugins/tune/tunemanager.cpp +++ b/plugins/deviceplugins/tune/tunemanager.cpp @@ -46,7 +46,7 @@ void TuneManager::tuneConnected() QTcpSocket *socket = m_server->nextPendingConnection(); if (m_tune) { - qWarning() << "--> ATTENTION: tune allready connected! connection refused."; + qWarning() << "--> ATTENTION: tune already connected! connection refused."; socket->disconnect(); delete socket; return;