119 lines
5.2 KiB
C++
119 lines
5.2 KiB
C++
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
* *
|
|
* Copyright (C) 2015 Simon Stürz <simon.stuerz@guh.io> *
|
|
* *
|
|
* 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 *
|
|
* <http://www.gnu.org/licenses/>. *
|
|
* *
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
/*!
|
|
\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 <QDebug>
|
|
|
|
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;
|
|
}
|