fixed some Radio433 bugs
This commit is contained in:
parent
aa528079b0
commit
4242c480ed
@ -33,9 +33,6 @@ Radio433::Radio433(QObject *parent) :
|
||||
m_transmitter = new Radio433Trasmitter();
|
||||
|
||||
connect(m_receiver,SIGNAL(readingChanged(bool)),this,SLOT(readingChanged(bool)));
|
||||
|
||||
m_receiver->startReceiver();
|
||||
m_transmitter->startTransmitter();
|
||||
}
|
||||
|
||||
Radio433::~Radio433()
|
||||
@ -47,6 +44,30 @@ Radio433::~Radio433()
|
||||
m_transmitter->quit();
|
||||
}
|
||||
|
||||
bool Radio433::available()
|
||||
{
|
||||
if(m_receiver->setUpGpio() && m_transmitter->setUpGpio()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Radio433::enabel()
|
||||
{
|
||||
if(m_receiver->startReceiver() && m_transmitter->startTransmitter()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Radio433::disabel()
|
||||
{
|
||||
if(m_receiver->stopReceiver() && m_transmitter->stopTransmitter()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Radio433::readingChanged(bool reading)
|
||||
{
|
||||
if(reading){
|
||||
|
||||
@ -31,6 +31,9 @@ public:
|
||||
explicit Radio433(QObject *parent = 0);
|
||||
~Radio433();
|
||||
|
||||
bool enabel();
|
||||
bool disabel();
|
||||
|
||||
private:
|
||||
Radio433Receiver *m_receiver;
|
||||
Radio433Trasmitter *m_transmitter;
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
Radio433Receiver::Radio433Receiver(QObject *parent, int gpio) :
|
||||
QThread(parent),m_gpioPin(gpio)
|
||||
{
|
||||
m_gpio = new Gpio(this,m_gpioPin);
|
||||
stopReceiver();
|
||||
|
||||
connect(this,SIGNAL(timingReady(int)),this,SLOT(handleTiming(int)),Qt::DirectConnection);
|
||||
@ -35,29 +36,27 @@ Radio433Receiver::~Radio433Receiver()
|
||||
{
|
||||
}
|
||||
|
||||
void Radio433Receiver::startReceiver()
|
||||
bool Radio433Receiver::startReceiver()
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_enabled = true;
|
||||
m_mutex.unlock();
|
||||
|
||||
m_timings.clear();
|
||||
|
||||
run();
|
||||
if(setUpGpio()){
|
||||
m_timings.clear();
|
||||
run();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Radio433Receiver::stopReceiver()
|
||||
bool Radio433Receiver::stopReceiver()
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_enabled = false;
|
||||
m_mutex.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Radio433Receiver::run()
|
||||
{
|
||||
// init the gpio
|
||||
setUpGpio();
|
||||
|
||||
struct pollfd fdset[2];
|
||||
int gpio_fd = m_gpio->openGpio();
|
||||
char buf[1];
|
||||
@ -102,10 +101,12 @@ void Radio433Receiver::run()
|
||||
|
||||
bool Radio433Receiver::setUpGpio()
|
||||
{
|
||||
m_gpio = new Gpio(this,m_gpioPin);
|
||||
m_gpio->setDirection(INPUT);
|
||||
m_gpio->setEdgeInterrupt(EDGE_BOTH);
|
||||
|
||||
if(!m_gpio->openGpio()){
|
||||
return false;
|
||||
}else{
|
||||
m_gpio->setDirection(INPUT);
|
||||
m_gpio->setEdgeInterrupt(EDGE_BOTH);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -36,8 +36,8 @@ public:
|
||||
ProtocolNone
|
||||
};
|
||||
|
||||
void startReceiver();
|
||||
void stopReceiver();
|
||||
bool startReceiver();
|
||||
bool stopReceiver();
|
||||
|
||||
private:
|
||||
int m_gpioPin;
|
||||
|
||||
@ -21,6 +21,8 @@
|
||||
Radio433Trasmitter::Radio433Trasmitter(QObject *parent, int gpio) :
|
||||
QThread(parent),m_gpioPin(gpio)
|
||||
{
|
||||
m_gpio = new Gpio(this,m_gpioPin);
|
||||
|
||||
stopTransmitter();
|
||||
}
|
||||
|
||||
@ -28,20 +30,40 @@ Radio433Trasmitter::~Radio433Trasmitter()
|
||||
{
|
||||
}
|
||||
|
||||
void Radio433Trasmitter::startTransmitter()
|
||||
bool Radio433Trasmitter::startTransmitter()
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_enabled = true;
|
||||
m_mutex.unlock();
|
||||
|
||||
run();
|
||||
if(setUpGpio()){
|
||||
run();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Radio433Trasmitter::stopTransmitter()
|
||||
bool Radio433Trasmitter::stopTransmitter()
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_enabled = false;
|
||||
m_mutex.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Radio433Trasmitter::setUpGpio()
|
||||
{
|
||||
if(!m_gpio->openGpio()){
|
||||
return false;
|
||||
}else{
|
||||
m_gpio->setDirection(OUTPUT);
|
||||
m_gpio->setValue(LOW);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Radio433Trasmitter::sendData(QList<int> rawData)
|
||||
{
|
||||
m_queueMutex.lock();
|
||||
m_rawDataQueue.enqueue(rawData);
|
||||
m_queueMutex.unlock();
|
||||
}
|
||||
|
||||
void Radio433Trasmitter::run()
|
||||
@ -86,6 +108,10 @@ void Radio433Trasmitter::run()
|
||||
m_allowSendingMutex.unlock();
|
||||
}
|
||||
m_gpio->setValue(LOW);
|
||||
}else{
|
||||
m_queueMutex.unlock();
|
||||
m_allowSendingMutex.unlock();
|
||||
break;
|
||||
}
|
||||
m_queueMutex.unlock();
|
||||
m_allowSendingMutex.unlock();
|
||||
@ -102,19 +128,3 @@ void Radio433Trasmitter::allowSending(bool sending)
|
||||
m_allowSending = sending;
|
||||
m_allowSendingMutex.unlock();
|
||||
}
|
||||
|
||||
bool Radio433Trasmitter::setUpGpio()
|
||||
{
|
||||
m_gpio = new Gpio(this,m_gpioPin);
|
||||
if(!m_gpio->setDirection(OUTPUT) || m_gpio->setValue(LOW)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Radio433Trasmitter::sendData(QList<int> rawData)
|
||||
{
|
||||
m_queueMutex.lock();
|
||||
m_rawDataQueue.enqueue(rawData);
|
||||
m_queueMutex.unlock();
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ public:
|
||||
explicit Radio433Trasmitter(QObject *parent = 0, int gpio = 22);
|
||||
~Radio433Trasmitter();
|
||||
|
||||
void startTransmitter();
|
||||
void stopTransmitter();
|
||||
bool startTransmitter();
|
||||
bool stopTransmitter();
|
||||
|
||||
void sendData(QList<int> rawData);
|
||||
|
||||
|
||||
@ -425,21 +425,24 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
||||
|
||||
QPair<DeviceManager::DeviceError, QString> DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||
{
|
||||
qDebug() << "should discover devices with params:" << params;
|
||||
QString location;
|
||||
foreach (const Param ¶m, params) {
|
||||
qDebug() << "### got param:" << param;
|
||||
if (param.name() == "location") {
|
||||
location = param.value().toString();
|
||||
}
|
||||
}
|
||||
if(deviceClassId == openweathermapDeviceClassId){
|
||||
|
||||
if (location.isEmpty()){
|
||||
m_openweaher->searchAutodetect();
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
QString location;
|
||||
foreach (const Param ¶m, params) {
|
||||
if (param.name() == "location") {
|
||||
location = param.value().toString();
|
||||
}
|
||||
}
|
||||
qDebug() << "Searching for... " << location;
|
||||
if (location.isEmpty()){
|
||||
m_openweaher->searchAutodetect();
|
||||
}else{
|
||||
m_openweaher->search(location);
|
||||
}
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}else{
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
m_openweaher->search(location);
|
||||
return report(DeviceManager::DeviceErrorAsync);
|
||||
}
|
||||
|
||||
QPair<DeviceManager::DeviceSetupStatus, QString> DevicePluginOpenweathermap::setupDevice(Device *device)
|
||||
|
||||
Reference in New Issue
Block a user