From ac436b075144d9e980b72fcbe041cc42c1a8205a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 13 Nov 2017 11:22:29 +0100 Subject: [PATCH] continue migrate to hardwaremanager --- guh.pri | 5 ---- guh.pro | 9 +----- libguh/hardware/radio433/radio433.cpp | 21 +++++-------- libguh/hardware/radio433/radio433.h | 13 ++++---- libguh/hardwaremanager.cpp | 43 ++++++++++++++++++++++++++- libguh/hardwaremanager.h | 9 ++++++ libguh/plugin/device.cpp | 1 - 7 files changed, 64 insertions(+), 37 deletions(-) diff --git a/guh.pri b/guh.pri index f49697c8..ed503a30 100644 --- a/guh.pri +++ b/guh.pri @@ -84,9 +84,4 @@ coverage { QMAKE_CLEAN += *.gcda *.gcno coverage.info coverage.xml } -# Enable Radio 433 MHz for GPIO's -enable433gpio { - DEFINES += GPIO433 -} - diff --git a/guh.pro b/guh.pro index 7b43f904..31aefce4 100644 --- a/guh.pro +++ b/guh.pro @@ -13,7 +13,7 @@ doc.depends = libguh server # Note: some how extraimages in qdocconf did not the trick doc.commands += cd $$top_srcdir/libguh/interfaces; ./generatedoc.sh; doc.commands += cd $$top_srcdir/doc; qdoc config.qdocconf; cp -r images/* html/images/; \ - cp -r favicons/* html/; cp -r $$top_srcdir/doc/html $$top_builddir/ + cp -r favicons/* html/; cp -r $$top_srcdir/doc/html $$top_builddir/ licensecheck.commands = $$top_srcdir/tests/auto/checklicenseheaders.sh $$top_srcdir @@ -54,10 +54,3 @@ disabletesting { message("Building guh with tests") SUBDIRS += tests } - -# GPIO RF 433 MHz support -contains(DEFINES, GPIO433) { - message("Radio 433 for GPIO's enabled") -} else { - message("Radio 433 for GPIO's disabled") -} diff --git a/libguh/hardware/radio433/radio433.cpp b/libguh/hardware/radio433/radio433.cpp index 252df360..241a9dc5 100644 --- a/libguh/hardware/radio433/radio433.cpp +++ b/libguh/hardware/radio433/radio433.cpp @@ -56,17 +56,15 @@ /*! Construct the hardware resource Radio433 with the given \a parent. Each possible 433 MHz hardware will be initialized here. */ Radio433::Radio433(QObject *parent) : - QObject(parent) + HardwareResource(HardwareResource::TypeRadio433, parent) { - #ifdef GPIO433 GuhSettings settings(GuhSettings::SettingsRoleGlobal); qCDebug(dcHardware) << "Loading GPIO settings from:" << settings.fileName(); - settings.beginGroup("GPIO"); + settings.beginGroup("RF433"); int transmitterGpioNumber = settings.value("rf433tx",22).toInt(); settings.endGroup(); m_transmitter = new Radio433Trasmitter(this, transmitterGpioNumber); - #endif m_brennenstuhlTransmitter = new Radio433BrennenstuhlGateway(this); connect(m_brennenstuhlTransmitter, &Radio433BrennenstuhlGateway::availableChanged, this, &Radio433::brennenstuhlAvailableChanged); @@ -75,9 +73,7 @@ Radio433::Radio433(QObject *parent) : /*! Destroys the hardware resource Radio433 object. */ Radio433::~Radio433() { - #ifdef GPIO433 m_transmitter->quit(); - #endif } /*! Enables GPIO transmitter and receiver and the Brennenstuhl Lan Gateway. @@ -86,10 +82,8 @@ bool Radio433::enable() { m_brennenstuhlTransmitter->enable(); - #ifdef GPIO433 // check if GPIOs are available if (Gpio::isAvailable()) { - bool transmitterAvailable = m_transmitter->startTransmitter(); if (!transmitterAvailable) { //qCWarning(dcHardware) << "ERROR: radio 433 MHz transmitter not available on GPIO's"; @@ -100,16 +94,17 @@ bool Radio433::enable() return false; } } - qCDebug(dcDeviceManager()) << "--> Radio 433 MHz GPIO's enabled."; - #endif + setEnabled(true); + qCDebug(dcDeviceManager()) << "--> Radio 433 MHz GPIO's enabled."; return true; } /*! Returns true, if the Radio433 hardware resources disabled correctly. */ -bool Radio433::disabel() +bool Radio433::disable() { m_brennenstuhlTransmitter->disable(); + setEnabled(false); return true; } @@ -117,6 +112,7 @@ void Radio433::brennenstuhlAvailableChanged(const bool &available) { if (available) { qCDebug(dcHardware()) << "--> Radio 433 MHz Brennenstuhl LAN Gateway available."; + setAvailable(true); } else { qCWarning(dcHardware()) << "--> Radio 433 MHz Brennenstuhl LAN Gateway NOT available."; } @@ -132,12 +128,9 @@ bool Radio433::sendData(int delay, QList rawData, int repetitions) sendBrennenstuhl = m_brennenstuhlTransmitter->sendData(delay, rawData, repetitions); } - #ifdef GPIO433 if (m_transmitter->available()) { m_transmitter->sendData(delay, rawData, repetitions); sendGpio = true; } - #endif - return (sendGpio || sendBrennenstuhl); } diff --git a/libguh/hardware/radio433/radio433.h b/libguh/hardware/radio433/radio433.h index e19a275a..b16660df 100644 --- a/libguh/hardware/radio433/radio433.h +++ b/libguh/hardware/radio433/radio433.h @@ -25,28 +25,22 @@ #include -#ifdef GPIO433 #include "radio433transmitter.h" -#endif #include "libguh.h" +#include "hardwareresource.h" #include "radio433brennenstuhlgateway.h" -class LIBGUH_EXPORT Radio433 : public QObject +class LIBGUH_EXPORT Radio433 : public HardwareResource { Q_OBJECT public: explicit Radio433(QObject *parent = 0); ~Radio433(); - bool enable(); - bool disabel(); private: - #ifdef GPIO433 Radio433Trasmitter *m_transmitter; - #endif - Radio433BrennenstuhlGateway *m_brennenstuhlTransmitter; private slots: @@ -55,6 +49,9 @@ private slots: public slots: bool sendData(int delay, QList rawData, int repetitions); + bool enable(); + bool disable(); + }; #endif // RADIO433_H diff --git a/libguh/hardwaremanager.cpp b/libguh/hardwaremanager.cpp index 22d36eda..1b817320 100644 --- a/libguh/hardwaremanager.cpp +++ b/libguh/hardwaremanager.cpp @@ -5,6 +5,8 @@ HardwareManager::HardwareManager(QObject *parent) : QObject(parent) // Init hardware resources m_pluginTimer = new PluginTimer(10000, this); + m_hardwareResources.append(m_pluginTimer); + m_radio433 = new Radio433(this); m_radio433->enable(); @@ -24,7 +26,6 @@ HardwareManager::HardwareManager(QObject *parent) : QObject(parent) delete m_bluetoothScanner; m_bluetoothScanner = nullptr; } - } Radio433 *HardwareManager::radio433() @@ -57,3 +58,43 @@ BluetoothScanner *HardwareManager::bluetoothScanner() return m_bluetoothScanner; } +bool HardwareManager::isAvailable(const HardwareResource::Type &hardwareResourceType) const +{ + foreach (HardwareResource *resource, m_hardwareResources) { + if (resource->hardwareReourceType() == hardwareResourceType && resource->available()) { + return true; + } + } + return false; +} + +bool HardwareManager::isEnabled(const HardwareResource::Type &hardwareResourceType) const +{ + foreach (HardwareResource *resource, m_hardwareResources) { + if (resource->hardwareReourceType() == hardwareResourceType && resource->enabled()) { + return true; + } + } + return false; +} + +bool HardwareManager::enableHardwareReource(const HardwareResource::Type &hardwareResourceType) +{ + foreach (HardwareResource *resource, m_hardwareResources) { + if (resource->hardwareReourceType() == hardwareResourceType) { + return resource->enabled(); + } + } + return false; +} + +bool HardwareManager::disableHardwareReource(const HardwareResource::Type &hardwareResourceType) +{ + foreach (HardwareResource *resource, m_hardwareResources) { + if (resource->hardwareReourceType() == hardwareResourceType) { + return resource->disable(); + } + } + return false; +} + diff --git a/libguh/hardwaremanager.h b/libguh/hardwaremanager.h index 8d52c95d..b01f64fb 100644 --- a/libguh/hardwaremanager.h +++ b/libguh/hardwaremanager.h @@ -27,7 +27,12 @@ public: QtAvahiServiceBrowser *avahiBrowser(); BluetoothScanner *bluetoothScanner(); + bool isAvailable(const HardwareResource::Type &hardwareResourceType) const; + bool isEnabled(const HardwareResource::Type &hardwareResourceType) const; + private: + QList m_hardwareResources; + // Hardware Resources Radio433 *m_radio433 = nullptr; PluginTimer *m_pluginTimer = nullptr; @@ -37,8 +42,12 @@ private: BluetoothScanner *m_bluetoothScanner = nullptr; signals: + void hardwareResourceAvailableChanged(const HardwareResource::Type &hardwareResourceType, const bool &available); + void hardwareResourceEnabledChanged(const HardwareResource::Type &hardwareResourceType, const bool &enabled); public slots: + bool enableHardwareReource(const HardwareResource::Type &hardwareResourceType); + bool disableHardwareReource(const HardwareResource::Type &hardwareResourceType); }; diff --git a/libguh/plugin/device.cpp b/libguh/plugin/device.cpp index 15b2fc43..aa9500f2 100644 --- a/libguh/plugin/device.cpp +++ b/libguh/plugin/device.cpp @@ -38,7 +38,6 @@ This signal is emitted when the \l{State} with the given \a stateTypeId changed. The \a value parameter describes the new value of the State. */ - #include "device.h" #include "types/event.h" #include "loggingcategories.h"