From 12a0afd90caa0f38deb0a58ff20a164e3ed5ac53 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 11 Jul 2017 14:14:07 +0200 Subject: [PATCH] imported all internal guh plugins --- .../deviceplugingenericelements.cpp | 118 ++++++++++++++++++ genericelements/deviceplugingenericelements.h | 47 +++++++ .../deviceplugingenericelements.json | 109 ++++++++++++++++ genericelements/genericelements.pro | 15 +++ ...2161e-39b7-4416-8623-39e730721efb-de_DE.qm | Bin 0 -> 1086 bytes ...2161e-39b7-4416-8623-39e730721efb-en_US.qm | 1 + genericelements/translations/de_DE.ts | 91 ++++++++++++++ genericelements/translations/en_US.ts | 91 ++++++++++++++ plugins.pri | 61 +++++++++ 9 files changed, 533 insertions(+) create mode 100644 genericelements/deviceplugingenericelements.cpp create mode 100644 genericelements/deviceplugingenericelements.h create mode 100644 genericelements/deviceplugingenericelements.json create mode 100644 genericelements/genericelements.pro create mode 100644 genericelements/translations/6e22161e-39b7-4416-8623-39e730721efb-de_DE.qm create mode 100644 genericelements/translations/6e22161e-39b7-4416-8623-39e730721efb-en_US.qm create mode 100644 genericelements/translations/de_DE.ts create mode 100644 genericelements/translations/en_US.ts create mode 100644 plugins.pri diff --git a/genericelements/deviceplugingenericelements.cpp b/genericelements/deviceplugingenericelements.cpp new file mode 100644 index 0000000..988e33e --- /dev/null +++ b/genericelements/deviceplugingenericelements.cpp @@ -0,0 +1,118 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2015 Simon Stürz * + * * + * This file is part of guh. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/*! + \page genericelements.html + \title Generic elements + \brief Common elements to test the rule engine. + + \ingroup plugins + \ingroup guh-tests + + The generic elements plugin allows you create virtual buttons, which can be connected with a rule. This gives you + the possibility to execute multiple \l{Action}{Actions} with one signal. Without a rule this generic elements are + useless. + + \chapter Toggle Button + With the "Toggle Button" \l{DeviceClass} you can create a button with one \l{Action} \unicode{0x2192} toggle. In the \tt state \l{State} you can find out, + what happens if the button will be pressed. The states can be true or false. + + \chapter Button + With the "Button" \l{DeviceClass} you can create a button with one \l{Action} \unicode{0x2192} press. This button just creates one \l{Event}. + + \chapter ON/OFF Button + With the "ON/OFF Button" \l{DeviceClass} you create a button pair with the \l{Action}{Actions} \unicode{0x2192} ON and OFF. + + \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/genericelements/deviceplugingenericelements.json +*/ + + +#include "deviceplugingenericelements.h" +#include "devicemanager.h" +#include "plugininfo.h" + +#include + +DevicePluginGenericElements::DevicePluginGenericElements() +{ +} + +DeviceManager::HardwareResources DevicePluginGenericElements::requiredHardware() const +{ + return DeviceManager::HardwareResourceNone; +} + +DeviceManager::DeviceSetupStatus DevicePluginGenericElements::setupDevice(Device *device) +{ + // Toggle Button + if (device->deviceClassId() == toggleButtonDeviceClassId) { + return DeviceManager::DeviceSetupStatusSuccess; + } + // Button + if (device->deviceClassId() == buttonDeviceClassId) { + return DeviceManager::DeviceSetupStatusSuccess; + } + // ON/OFF Button + if (device->deviceClassId() == onOffButtonDeviceClassId) { + return DeviceManager::DeviceSetupStatusSuccess; + } + return DeviceManager::DeviceSetupStatusFailure; +} + +DeviceManager::DeviceError DevicePluginGenericElements::executeAction(Device *device, const Action &action) +{ + // Toggle Button + if (device->deviceClassId() == toggleButtonDeviceClassId ) { + if (action.actionTypeId() == stateActionTypeId) { + device->setStateValue(stateStateTypeId, !device->stateValue(stateStateTypeId).toBool()); + return DeviceManager::DeviceErrorNoError; + } + return DeviceManager::DeviceErrorActionTypeNotFound; + } + // Button + if (device->deviceClassId() == buttonDeviceClassId ) { + if (action.actionTypeId() == buttonPressActionTypeId) { + emit emitEvent(Event(buttonPressedEventTypeId, device->id())); + return DeviceManager::DeviceErrorNoError; + } + return DeviceManager::DeviceErrorActionTypeNotFound; + } + // ON/OFF Button + if (device->deviceClassId() == onOffButtonDeviceClassId ) { + if (action.actionTypeId() == onOffButtonOnActionTypeId) { + emit emitEvent(Event(onOffButtonOnEventTypeId, device->id())); + return DeviceManager::DeviceErrorNoError; + } + if (action.actionTypeId() == onOffButtonOffActionTypeId) { + emit emitEvent(Event(onOffButtonOffEventTypeId, device->id())); + return DeviceManager::DeviceErrorNoError; + } + return DeviceManager::DeviceErrorActionTypeNotFound; + } + return DeviceManager::DeviceErrorDeviceClassNotFound; +} diff --git a/genericelements/deviceplugingenericelements.h b/genericelements/deviceplugingenericelements.h new file mode 100644 index 0000000..1e9555d --- /dev/null +++ b/genericelements/deviceplugingenericelements.h @@ -0,0 +1,47 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2015 Simon Stürz * + * * + * This file is part of guh. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICEPLUGINGENERICELEMENTS_H +#define DEVICEPLUGINGENERICELEMENTS_H + +#include "plugin/deviceplugin.h" + +class DevicePluginGenericElements : public DevicePlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "deviceplugingenericelements.json") + Q_INTERFACES(DevicePlugin) + +public: + explicit DevicePluginGenericElements(); + + DeviceManager::HardwareResources requiredHardware() const override; + DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; + + +public slots: + DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; + +}; + +#endif // DEVICEPLUGINGENERICELEMENTS_H diff --git a/genericelements/deviceplugingenericelements.json b/genericelements/deviceplugingenericelements.json new file mode 100644 index 0000000..c39dd49 --- /dev/null +++ b/genericelements/deviceplugingenericelements.json @@ -0,0 +1,109 @@ + { + "name": "Generic Elements", + "idName": "GenericElements", + "id": "6e22161e-39b7-4416-8623-39e730721efb", + "vendors": [ + { + "name": "guh", + "idName": "guh", + "id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6", + "deviceClasses": [ + { + "id": "c0f511f9-70f5-499b-bd70-2c0e9ddd68c4", + "idName": "toggleButton", + "name": "Toggle Button", + "deviceIcon": "Switch", + "primaryActionTypeId": "b5e90567-54aa-49bd-a78a-3c19fb38aaf5", + "basicTags": [ + "Device", + "Actuator" + ], + "createMethods": ["user"], + "paramTypes": [ ], + "stateTypes": [ + { + "id": "b5e90567-54aa-49bd-a78a-3c19fb38aaf5", + "idName": "state", + "name": "state", + "eventTypeName": "state changed", + "actionTypeName": "Set state", + "index": 0, + "type": "bool", + "defaultValue": false, + "writable": true + } + ] + }, + { + "id": "820b2f2d-0d92-48c8-8fd4-f94ce8fc4103", + "idName": "button", + "name": "Button", + "deviceIcon": "Switch", + "primaryActionTypeId": "01f38af1-b2ab-4ec3-844e-ef52f0f229a9", + "basicTags": [ + "Device", + "Actuator" + ], + "createMethods": ["user"], + "paramTypes": [ ], + "actionTypes": [ + { + "id": "01f38af1-b2ab-4ec3-844e-ef52f0f229a9", + "idName": "buttonPress", + "index": 0, + "name": "press" + } + ], + "eventTypes": [ + { + "id": "effdbc2d-e467-4b0b-80a9-9dda251bfa5c", + "idName": "buttonPressed", + "index": 0, + "name": "button pressed" + } + ] + }, + { + "id": "430d188c-476d-4825-a9bd-86dfa3094b56", + "idName": "onOffButton", + "name": "ON/OFF Button", + "deviceIcon": "Switch", + "basicTags": [ + "Device", + "Actuator" + ], + "createMethods": ["user"], + "paramTypes": [ ], + "actionTypes": [ + { + "id": "892596d2-0863-4807-97da-469b9f7003f2", + "idName": "onOffButtonOn", + "index": 0, + "name": "press ON" + }, + { + "id": "a8d64050-0b58-4ccf-b052-77ce2b7368ad", + "idName": "onOffButtonOff", + "index": 1, + "name": "press OFF" + } + ], + "eventTypes": [ + { + "id": "4eeba6a2-e4c7-4a2e-8360-2797d98114e6", + "idName": "onOffButtonOn", + "index": 0, + "name": "ON pressed" + }, + { + "id": "b636c5f3-2eb0-4682-96d4-88a4aa9d2c12", + "idName": "onOffButtonOff", + "index": 1, + "name": "OFF pressed" + } + ] + } + ] + } + ] +} diff --git a/genericelements/genericelements.pro b/genericelements/genericelements.pro new file mode 100644 index 0000000..9fa63c2 --- /dev/null +++ b/genericelements/genericelements.pro @@ -0,0 +1,15 @@ +TRANSLATIONS = translations/en_US.ts \ + translations/de_DE.ts + +# Note: include after the TRANSLATIONS definition +include(../plugins.pri) + +TARGET = $$qtLibraryTarget(guh_deviceplugingenericelements) + +SOURCES += \ + deviceplugingenericelements.cpp + +HEADERS += \ + deviceplugingenericelements.h + + diff --git a/genericelements/translations/6e22161e-39b7-4416-8623-39e730721efb-de_DE.qm b/genericelements/translations/6e22161e-39b7-4416-8623-39e730721efb-de_DE.qm new file mode 100644 index 0000000000000000000000000000000000000000..4d2118724d08fcb7e08253d93f21a744c79cbb87 GIT binary patch literal 1086 zcmcE7ks@*G{hX<16=n7(EZlq7iGhKkfPo=z2Ll6>8$)@|Vjx}2P_<$y0|T=rLq}sD z0|TQpbHJ-5KzCck@XUTRThvTIIiZfaghF(XKq8iPAfeI7^;LncsnGD8NCt-#>QkOQQ1!E!(o z;pPcI4N-uZg41LP21kZcpot0$=|EFbfad=Jnx4&20ym4>-_1>-peVJtI5h>QF=9Yt z^6(hKlAoTQlS;@va>$zT1QTBpI2{lSDmI{_N*OZX zzF|%;&A{moJ_Z+fv;q?mToWreQgLb%LD8lFjFwP_V7O*Zux15dT;Mc72*UtBxONVx yc0ZiDd9X$sEB+{xL)HWh=O@5~nF34)MM!Cy7i^3|az + + + + GenericElements + + + Generic Elements + The name of the plugin Generic Elements (6e22161e-39b7-4416-8623-39e730721efb) + Generische Elemente + + + + guh + The name of the vendor (2062d64d-3232-433c-88bc-0d33c0ba2ba6) + guh + + + + Toggle Button + The name of the DeviceClass (c0f511f9-70f5-499b-bd70-2c0e9ddd68c4) + Toggle Taster + + + + state changed + The name of the autocreated EventType (b5e90567-54aa-49bd-a78a-3c19fb38aaf5) + Status geändert + + + + state + The name of the ParamType of StateType (b5e90567-54aa-49bd-a78a-3c19fb38aaf5) of DeviceClass Toggle Button + Status + + + + Set state + The name of the autocreated ActionType (b5e90567-54aa-49bd-a78a-3c19fb38aaf5) + Setze Status + + + + Button + The name of the DeviceClass (820b2f2d-0d92-48c8-8fd4-f94ce8fc4103) + Taster + + + + press + The name of the ActionType 01f38af1-b2ab-4ec3-844e-ef52f0f229a9 of deviceClass Button + Drücken + + + + button pressed + The name of the EventType effdbc2d-e467-4b0b-80a9-9dda251bfa5c of deviceClass Button + Taster gedrückt + + + + ON/OFF Button + The name of the DeviceClass (430d188c-476d-4825-a9bd-86dfa3094b56) + An/Aus Taster + + + + press ON + The name of the ActionType 892596d2-0863-4807-97da-469b9f7003f2 of deviceClass ON/OFF Button + Drücke AN + + + + press OFF + The name of the ActionType a8d64050-0b58-4ccf-b052-77ce2b7368ad of deviceClass ON/OFF Button + Drücke AUS + + + + ON pressed + The name of the EventType 4eeba6a2-e4c7-4a2e-8360-2797d98114e6 of deviceClass ON/OFF Button + An gedrückt + + + + OFF pressed + The name of the EventType b636c5f3-2eb0-4682-96d4-88a4aa9d2c12 of deviceClass ON/OFF Button + Aus gedrückt + + + diff --git a/genericelements/translations/en_US.ts b/genericelements/translations/en_US.ts new file mode 100644 index 0000000..0a8c935 --- /dev/null +++ b/genericelements/translations/en_US.ts @@ -0,0 +1,91 @@ + + + + + GenericElements + + + Generic Elements + The name of the plugin Generic Elements (6e22161e-39b7-4416-8623-39e730721efb) + + + + + guh + The name of the vendor (2062d64d-3232-433c-88bc-0d33c0ba2ba6) + + + + + Toggle Button + The name of the DeviceClass (c0f511f9-70f5-499b-bd70-2c0e9ddd68c4) + + + + + state changed + The name of the autocreated EventType (b5e90567-54aa-49bd-a78a-3c19fb38aaf5) + + + + + state + The name of the ParamType of StateType (b5e90567-54aa-49bd-a78a-3c19fb38aaf5) of DeviceClass Toggle Button + + + + + Set state + The name of the autocreated ActionType (b5e90567-54aa-49bd-a78a-3c19fb38aaf5) + + + + + Button + The name of the DeviceClass (820b2f2d-0d92-48c8-8fd4-f94ce8fc4103) + + + + + press + The name of the ActionType 01f38af1-b2ab-4ec3-844e-ef52f0f229a9 of deviceClass Button + + + + + button pressed + The name of the EventType effdbc2d-e467-4b0b-80a9-9dda251bfa5c of deviceClass Button + + + + + ON/OFF Button + The name of the DeviceClass (430d188c-476d-4825-a9bd-86dfa3094b56) + + + + + press ON + The name of the ActionType 892596d2-0863-4807-97da-469b9f7003f2 of deviceClass ON/OFF Button + + + + + press OFF + The name of the ActionType a8d64050-0b58-4ccf-b052-77ce2b7368ad of deviceClass ON/OFF Button + + + + + ON pressed + The name of the EventType 4eeba6a2-e4c7-4a2e-8360-2797d98114e6 of deviceClass ON/OFF Button + + + + + OFF pressed + The name of the EventType b636c5f3-2eb0-4682-96d4-88a4aa9d2c12 of deviceClass ON/OFF Button + + + + diff --git a/plugins.pri b/plugins.pri new file mode 100644 index 0000000..331a385 --- /dev/null +++ b/plugins.pri @@ -0,0 +1,61 @@ +TEMPLATE = lib +CONFIG += plugin + +QT += network bluetooth + +QMAKE_CXXFLAGS += -Werror -std=c++11 -g +QMAKE_LFLAGS += -std=c++11 + +INCLUDEPATH += /usr/include/guh +LIBS += -lguh + +PLUGIN_PATH=/usr/lib/$$system('dpkg-architecture -q DEB_HOST_MULTIARCH')/guh/plugins/ + +# Check for Bluetoot LE support (Qt >= 5.4) +equals(QT_MAJOR_VERSION, 5):greaterThan(QT_MINOR_VERSION, 3) { + DEFINES += BLUETOOTH_LE +} + +# Check if this is a snap build +snappy{ + INCLUDEPATH+=$$(SNAPCRAFT_STAGE)/usr/include/guh +} + +# Create plugininfo file +JSONFILES = deviceplugin"$$TARGET".json +plugininfo.target = plugininfo.h +plugininfo.output = plugininfo.h +plugininfo.CONFIG = no_link +plugininfo.input = JSONFILES +plugininfo.commands = touch ${QMAKE_FILE_OUT}; guh-generateplugininfo \ + --filetype i \ + --jsonfile ${QMAKE_FILE_NAME} \ + --output ${QMAKE_FILE_OUT} \ + --builddir $$OUT_PWD \ + --translations $$TRANSLATIONS; \ + rsync -a "$$OUT_PWD"/translations/*.qm $$shadowed($$PWD)/translations/; +PRE_TARGETDEPS += compiler_plugininfo_make_all +QMAKE_EXTRA_COMPILERS += plugininfo + +externplugininfo.target = extern-plugininfo.h +externplugininfo.output = extern-plugininfo.h +externplugininfo.CONFIG = no_link +externplugininfo.input = JSONFILES +externplugininfo.commands = touch ${QMAKE_FILE_OUT}; guh-generateplugininfo \ + --filetype e \ + --jsonfile ${QMAKE_FILE_NAME} \ + --output ${QMAKE_FILE_OUT} \ + --builddir $$OUT_PWD \ + --translations $$TRANSLATIONS; +PRE_TARGETDEPS += compiler_externplugininfo_make_all +QMAKE_EXTRA_COMPILERS += externplugininfo + + +# Install translation files +translations.path = /usr/share/guh/translations +translations.files = $$[QT_SOURCE_TREE]/translations/*.qm + +# Install plugin +target.path = $$PLUGIN_PATH +INSTALLS += target translations +