mirror of https://github.com/nymea/nymea.git
radio thread fixed
parent
afb3ef0a02
commit
992ccd3a04
|
|
@ -17,7 +17,25 @@ DeviceManager::DeviceManager(QObject *parent) :
|
|||
{
|
||||
m_radio433 = new Radio433(this);
|
||||
|
||||
<<<<<<< HEAD
|
||||
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
|
||||
=======
|
||||
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);
|
||||
|
||||
|
||||
>>>>>>> radio thread fixed
|
||||
}
|
||||
|
||||
QList<DeviceClass> DeviceManager::supportedDevices()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#include "gpio.h"
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
Gpio::Gpio(QObject *parent, int gpio) :
|
||||
QObject(parent),m_gpio(gpio)
|
||||
QThread(parent),m_gpio(gpio)
|
||||
{
|
||||
exportGpio();
|
||||
}
|
||||
|
|
@ -12,6 +13,46 @@ Gpio::~Gpio()
|
|||
unexportGpio();
|
||||
}
|
||||
|
||||
void Gpio::run()
|
||||
{
|
||||
struct pollfd fdset[2];
|
||||
int gpio_fd = openGpio();
|
||||
int nfds = 2;
|
||||
int rc;
|
||||
int timeout = 3000;
|
||||
char buf[64];
|
||||
|
||||
|
||||
bool enabled = true;
|
||||
|
||||
while(enabled){
|
||||
memset((void*)fdset, 0, sizeof(fdset));
|
||||
fdset[0].fd = STDIN_FILENO;
|
||||
fdset[0].events = POLLIN;
|
||||
|
||||
fdset[1].fd = gpio_fd;
|
||||
fdset[1].events = POLLPRI;
|
||||
|
||||
rc = poll(fdset, nfds, timeout);
|
||||
|
||||
if (rc < 0) {
|
||||
qDebug() << "ERROR: poll failed";
|
||||
return;
|
||||
}
|
||||
if(rc == 0){
|
||||
//timeout
|
||||
}
|
||||
if (fdset[1].revents & POLLPRI) {
|
||||
read(fdset[1].fd, buf, 64);
|
||||
emit pinInterrupt();
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
enabled = m_enabled;
|
||||
m_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
bool Gpio::exportGpio()
|
||||
{
|
||||
char buf[64];
|
||||
|
|
@ -174,35 +215,9 @@ bool Gpio::setEdgeInterrupt(int edge)
|
|||
return false;
|
||||
}
|
||||
|
||||
void Gpio::enableInterrupt()
|
||||
void Gpio::stop()
|
||||
{
|
||||
struct pollfd fdset[2];
|
||||
int gpio_fd = openGpio();
|
||||
int nfds = 2;
|
||||
int rc;
|
||||
int timeout = 3000;
|
||||
char buf[64];
|
||||
|
||||
while(1){
|
||||
memset((void*)fdset, 0, sizeof(fdset));
|
||||
fdset[0].fd = STDIN_FILENO;
|
||||
fdset[0].events = POLLIN;
|
||||
|
||||
fdset[1].fd = gpio_fd;
|
||||
fdset[1].events = POLLPRI;
|
||||
|
||||
rc = poll(fdset, nfds, timeout);
|
||||
|
||||
if (rc < 0) {
|
||||
qDebug() << "ERROR: poll failed";
|
||||
return;
|
||||
}
|
||||
if(rc == 0){
|
||||
//timeout
|
||||
}
|
||||
if (fdset[1].revents & POLLPRI) {
|
||||
read(fdset[1].fd, buf, 64);
|
||||
emit pinInterrupt();
|
||||
}
|
||||
}
|
||||
m_mutex.lock();
|
||||
m_enabled = false;
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
#define GPIO_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -46,13 +50,15 @@
|
|||
**********************************
|
||||
*/
|
||||
|
||||
class Gpio : public QObject
|
||||
class Gpio : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Gpio(QObject *parent = 0, int gpio = 0);
|
||||
~Gpio();
|
||||
|
||||
void run() override;
|
||||
|
||||
bool exportGpio();
|
||||
bool unexportGpio();
|
||||
|
||||
|
|
@ -65,18 +71,20 @@ public:
|
|||
|
||||
bool setEdgeInterrupt(int edge);
|
||||
|
||||
void stop();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
int m_gpio;
|
||||
int m_dir;
|
||||
QMutex m_mutex;
|
||||
bool m_enabled;
|
||||
|
||||
signals:
|
||||
void pinInterrupt();
|
||||
|
||||
public slots:
|
||||
void enableInterrupt();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
TARGET = hive
|
||||
TEMPLATE = lib
|
||||
|
||||
target.path = /usr/lib
|
||||
INSTALLS += target
|
||||
|
||||
SOURCES += device.cpp \
|
||||
deviceclass.cpp \
|
||||
devicemanager.cpp \
|
||||
|
|
|
|||
|
|
@ -7,34 +7,31 @@ Radio433::Radio433(QObject *parent) :
|
|||
QObject(parent)
|
||||
{
|
||||
// Set up receiver
|
||||
m_receiverThread = new QThread(this);
|
||||
m_receiver = new Gpio(0,27);
|
||||
m_receiver = new Gpio(this,27);
|
||||
m_receiver->setDirection(INPUT);
|
||||
m_receiver->setEdgeInterrupt(EDGE_BOTH);
|
||||
m_receiver->moveToThread(m_receiverThread);
|
||||
|
||||
// Set up transmitter
|
||||
m_transmitter = new Gpio(this,22);
|
||||
m_transmitter->setDirection(OUTPUT);
|
||||
m_transmitter->setValue(LOW);
|
||||
|
||||
connect(m_receiverThread,SIGNAL(finished()),this,SLOT(deleteLater()));
|
||||
connect(m_receiver,SIGNAL(pinInterrupt()),this,SLOT(handleInterrupt()));
|
||||
|
||||
enableReceiver();
|
||||
m_receiver->start();
|
||||
}
|
||||
|
||||
Radio433::~Radio433()
|
||||
{
|
||||
m_receiverThread->quit();
|
||||
m_receiverThread->wait();
|
||||
m_receiver->quit();
|
||||
m_receiver->wait();
|
||||
}
|
||||
|
||||
void Radio433::sendData(QList<int> rawData)
|
||||
{
|
||||
|
||||
//first we have to disable our receiver, to prevent reading the hive signal it self
|
||||
disableReceiver();
|
||||
m_receiver->stop();
|
||||
|
||||
m_transmitter->setValue(LOW);
|
||||
delayMicroseconds(500);
|
||||
|
|
@ -47,7 +44,7 @@ void Radio433::sendData(QList<int> rawData)
|
|||
}
|
||||
|
||||
// reenable it
|
||||
enableReceiver();
|
||||
m_receiver->start();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -133,16 +130,11 @@ void Radio433::handleInterrupt()
|
|||
void Radio433::enableReceiver()
|
||||
{
|
||||
qDebug() << "starting receiver";
|
||||
m_receiverThread->start();
|
||||
qDebug() << "fooo";
|
||||
QMetaObject::invokeMethod(m_receiver, SLOT(enableInterrupt()), Qt::QueuedConnection);
|
||||
// m_receiver->enableInterrupt();
|
||||
qDebug() << "receiver enabeld.";
|
||||
m_receiver->start();
|
||||
}
|
||||
|
||||
void Radio433::disableReceiver()
|
||||
{
|
||||
m_receiverThread->quit();
|
||||
m_receiverThread->wait();
|
||||
m_receiver->stop();
|
||||
qDebug() << "receiver disabeld.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ public:
|
|||
private:
|
||||
Gpio *m_receiver;
|
||||
Gpio *m_transmitter;
|
||||
QThread *m_receiverThread;
|
||||
|
||||
unsigned int m_timings[RC_MAX_CHANGES];
|
||||
unsigned int m_duration;
|
||||
|
|
|
|||
Loading…
Reference in New Issue