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
|
||||
|
||||
server.depends = libhive plugins
|
||||
plugins.deoends = libhive
|
||||
|
||||
|
||||
@ -15,24 +15,9 @@ Q_IMPORT_PLUGIN(RfSwitch)
|
||||
DeviceManager::DeviceManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
qDebug() << "creating radio";
|
||||
m_radio433 = new Radio433(this);
|
||||
|
||||
qDebug() << "loading plugins";
|
||||
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);
|
||||
|
||||
|
||||
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QList<DeviceClass> DeviceManager::supportedDevices()
|
||||
@ -45,8 +30,21 @@ QList<Device *> DeviceManager::devices() const
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
Radio433 *DeviceManager::radio() const
|
||||
Radio433 *DeviceManager::radio433() const
|
||||
{
|
||||
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;
|
||||
|
||||
Radio433 *radio() const;
|
||||
Radio433 *radio433() const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void loadPlugins();
|
||||
|
||||
private:
|
||||
QList<DeviceClass> m_supportedDevices;
|
||||
|
||||
@ -7,9 +7,10 @@ DevicePlugin::~DevicePlugin()
|
||||
|
||||
}
|
||||
|
||||
void DevicePlugin::init(DeviceManager *deviceManager)
|
||||
void DevicePlugin::initPlugin(DeviceManager *deviceManager)
|
||||
{
|
||||
m_deviceManager = deviceManager;
|
||||
init();
|
||||
}
|
||||
|
||||
DeviceManager *DevicePlugin::deviceManager() const
|
||||
|
||||
@ -13,7 +13,9 @@ public:
|
||||
DevicePlugin();
|
||||
virtual ~DevicePlugin();
|
||||
|
||||
void init(DeviceManager *deviceManager);
|
||||
void initPlugin(DeviceManager *deviceManager);
|
||||
|
||||
virtual void init() {}
|
||||
|
||||
virtual QString pluginName() const = 0;
|
||||
|
||||
|
||||
@ -1,11 +1,19 @@
|
||||
#include "rfswitch.h"
|
||||
|
||||
#include "devicemanager.h"
|
||||
#include "radio433.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
RfSwitch::RfSwitch()
|
||||
{
|
||||
}
|
||||
|
||||
void RfSwitch::init()
|
||||
{
|
||||
connect(deviceManager()->radio433(), &Radio433::dataReceived, this, &RfSwitch::dataReceived);
|
||||
}
|
||||
|
||||
QList<DeviceClass> RfSwitch::supportedDevices() const
|
||||
{
|
||||
// TODO: load list from config with static uuid
|
||||
@ -27,3 +35,8 @@ QString RfSwitch::pluginName() const
|
||||
{
|
||||
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:
|
||||
explicit RfSwitch();
|
||||
|
||||
void init() override;
|
||||
QList<DeviceClass> supportedDevices() const override;
|
||||
|
||||
QString pluginName() const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void dataReceived(QList<int> rawData);
|
||||
};
|
||||
|
||||
#endif // RFSWITCH_H
|
||||
|
||||
Reference in New Issue
Block a user