first version of leynew plugin, rf part not working yet

This commit is contained in:
Simon Stürz 2015-02-11 15:15:17 +01:00 committed by Michael Zanetti
parent 1aa8e0a92f
commit a4b51ccdcc
7 changed files with 322 additions and 1 deletions

View File

@ -13,3 +13,5 @@ usr/lib/guh/plugins/libguh_devicepluginwifidetector.so
usr/lib/guh/plugins/libguh_deviceplugindatetime.so
usr/lib/guh/plugins/libguh_deviceplugingenericelements.so
usr/lib/guh/plugins/libguh_deviceplugincommandlauncher.so
usr/lib/guh/plugins/libguh_devicepluginleynew.so

View File

@ -64,7 +64,7 @@ bool Radio433BrennenstuhlGateway::sendData(int delay, QList<int> rawData)
* ; | end of command
*/
message.append("TXP:0,0,10,0," + QString::number(delay) + "," + QString::number(rawData.count()/2) + "," + data + ";");
message.append("TXP:0,0,20,0," + QString::number(delay) + "," + QString::number(rawData.count()/2) + "," + data + ";");
if (m_gateway->writeDatagram(message, m_gatewayAddress, m_port) > 0) {
m_available = true;

View File

@ -13,6 +13,7 @@ SUBDIRS += elro \
datetime \
genericelements \
commandlauncher \
leynew \

View File

@ -0,0 +1,138 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 leynew.html
\title Leynew
\ingroup plugins
\ingroup rf433
This plugin allows to controll RF 433 MHz actors an receive remote signals from \l{http://www.leynew.com/en/}{Leynew}
devices.
Currently only following device is supported:
\l{http://www.leynew.com/en/productview.asp?id=589}{http://www.leynew.com/en/productview.asp?id=589}
\l{http://image.en.09635.com/2012-8/15/RF-Controller-Aluminum-Version-LN-CON-RF20B-H-3CH-LV-316.jpg}{http://image.en.09635.com/2012-8/15/RF-Controller-Aluminum-Version-LN-CON-RF20B-H-3CH-LV-316.jpg}
\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}.
Each \l{DeviceClass} has a list of \l{ParamType}{paramTypes}, \l{ActionType}{actionTypes}, \l{StateType}{stateTypes}
and \l{EventType}{eventTypes}. The \l{DeviceClass::CreateMethod}{createMethods} parameter describes how the \l{Device}
will be created in the system. A device can have more than one \l{DeviceClass::CreateMethod}{CreateMethod}.
The \l{DeviceClass::SetupMethod}{setupMethod} describes the setup method of the \l{Device}.
The detailed implementation of each \l{DeviceClass} can be found in the source code.
\quotefile plugins/deviceplugins/elro/devicepluginleynew.json
*/
#include "devicepluginleynew.h"
#include "devicemanager.h"
#include "plugininfo.h"
#include <QDebug>
#include <QStringList>
DevicePluginLeynew::DevicePluginLeynew()
{
}
DeviceManager::DeviceSetupStatus DevicePluginLeynew::setupDevice(Device *device)
{
Q_UNUSED(device);
return DeviceManager::DeviceSetupStatusSuccess;
}
DeviceManager::HardwareResources DevicePluginLeynew::requiredHardware() const
{
return DeviceManager::HardwareResourceRadio433;
}
DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, const Action &action)
{
if (device->deviceClassId() != rfControllerDeviceClassId) {
return DeviceManager::DeviceErrorDeviceClassNotFound;
}
QList<int> rawData;
QByteArray binCode;
// TODO: find out how ID will be calculated to bin code or make it discoverable
// =======================================
// bincode depending on the ID
if (device->paramValue("ID") == "0115"){
binCode.append("001101000001");
} else if (device->paramValue("ID") == "0014") {
binCode.append("110000010101");
} else {
return DeviceManager::DeviceErrorInvalidParameter;
}
// =======================================
// bincode depending on the action
if (action.actionTypeId() == brightnessUpActionTypeId) {
binCode.append("000000000011");
} else if (action.actionTypeId() == brightnessDownActionTypeId) {
binCode.append("000000001100");
} if (action.actionTypeId() == powerActionTypeId) {
binCode.append("000011000000");
}
// =======================================
//create rawData timings list
int delay = 200;
// sync signal (starting with ON)
rawData.append(1);
rawData.append(10);
// add the code
foreach (QChar c, binCode) {
if(c == '0'){
// _ _
// | |_
rawData.append(2);
rawData.append(1);
}else{
// _
// | |_ _
rawData.append(1);
rawData.append(2);
}
}
qDebug() << binCode;
qDebug() << rawData;
// =======================================
// send data to hardware resource
if(transmitData(delay, rawData)){
qDebug() << "transmitted" << pluginName() << device->name() << action.param("name").name();
return DeviceManager::DeviceErrorNoError;
}else{
qDebug() << "could not transmitt" << pluginName() << device->name() << action.param("name").name();
return DeviceManager::DeviceErrorHardwareNotAvailable;
}
}

View File

@ -0,0 +1,42 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 DEVICEPLUGINLEYNEW_H
#define DEVICEPLUGINLEYNEW_H
#include "plugin/deviceplugin.h"
class DevicePluginLeynew : public DevicePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "devicepluginleynew.json")
Q_INTERFACES(DevicePlugin)
public:
explicit DevicePluginLeynew();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::HardwareResources requiredHardware() const override;
public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
};
#endif // DEVICEPLUGINLEYNEW_H

View File

@ -0,0 +1,127 @@
{
"name": "Leynew",
"id": "9a6d23e6-fad8-4203-aeab-2e6e5c756990",
"vendors": [
{
"name": "Leynew",
"id": "83c649b4-49b0-4482-9334-d86a85bfbd2a",
"deviceClasses": [
{
"deviceClassId": "6b1f8f37-7eb4-46c4-9f15-a6eb4904999c",
"idName": "rfController",
"name": "RF Controller (LN-CON-RF20B)",
"createMethods": ["user"],
"paramTypes": [
{
"name": "ID",
"type": "QString",
"allowedValues": ["0115", "0014"]
}
],
"actionTypes": [
{
"id": "18a30ff1-28d7-4cd0-8388-290db52cd48d",
"idName": "brightnessUp",
"name": "Brightness up"
},
{
"id": "d1d251b6-ffe6-4b0c-bf03-bfa8947caa1d",
"idName": "brightnessDown",
"name": "Brightness down"
},
{
"id": "b8b4ef78-126f-431b-b33f-742754da5af4",
"idName": "playPause",
"name": "Play / Pause"
},
{
"id": "35495871-3b80-458b-b60d-5dc614c9fbf1",
"idName": "power",
"name": "Power"
},
{
"id": "737f77b6-fe2a-45ad-9945-8f0197e57741",
"idName": "red",
"name": "Red"
},
{
"id": "6471e804-fd54-41dd-88ed-ec46d6cc33db",
"idName": "green",
"name": "Green"
},
{
"id": "3abfe3c4-f9b3-4b22-aa3a-86ef99adedbe",
"idName": "blue",
"name": "Blue"
},
{
"id": "6a92d30d-7bce-4238-8e05-d25d3475699c",
"idName": "white",
"name": "White"
},
{
"id": "10a145db-adea-4eff-921d-4ce1ceb940cd",
"idName": "orange",
"name": "Orange"
},
{
"id": "46bbfb97-1600-4e91-930d-6ef4be7bdd9c",
"idName": "yellow",
"name": "Yellow"
},
{
"id": "7e1db150-c68f-4c54-8259-61d050f31555",
"idName": "cyan",
"name": "Cyan"
},
{
"id": "4008076e-ff8c-400b-8983-0a452ed66509",
"idName": "purple",
"name": "Purple"
},
{
"id": "c692b7b0-f891-4729-8e76-4e67f1f6ff4a",
"idName": "auto",
"name": "Auto"
},
{
"id": "14e696ef-6f9f-4095-9731-5f9e541dd416",
"idName": "jump3",
"name": "Jump 3"
},
{
"id": "1e764e9f-5ff1-4cd1-b3a8-7feb2a3f204c",
"idName": "fade3",
"name": "Fade 3"
},
{
"id": "85b37c46-a44c-4989-add2-06b5537fe1a1",
"idName": "speedUp",
"name": "Speed up"
},
{
"id": "7fdb9f73-e773-4839-9137-3771feabe3e9",
"idName": "speedDown",
"name": "Speed down"
},
{
"id": "851e024b-0eee-4eec-8261-478c28c03557",
"idName": "fade7",
"name": "Fade 7"
},
{
"id": "c40392be-323d-48db-a076-40cf4d8cc7eb",
"idName": "jump7",
"name": "Jump 7"
},
{
"id": "db700960-2b02-4ad3-8257-a28cb5fc6356",
"idName": "flash",
"name": "Flash"
}
]
}
]
}
]
}

View File

@ -0,0 +1,11 @@
include(../../plugins.pri)
TARGET = $$qtLibraryTarget(guh_devicepluginleynew)
SOURCES += \
devicepluginleynew.cpp
HEADERS += \
devicepluginleynew.h