add plugin files
This commit is contained in:
parent
699495dcc0
commit
7e152b7a09
182
plugins/deviceplugins/senic/devicepluginsenic.cpp
Normal file
182
plugins/deviceplugins/senic/devicepluginsenic.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2016 Simon Stürz <simon.stuerz@guh.guru> *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
* Guh is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, version 2 of the License. *
|
||||
* *
|
||||
* Guh is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\page senic.html
|
||||
\title Senic - Nuimo
|
||||
\brief Plugin for Senic Nuimo.
|
||||
|
||||
\ingroup plugins
|
||||
\ingroup guh-plugins
|
||||
|
||||
|
||||
\chapter Plugin properties
|
||||
Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses}
|
||||
and \l{Vendor}{Vendors} of this \l{DevicePlugin}.
|
||||
|
||||
For more details how to read this JSON file please check out the documentation for \l{The plugin JSON File}.
|
||||
|
||||
\quotefile plugins/deviceplugins/senic/devicepluginsenic.json
|
||||
*/
|
||||
|
||||
#ifdef BLUETOOTH_LE
|
||||
|
||||
#include "devicepluginsenic.h"
|
||||
#include "plugin/device.h"
|
||||
#include "devicemanager.h"
|
||||
#include "plugininfo.h"
|
||||
|
||||
DevicePluginSenic::DevicePluginSenic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
Q_UNUSED(params)
|
||||
|
||||
if (deviceClassId != nuimoDeviceClassId)
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
|
||||
if (!discoverBluetooth())
|
||||
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
||||
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
||||
DeviceManager::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
|
||||
{
|
||||
QString name = device->paramValue("name").toString();
|
||||
QBluetoothAddress address = QBluetoothAddress(device->paramValue("mac address").toString());
|
||||
QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo(address, name, 0);
|
||||
|
||||
Nuimo *nuimo = new Nuimo(deviceInfo, QLowEnergyController::RandomAddress, this);
|
||||
connect(nuimo, &Nuimo::availableChanged, this, &DevicePluginSenic::connectionAvailableChanged);
|
||||
connect(nuimo, &Nuimo::batteryValueChaged, this, &DevicePluginSenic::onBatteryValueChanged);
|
||||
connect(nuimo, &Nuimo::buttonPressed, this, &DevicePluginSenic::onButtonPressed);
|
||||
connect(nuimo, &Nuimo::buttonReleased, this, &DevicePluginSenic::onButtonReleased);
|
||||
|
||||
m_nuimos.insert(nuimo, device);
|
||||
|
||||
nuimo->connectDevice();
|
||||
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
DeviceManager::HardwareResources DevicePluginSenic::requiredHardware() const
|
||||
{
|
||||
return DeviceManager::HardwareResourceBluetoothLE;
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DevicePluginSenic::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
QPointer<Nuimo> nuimo = m_nuimos.key(device);
|
||||
if (nuimo.isNull())
|
||||
return DeviceManager::DeviceErrorHardwareFailure;
|
||||
|
||||
// reconnect action does not need available true
|
||||
if (action.actionTypeId() == connectActionTypeId) {
|
||||
nuimo->reconnectDevice();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
if (action.actionTypeId() == disconnectActionTypeId) {
|
||||
nuimo->disconnectDevice();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
if (action.actionTypeId() == showLogoActionTypeId) {
|
||||
nuimo->showGuhLogo();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
|
||||
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
void DevicePluginSenic::bluetoothDiscoveryFinished(const QList<QBluetoothDeviceInfo> &deviceInfos)
|
||||
{
|
||||
QList<DeviceDescriptor> deviceDescriptors;
|
||||
foreach (QBluetoothDeviceInfo deviceInfo, deviceInfos) {
|
||||
if (deviceInfo.name().contains("Nuimo")) {
|
||||
if (!verifyExistingDevices(deviceInfo)) {
|
||||
DeviceDescriptor descriptor(nuimoDeviceClassId, "Nuimo", deviceInfo.address().toString());
|
||||
ParamList params;
|
||||
params.append(Param("name", deviceInfo.name()));
|
||||
params.append(Param("mac address", deviceInfo.address().toString()));
|
||||
descriptor.setParams(params);
|
||||
deviceDescriptors.append(descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit devicesDiscovered(nuimoDeviceClassId, deviceDescriptors);
|
||||
}
|
||||
|
||||
void DevicePluginSenic::deviceRemoved(Device *device)
|
||||
{
|
||||
if (!m_nuimos.values().contains(device))
|
||||
return;
|
||||
|
||||
Nuimo *nuimo = m_nuimos.key(device);
|
||||
m_nuimos.take(nuimo);
|
||||
delete nuimo;
|
||||
}
|
||||
|
||||
bool DevicePluginSenic::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo)
|
||||
{
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->paramValue("mac address").toString() == deviceInfo.address().toString())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DevicePluginSenic::connectionAvailableChanged()
|
||||
{
|
||||
Nuimo *nuimo = static_cast<Nuimo *>(sender());
|
||||
Device *device = m_nuimos.value(nuimo);
|
||||
device->setStateValue(availableStateTypeId, nuimo->isAvailable());
|
||||
}
|
||||
|
||||
void DevicePluginSenic::onBatteryValueChanged(const uint &percentage)
|
||||
{
|
||||
Nuimo *nuimo = static_cast<Nuimo *>(sender());
|
||||
Device *device = m_nuimos.value(nuimo);
|
||||
device->setStateValue(batteryStateTypeId, percentage);
|
||||
}
|
||||
|
||||
void DevicePluginSenic::onButtonPressed()
|
||||
{
|
||||
Nuimo *nuimo = static_cast<Nuimo *>(sender());
|
||||
Device *device = m_nuimos.value(nuimo);
|
||||
emitEvent(Event(clickedEventTypeId, device->id()));
|
||||
}
|
||||
|
||||
void DevicePluginSenic::onButtonReleased()
|
||||
{
|
||||
// TODO: user timer for detekt long pressed (if needed)
|
||||
}
|
||||
|
||||
|
||||
#endif // BLUETOOTH_LE
|
||||
|
||||
|
||||
63
plugins/deviceplugins/senic/devicepluginsenic.h
Normal file
63
plugins/deviceplugins/senic/devicepluginsenic.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2016 Simon Stürz <simon.stuerz@guh.guru> *
|
||||
* *
|
||||
* This file is part of guh. *
|
||||
* *
|
||||
* Guh is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, version 2 of the License. *
|
||||
* *
|
||||
* Guh is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef DEVICEPLUGINELGATO_H
|
||||
#define DEVICEPLUGINELGATO_H
|
||||
|
||||
#ifdef BLUETOOTH_LE
|
||||
|
||||
#include "plugin/deviceplugin.h"
|
||||
#include "bluetooth/bluetoothlowenergydevice.h"
|
||||
|
||||
#include "nuimo.h"
|
||||
|
||||
class DevicePluginSenic : public DevicePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "devicepluginsenic.json")
|
||||
Q_INTERFACES(DevicePlugin)
|
||||
|
||||
public:
|
||||
explicit DevicePluginSenic();
|
||||
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||
DeviceManager::HardwareResources requiredHardware() const override;
|
||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
void bluetoothDiscoveryFinished(const QList<QBluetoothDeviceInfo> &deviceInfos);
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
||||
private:
|
||||
QHash<Nuimo *, Device *> m_nuimos;
|
||||
bool verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo);
|
||||
|
||||
private slots:
|
||||
void connectionAvailableChanged();
|
||||
void onBatteryValueChanged(const uint &percentage);
|
||||
void onButtonPressed();
|
||||
void onButtonReleased();
|
||||
|
||||
};
|
||||
|
||||
#endif // BLUETOOTH_LE
|
||||
|
||||
#endif // DEVICEPLUGINELGATO_H
|
||||
99
plugins/deviceplugins/senic/devicepluginsenic.json
Normal file
99
plugins/deviceplugins/senic/devicepluginsenic.json
Normal file
@ -0,0 +1,99 @@
|
||||
{
|
||||
"name": "Senic",
|
||||
"id": "413e9d77-335f-4ecf-abbc-8f2a8a399c39",
|
||||
"idName": "Senic",
|
||||
"vendors": [
|
||||
{
|
||||
"name": "Senic",
|
||||
"id": "8e6cae9c-706b-49e5-ae86-da52a20dd336",
|
||||
"deviceClasses": [
|
||||
{
|
||||
"deviceClassId": "315ece51-053e-49f9-831f-b09f9f27fb9f",
|
||||
"idName": "nuimo",
|
||||
"name": "Nuimo",
|
||||
"deviceIcon": "Switch",
|
||||
"basicTags": [
|
||||
"Device",
|
||||
"Sensor"
|
||||
],
|
||||
"createMethods": ["discovery"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "QString",
|
||||
"index": 0,
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"name": "mac address",
|
||||
"type": "QString",
|
||||
"index": 1,
|
||||
"inputType": "MacAddress"
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
{
|
||||
"id": "5286976a-f5dc-4662-872a-438ac5d491cb",
|
||||
"idName": "available",
|
||||
"name": "available",
|
||||
"index": 0,
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"id": "b5ee2465-7fa1-450b-8073-f115537d3409",
|
||||
"idName": "battery",
|
||||
"name": "battery",
|
||||
"index": 1,
|
||||
"type": "int",
|
||||
"minValue": 0,
|
||||
"maxValue": 100,
|
||||
"unit": "Percentage",
|
||||
"defaultValue": 0
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
{
|
||||
"id": "bb1c46fe-5dfb-4fa3-ad89-0ba576ac780e",
|
||||
"idName": "connect",
|
||||
"index": 0,
|
||||
"name": "connect"
|
||||
},
|
||||
{
|
||||
"id": "11bf3143-34f8-42ab-9750-073040c1a7fc",
|
||||
"idName": "disconnect",
|
||||
"index": 1,
|
||||
"name": "disconnect"
|
||||
},
|
||||
{
|
||||
"id": "d44ca5b7-f8d6-4413-9d2e-cef89282c039",
|
||||
"idName": "showLogo",
|
||||
"index": 2,
|
||||
"name": "show logo"
|
||||
}
|
||||
],
|
||||
"eventTypes": [
|
||||
{
|
||||
"id": "5b9e08e8-7a6c-4311-9db6-82547847708c",
|
||||
"idName": "clicked",
|
||||
"name": "clicked",
|
||||
"index": "0"
|
||||
},
|
||||
{
|
||||
"id": "2be36aa0-e2fe-4192-81c5-cf0bb7f08dd4",
|
||||
"idName": "swipeLeft",
|
||||
"name": "Swipe left",
|
||||
"index": "1"
|
||||
},
|
||||
{
|
||||
"id": "81fb61ab-6d3d-4c1b-85fe-3dbd5c8dead7",
|
||||
"idName": "swipeRight",
|
||||
"name": "Swipe right",
|
||||
"index": "2"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
13
plugins/deviceplugins/senic/senic.pro
Normal file
13
plugins/deviceplugins/senic/senic.pro
Normal file
@ -0,0 +1,13 @@
|
||||
include(../../plugins.pri)
|
||||
|
||||
TARGET = $$qtLibraryTarget(guh_devicepluginsenic)
|
||||
|
||||
SOURCES += \
|
||||
devicepluginsenic.cpp \
|
||||
nuimo.cpp
|
||||
|
||||
HEADERS += \
|
||||
devicepluginsenic.h \
|
||||
nuimo.h
|
||||
|
||||
|
||||
Reference in New Issue
Block a user