deviceplugin can now receive rf data
This commit is contained in:
parent
7587944de2
commit
afb3ef0a02
1
Hive.pro
1
Hive.pro
@ -3,4 +3,5 @@ TEMPLATE=subdirs
|
|||||||
SUBDIRS += libhive server plugins
|
SUBDIRS += libhive server plugins
|
||||||
|
|
||||||
server.depends = libhive plugins
|
server.depends = libhive plugins
|
||||||
|
plugins.deoends = libhive
|
||||||
|
|
||||||
|
|||||||
@ -15,24 +15,9 @@ Q_IMPORT_PLUGIN(RfSwitch)
|
|||||||
DeviceManager::DeviceManager(QObject *parent) :
|
DeviceManager::DeviceManager(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << "creating radio";
|
|
||||||
m_radio433 = new Radio433(this);
|
m_radio433 = new Radio433(this);
|
||||||
|
|
||||||
qDebug() << "loading plugins";
|
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
|
||||||
foreach (QObject *pluginObject, QPluginLoader::staticInstances()) {
|
|
||||||
DevicePlugin *pluginIface = qobject_cast<DevicePlugin*>(pluginObject);
|
|
||||||
qDebug() << "got plugin instance";
|
|
||||||
if (pluginIface) {
|
|
||||||
qDebug() << "got device plugin" << pluginIface->pluginName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: load dynamically
|
|
||||||
// RfSwitch *rfSwitch = new RfSwitch(this);
|
|
||||||
// m_supportedDevices.append(rfSwitch->supportedDevices());
|
|
||||||
// m_devicePlugins.append(rfSwitch);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<DeviceClass> DeviceManager::supportedDevices()
|
QList<DeviceClass> DeviceManager::supportedDevices()
|
||||||
@ -45,8 +30,21 @@ QList<Device *> DeviceManager::devices() const
|
|||||||
return m_devices;
|
return m_devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
Radio433 *DeviceManager::radio() const
|
Radio433 *DeviceManager::radio433() const
|
||||||
{
|
{
|
||||||
return m_radio433;
|
return m_radio433;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceManager::loadPlugins()
|
||||||
|
{
|
||||||
|
foreach (QObject *pluginObject, QPluginLoader::staticInstances()) {
|
||||||
|
DevicePlugin *pluginIface = qobject_cast<DevicePlugin*>(pluginObject);
|
||||||
|
if (pluginIface) {
|
||||||
|
qDebug() << "*** Loaded plugin" << pluginIface->pluginName();
|
||||||
|
pluginIface->initPlugin(this);
|
||||||
|
m_supportedDevices.append(pluginIface->supportedDevices());
|
||||||
|
m_devicePlugins.append(pluginIface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,11 +19,12 @@ public:
|
|||||||
|
|
||||||
QList<Device*> devices() const;
|
QList<Device*> devices() const;
|
||||||
|
|
||||||
Radio433 *radio() const;
|
Radio433 *radio433() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
|
void loadPlugins();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<DeviceClass> m_supportedDevices;
|
QList<DeviceClass> m_supportedDevices;
|
||||||
|
|||||||
@ -7,9 +7,10 @@ DevicePlugin::~DevicePlugin()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePlugin::init(DeviceManager *deviceManager)
|
void DevicePlugin::initPlugin(DeviceManager *deviceManager)
|
||||||
{
|
{
|
||||||
m_deviceManager = deviceManager;
|
m_deviceManager = deviceManager;
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager *DevicePlugin::deviceManager() const
|
DeviceManager *DevicePlugin::deviceManager() const
|
||||||
|
|||||||
@ -13,7 +13,9 @@ public:
|
|||||||
DevicePlugin();
|
DevicePlugin();
|
||||||
virtual ~DevicePlugin();
|
virtual ~DevicePlugin();
|
||||||
|
|
||||||
void init(DeviceManager *deviceManager);
|
void initPlugin(DeviceManager *deviceManager);
|
||||||
|
|
||||||
|
virtual void init() {}
|
||||||
|
|
||||||
virtual QString pluginName() const = 0;
|
virtual QString pluginName() const = 0;
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,19 @@
|
|||||||
#include "rfswitch.h"
|
#include "rfswitch.h"
|
||||||
|
|
||||||
#include "devicemanager.h"
|
#include "devicemanager.h"
|
||||||
|
#include "radio433.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
RfSwitch::RfSwitch()
|
RfSwitch::RfSwitch()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RfSwitch::init()
|
||||||
|
{
|
||||||
|
connect(deviceManager()->radio433(), &Radio433::dataReceived, this, &RfSwitch::dataReceived);
|
||||||
|
}
|
||||||
|
|
||||||
QList<DeviceClass> RfSwitch::supportedDevices() const
|
QList<DeviceClass> RfSwitch::supportedDevices() const
|
||||||
{
|
{
|
||||||
// TODO: load list from config with static uuid
|
// TODO: load list from config with static uuid
|
||||||
@ -27,3 +35,8 @@ QString RfSwitch::pluginName() const
|
|||||||
{
|
{
|
||||||
return "RF Switch";
|
return "RF Switch";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RfSwitch::dataReceived(QList<int> rawData)
|
||||||
|
{
|
||||||
|
qDebug() << "data received from Radio433" << rawData;
|
||||||
|
}
|
||||||
|
|||||||
@ -13,14 +13,13 @@ class RfSwitch : public QObject, public DevicePlugin
|
|||||||
public:
|
public:
|
||||||
explicit RfSwitch();
|
explicit RfSwitch();
|
||||||
|
|
||||||
|
void init() override;
|
||||||
QList<DeviceClass> supportedDevices() const override;
|
QList<DeviceClass> supportedDevices() const override;
|
||||||
|
|
||||||
QString pluginName() const;
|
QString pluginName() const;
|
||||||
|
|
||||||
signals:
|
private slots:
|
||||||
|
void dataReceived(QList<int> rawData);
|
||||||
public slots:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RFSWITCH_H
|
#endif // RFSWITCH_H
|
||||||
|
|||||||
Reference in New Issue
Block a user