From 703944a240e8c3c644cd9d952cc2ba402bde7956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 4 Sep 2021 16:55:33 +0200 Subject: [PATCH 1/5] Update to libnymea-gpio, extend gpio params, restore output gpio on reboot and add gpio buttons --- debian/control | 2 + gpio/gpio.pro | 2 +- gpio/integrationplugingpio.cpp | 205 ++++++++++----- gpio/integrationplugingpio.h | 21 +- gpio/integrationplugingpio.json | 158 ++++++++++- ...127ead55-996a-44ac-ba82-fc3c634e018a-de.ts | 246 +++++++++++------- ...ead55-996a-44ac-ba82-fc3c634e018a-en_US.ts | 246 +++++++++++------- 7 files changed, 621 insertions(+), 259 deletions(-) diff --git a/debian/control b/debian/control index ccb78d60..4b4c7edd 100644 --- a/debian/control +++ b/debian/control @@ -6,6 +6,7 @@ Build-depends: libboblight-dev, debhelper (>= 0.0.0), libnymea-dev (>= 0.26~), libnymea-mqtt-dev, + libnymea-gpio-dev, libnymea-zigbee-dev, libqt5serialport5-dev, libqt5websockets5-dev, @@ -365,6 +366,7 @@ Package: nymea-plugin-gpio Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, + libnymea-gpio, nymea-plugins-translations, Description: nymea.io plugin for gpio The nymea daemon is a plugin based IoT (Internet of Things) server. The diff --git a/gpio/gpio.pro b/gpio/gpio.pro index f3f8ffd1..060a7a1d 100644 --- a/gpio/gpio.pro +++ b/gpio/gpio.pro @@ -1,6 +1,6 @@ include(../plugins.pri) -TARGET = $$qtLibraryTarget(nymea_integrationplugingpio) +PKGCONFIG += nymea-gpio SOURCES += \ integrationplugingpio.cpp \ diff --git a/gpio/integrationplugingpio.cpp b/gpio/integrationplugingpio.cpp index 08fd6a7f..9b86ed81 100644 --- a/gpio/integrationplugingpio.cpp +++ b/gpio/integrationplugingpio.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2021, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -35,6 +35,33 @@ IntegrationPluginGpio::IntegrationPluginGpio() { + +} + +void IntegrationPluginGpio::init() +{ + // Raspberry pi + m_gpioParamTypeIds.insert(gpioOutputRpiThingClassId, gpioOutputRpiThingGpioParamTypeId); + m_gpioParamTypeIds.insert(gpioInputRpiThingClassId, gpioInputRpiThingGpioParamTypeId); + m_gpioParamTypeIds.insert(counterRpiThingClassId, counterRpiThingGpioParamTypeId); + m_gpioParamTypeIds.insert(gpioButtonRpiThingClassId, gpioButtonRpiThingGpioParamTypeId); + + // Beagle bone black + m_gpioParamTypeIds.insert(gpioOutputBbbThingClassId, gpioOutputBbbThingGpioParamTypeId); + m_gpioParamTypeIds.insert(gpioInputBbbThingClassId, gpioInputBbbThingGpioParamTypeId); + m_gpioParamTypeIds.insert(counterBbbThingClassId, counterBbbThingGpioParamTypeId); + + // Raspberry pi + m_activeLowParamTypeIds.insert(gpioOutputRpiThingClassId, gpioOutputRpiThingActiveLowParamTypeId); + m_activeLowParamTypeIds.insert(gpioInputRpiThingClassId, gpioInputRpiThingActiveLowParamTypeId); + m_activeLowParamTypeIds.insert(counterRpiThingClassId, counterRpiThingActiveLowParamTypeId); + m_activeLowParamTypeIds.insert(gpioButtonRpiThingClassId, gpioButtonRpiThingActiveLowParamTypeId); + + // Beagle bone black + m_activeLowParamTypeIds.insert(gpioOutputBbbThingClassId, gpioOutputBbbThingActiveLowParamTypeId); + m_activeLowParamTypeIds.insert(gpioInputBbbThingClassId, gpioInputBbbThingActiveLowParamTypeId); + m_activeLowParamTypeIds.insert(counterBbbThingClassId, counterBbbThingActiveLowParamTypeId); + } void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) @@ -51,30 +78,34 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) // GPIO Switch if (thing->thingClassId() == gpioOutputRpiThingClassId || thing->thingClassId() == gpioOutputBbbThingClassId) { + // Create and configure gpio - int gpioId = -1; - if (thing->thingClassId() == gpioOutputRpiThingClassId) - gpioId = thing->paramValue(gpioOutputRpiThingGpioParamTypeId).toInt(); - - if (thing->thingClassId() == gpioOutputBbbThingClassId) - gpioId = thing->paramValue(gpioOutputBbbThingGpioParamTypeId).toInt(); - - Gpio *gpio = new Gpio(gpioId, this); + Gpio *gpio = new Gpio(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); if (!gpio->exportGpio()) { qCWarning(dcGpioController()) << "Could not export gpio for thing" << thing->name(); + gpio->deleteLater(); //: Error setting up GPIO thing return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Exporting GPIO failed.")); } if (!gpio->setDirection(Gpio::DirectionOutput)) { qCWarning(dcGpioController()) << "Could not configure output gpio for thing" << thing->name(); + gpio->deleteLater(); //: Error setting up GPIO thing return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Configuring output GPIO failed.")); } + if (!gpio->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool())) { + qCWarning(dcGpioController()) << "Could not configure output gpio for thing" << thing->name(); + gpio->deleteLater(); + //: Error setting up GPIO thing + return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Configuring GPIO active low failed.")); + } + if (!gpio->setValue(Gpio::ValueLow)) { qCWarning(dcGpioController()) << "Could not set gpio value for thing" << thing->name(); + gpio->deleteLater(); //: Error setting up GPIO thing return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Setting GPIO value failed.")); } @@ -92,64 +123,102 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) if (thing->thingClassId() == gpioInputRpiThingClassId || thing->thingClassId() == gpioInputBbbThingClassId) { - int gpioId = -1; - if (thing->thingClassId() == gpioInputRpiThingClassId) - gpioId = thing->paramValue(gpioInputRpiThingGpioParamTypeId).toInt(); - - if (thing->thingClassId() == gpioInputBbbThingClassId) - gpioId = thing->paramValue(gpioInputBbbThingGpioParamTypeId).toInt(); - - GpioMonitor *monitor = new GpioMonitor(gpioId, this); - + GpioMonitor *monitor = new GpioMonitor(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); if (!monitor->enable()) { qCWarning(dcGpioController()) << "Could not enable gpio monitor for thing" << thing->name(); //: Error setting up GPIO thing return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed.")); } - connect(monitor, &GpioMonitor::valueChanged, this, &IntegrationPluginGpio::onGpioValueChanged); + connect(monitor, &GpioMonitor::enabledChanged, thing, [this, thing](bool enabled){ + if (thing->thingClassId() == gpioInputRpiThingClassId) { + thing->setStateValue(gpioInputRpiPowerStateTypeId, enabled); + } else if (thing->thingClassId() == gpioInputBbbThingClassId) { + thing->setStateValue(gpioInputBbbPowerStateTypeId, enabled); + } else if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { + if (enabled) { + m_counterValues[thing->id()] += 1; + } + } + }); m_monitorDevices.insert(monitor, thing); if (thing->thingClassId() == gpioInputRpiThingClassId) - m_raspberryPiGpioMoniors.insert(monitor->gpio()->gpioNumber(), monitor); + m_raspberryPiGpioMoniors.insert(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), monitor); if (thing->thingClassId() == gpioInputBbbThingClassId) - m_beagleboneBlackGpioMoniors.insert(monitor->gpio()->gpioNumber(), monitor); + m_beagleboneBlackGpioMoniors.insert(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), monitor); return info->finish(Thing::ThingErrorNoError); } + // Counter if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { - - int gpioId = -1; - if (thing->thingClassId() == counterRpiThingClassId) - gpioId = thing->paramValue(counterRpiThingGpioParamTypeId).toInt(); - - if (thing->thingClassId() == counterBbbThingClassId) - gpioId = thing->paramValue(counterBbbThingGpioParamTypeId).toInt(); - - GpioMonitor *monitor = new GpioMonitor(gpioId, this); - + GpioMonitor *monitor = new GpioMonitor(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); if (!monitor->enable()) { qCWarning(dcGpioController()) << "Could not enable gpio monitor for thing" << thing->name(); //: Error setting up GPIO thing return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed.")); } - connect(monitor, &GpioMonitor::valueChanged, this, &IntegrationPluginGpio::onGpioValueChanged); + connect(monitor, &GpioMonitor::enabledChanged, thing, [this, thing](bool enabled){ + if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { + if (enabled) { + m_counterValues[thing->id()] += 1; + } + } + }); m_monitorDevices.insert(monitor, thing); if (thing->thingClassId() == counterRpiThingClassId) - m_raspberryPiGpioMoniors.insert(monitor->gpio()->gpioNumber(), monitor); + m_raspberryPiGpioMoniors.insert(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), monitor); if (thing->thingClassId() == counterBbbThingClassId) - m_beagleboneBlackGpioMoniors.insert(monitor->gpio()->gpioNumber(), monitor); + m_beagleboneBlackGpioMoniors.insert(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), monitor); m_counterValues.insert(thing->id(), 0); return info->finish(Thing::ThingErrorNoError); } + + // Button + if (thing->thingClassId() == gpioButtonRpiThingClassId) { + GpioButton *button = new GpioButton(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); + if (!button->enable()) { + qCWarning(dcGpioController()) << "Could not enable button" << button; + button->deleteLater(); + return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO button failed.")); + } + + connect(button, &GpioButton::clicked, this, [this, thing, button](){ + qCDebug(dcGpioController()) << button << "clicked"; + if (thing->thingClassId() == gpioButtonRpiThingClassId) { + emitEvent(Event(gpioButtonRpiPressedEventTypeId, thing->id())); + } else if (thing->thingClassId() == gpioButtonBbbThingClassId) { + emitEvent(Event(gpioButtonBbbPressedEventTypeId, thing->id())); + } + }); + + connect(button, &GpioButton::longPressed, this, [this, thing, button](){ + qCDebug(dcGpioController()) << button << "long pressed"; + if (thing->thingClassId() == gpioButtonRpiThingClassId) { + emitEvent(Event(gpioButtonRpiLongPressedEventTypeId, thing->id())); + } else if (thing->thingClassId() == gpioButtonBbbThingClassId) { + emitEvent(Event(gpioButtonBbbLongPressedEventTypeId, thing->id())); + } + }); + + m_buttonDevices.insert(button, thing); + + if (thing->thingClassId() == gpioButtonRpiThingClassId) + m_raspberryPiGpioButtons.insert(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), button); + + if (thing->thingClassId() == gpioButtonBbbThingClassId) + m_beagleboneBlackGpioButtons.insert(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), button); + } + + return info->finish(Thing::ThingErrorNoError); } @@ -167,7 +236,6 @@ void IntegrationPluginGpio::discoverThings(ThingDiscoveryInfo *info) // Check which board / gpio configuration const ThingClass deviceClass = supportedThings().findById(deviceClassId); if (deviceClass.vendorId() == raspberryPiVendorId) { - // Create the list of available gpios QList gpioDescriptors = raspberryPiGpioDescriptors(); for (int i = 0; i < gpioDescriptors.count(); i++) { @@ -180,6 +248,9 @@ void IntegrationPluginGpio::discoverThings(ThingDiscoveryInfo *info) if (m_raspberryPiGpioMoniors.keys().contains(gpioDescriptor.gpio())) continue; + if (m_raspberryPiGpioButtons.keys().contains(gpioDescriptor.gpio())) + continue; + QString description; if (gpioDescriptor.description().isEmpty()) { description = QString("Pin %1").arg(gpioDescriptor.pin()); @@ -197,11 +268,15 @@ void IntegrationPluginGpio::discoverThings(ThingDiscoveryInfo *info) parameters.append(Param(gpioInputRpiThingGpioParamTypeId, gpioDescriptor.gpio())); parameters.append(Param(gpioInputRpiThingPinParamTypeId, gpioDescriptor.pin())); parameters.append(Param(gpioInputRpiThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == gpioButtonRpiThingClassId) { + parameters.append(Param(gpioButtonRpiThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioButtonRpiThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioButtonRpiThingDescriptionParamTypeId, gpioDescriptor.description())); } descriptor.setParams(parameters); foreach (Thing *existingThing, myThings()) { - if (existingThing->paramValue(gpioOutputRpiThingGpioParamTypeId).toInt() == gpioDescriptor.gpio()) { + if (existingThing->paramValue(m_gpioParamTypeIds.value(deviceClass.id())).toInt() == gpioDescriptor.gpio()) { descriptor.setThingId(existingThing->id()); break; } @@ -243,6 +318,10 @@ void IntegrationPluginGpio::discoverThings(ThingDiscoveryInfo *info) parameters.append(Param(gpioInputBbbThingGpioParamTypeId, gpioDescriptor.gpio())); parameters.append(Param(gpioInputBbbThingPinParamTypeId, gpioDescriptor.pin())); parameters.append(Param(gpioInputBbbThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == gpioButtonBbbThingClassId) { + parameters.append(Param(gpioButtonBbbThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioButtonBbbThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioButtonBbbThingDescriptionParamTypeId, gpioDescriptor.description())); } descriptor.setParams(parameters); @@ -279,14 +358,30 @@ void IntegrationPluginGpio::thingRemoved(Thing *thing) m_monitorDevices.remove(monitor); if (m_raspberryPiGpioMoniors.values().contains(monitor)) - m_raspberryPiGpios.remove(monitor->gpio()->gpioNumber()); + m_raspberryPiGpios.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); if (m_beagleboneBlackGpioMoniors.values().contains(monitor)) - m_beagleboneBlackGpioMoniors.remove(monitor->gpio()->gpioNumber()); + m_beagleboneBlackGpioMoniors.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); delete monitor; } + if (m_buttonDevices.values().contains(thing)) { + GpioButton *button = m_buttonDevices.key(thing); + if (!button) + return; + + m_buttonDevices.remove(button); + + if (m_raspberryPiGpioButtons.values().contains(button)) + m_raspberryPiGpios.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); + + if (m_beagleboneBlackGpioButtons.values().contains(button)) + m_beagleboneBlackGpioButtons.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); + + delete button; + } + if (m_counterValues.contains(thing->id())) { m_counterValues.remove(thing->id()); } @@ -373,12 +468,21 @@ void IntegrationPluginGpio::postSetupThing(Thing *thing) if (!gpio) return; - gpio->setValue(Gpio::ValueLow); + // Note: reset the pin to the last cached value if (thing->thingClassId() == gpioOutputRpiThingClassId) { - thing->setStateValue(gpioOutputRpiPowerStateTypeId, false); + if (thing->stateValue(gpioOutputRpiPowerStateTypeId).toBool()) { + gpio->setValue(Gpio::ValueHigh); + } else { + gpio->setValue(Gpio::ValueLow); + } } + if (thing->thingClassId() == gpioOutputBbbThingClassId) { - thing->setStateValue(gpioOutputBbbPowerStateTypeId, false); + if (thing->stateValue(gpioOutputBbbPowerStateTypeId).toBool()) { + gpio->setValue(Gpio::ValueHigh); + } else { + gpio->setValue(Gpio::ValueLow); + } } } @@ -521,22 +625,3 @@ QList IntegrationPluginGpio::beagleboneBlackGpioDescriptors() gpioDescriptors << GpioDescriptor(89, 30, "P8 - LCD_AC_BIAS_E"); return gpioDescriptors; } - -void IntegrationPluginGpio::onGpioValueChanged(const bool &value) -{ - GpioMonitor *monitor = static_cast(sender()); - - Thing *thing = m_monitorDevices.value(monitor); - if (!thing) - return; - - if (thing->thingClassId() == gpioInputRpiThingClassId) { - thing->setStateValue(gpioInputRpiPowerStateTypeId, value); - } else if (thing->thingClassId() == gpioInputBbbThingClassId) { - thing->setStateValue(gpioInputBbbPowerStateTypeId, value); - } else if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { - if (value) { - m_counterValues[thing->id()] += 1; - } - } -} diff --git a/gpio/integrationplugingpio.h b/gpio/integrationplugingpio.h index 68b396c7..a8cc6718 100644 --- a/gpio/integrationplugingpio.h +++ b/gpio/integrationplugingpio.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2021, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -31,12 +31,14 @@ #ifndef INTEGRATIONPLUGINGPIO_H #define INTEGRATIONPLUGINGPIO_H -#include "hardware/gpio.h" -#include "hardware/gpiomonitor.h" -#include "gpiodescriptor.h" -#include "hardware/gpiomonitor.h" #include "integrations/integrationplugin.h" #include "plugintimer.h" +#include "gpiodescriptor.h" + +// libnymea-gpio +#include "gpio.h" +#include "gpiomonitor.h" +#include "gpiobutton.h" #include @@ -50,6 +52,7 @@ class IntegrationPluginGpio : public IntegrationPlugin public: explicit IntegrationPluginGpio(); + void init() override; void setupThing(ThingSetupInfo *info) override; void discoverThings(ThingDiscoveryInfo *info) override; void thingRemoved(Thing *thing) override; @@ -58,22 +61,26 @@ public: void postSetupThing(Thing *thing) override; private: + QHash m_gpioParamTypeIds; + QHash m_activeLowParamTypeIds; + QHash m_gpioDevices; QHash m_monitorDevices; + QHash m_buttonDevices; QHash m_raspberryPiGpios; QHash m_raspberryPiGpioMoniors; + QHash m_raspberryPiGpioButtons; QHash m_beagleboneBlackGpios; QHash m_beagleboneBlackGpioMoniors; + QHash m_beagleboneBlackGpioButtons; QList raspberryPiGpioDescriptors(); QList beagleboneBlackGpioDescriptors(); PluginTimer *m_counterTimer = nullptr; QHash m_counterValues; -private slots: - void onGpioValueChanged(const bool &value); }; #endif // INTEGRATIONPLUGINGPIO_H diff --git a/gpio/integrationplugingpio.json b/gpio/integrationplugingpio.json index bf3a9bc9..65751413 100644 --- a/gpio/integrationplugingpio.json +++ b/gpio/integrationplugingpio.json @@ -2,19 +2,9 @@ "displayName": "Gpio Controller", "name": "GpioController", "id": "127ead55-996a-44ac-ba82-fc3c634e018a", - "paramTypes": [ - { - "id": "bfb31f88-b481-49e1-9a0a-41b156b64efe", - "name": "longPressTime", - "displayName": "Long press time", - "type": "int", - "unit": "Seconds", - "defaultValue": 2 - } - ], "vendors": [ { - "displayName": "Raspberry Pi 2/3", + "displayName": "Raspberry Pi", "name": "raspberryPi", "id": "f0d00b66-bbd8-4a07-8591-ea48a61b229e", "thingClasses": [ @@ -39,6 +29,13 @@ "type": "int", "defaultValue": -1 }, + { + "id": "4dfddecc-d41c-4b31-bf4a-04297097bd5c", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, { "id": "504798eb-1faa-4703-a57a-2778e4bf9a67", "name": "description", @@ -57,7 +54,8 @@ "writable": true, "displayNameEvent": "Power changed", "displayNameAction": "Set power", - "ioType": "digitalOutput" + "ioType": "digitalOutput", + "cached": true } ] }, @@ -81,6 +79,13 @@ "type": "int", "defaultValue": -1 }, + { + "id": "d877b7cd-0440-4f49-a6d6-5c679d9f3cc3", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, { "id": "720bb37e-56e6-419e-878e-8c80aaf7ce32", "name": "description", @@ -101,6 +106,55 @@ } ] }, + { + "id": "1abd4dad-0757-4160-8df1-75c45bd61e6e", + "displayName": "GPIO Button", + "name": "gpioButtonRpi", + "createMethods": [ "discovery" ], + "interfaces": [ "longpressbutton" ], + "paramTypes": [ + { + "id": "234538be-710d-4a0b-9cb9-ac57b47ab14d", + "name": "gpio", + "displayName": "GPIO", + "type": "int", + "defaultValue": -1 + }, + { + "id": "90735212-d518-43c0-8fe9-aaa5362a512d", + "name": "pin", + "displayName": "Pin number", + "type": "int", + "defaultValue": -1 + }, + { + "id": "ad7b1641-bc7a-46d3-b029-d2f7628eb790", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, + { + "id": "5ea2fbf9-fd20-4bd7-b0ed-08f72f18157f", + "name": "description", + "displayName": "Description", + "type": "QString", + "defaultValue": "-" + } + ], + "eventTypes": [ + { + "id": "28330833-158c-4f99-9f6e-407ee8f29a4e", + "name": "pressed", + "displayName": "Pressed" + }, + { + "id": "5ad39e3d-b155-4091-a7ef-d843c00d75aa", + "name": "longPressed", + "displayName": "Long pressed" + } + ] + }, { "id": "75b13371-a064-47a7-bb82-e9d93a5b5027", "displayName": "Counter", @@ -122,6 +176,13 @@ "type": "int", "defaultValue": -1 }, + { + "id": "2b57c0ed-a7e5-4198-a82a-75c2cf3ca710", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, { "id": "f7b82516-ed2c-4d73-86fa-957b8b6737e4", "name": "description", @@ -170,6 +231,13 @@ "type": "int", "defaultValue": -1 }, + { + "id": "c7114a64-b9de-4d51-a58d-9d5c604a6f32", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, { "id": "760aa4ed-d933-4188-aec8-16285d763aa5", "name": "description", @@ -188,7 +256,8 @@ "writable": true, "displayNameEvent": "Power changed", "displayNameAction": "Set power", - "ioType": "digitalOutput" + "ioType": "digitalOutput", + "cached": true } ] }, @@ -212,6 +281,13 @@ "type": "int", "defaultValue": -1 }, + { + "id": "7b4b7c74-ed0d-4add-8e10-1a356a76c0e7", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, { "id": "da746cde-2380-4ee5-bf2c-017249fcdeef", "name": "description", @@ -232,6 +308,55 @@ } ] }, + { + "id": "4a4b79b9-7e43-4fd7-840f-31108bef0ee2", + "displayName": "GPIO Button", + "name": "gpioButtonBbb", + "createMethods": [ "discovery" ], + "interfaces": [ "longpressbutton" ], + "paramTypes": [ + { + "id": "7a5ad4d6-2aa3-496f-9fb9-ae46eb8b4376", + "name": "gpio", + "displayName": "GPIO", + "type": "int", + "defaultValue": -1 + }, + { + "id": "4c24d8f5-8b87-457f-a64b-aa52f7f81dc0", + "name": "pin", + "displayName": "Pin number", + "type": "int", + "defaultValue": -1 + }, + { + "id": "bd3fefb3-1204-41ed-8452-1b9d11f265a0", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, + { + "id": "fc7850b7-3b9c-4df9-8153-40f3582213ea", + "name": "description", + "displayName": "Description", + "type": "QString", + "defaultValue": "-" + } + ], + "eventTypes": [ + { + "id": "d02b16a8-a242-41f5-b4e0-d3209849f25e", + "name": "pressed", + "displayName": "Pressed" + }, + { + "id": "11ffeeed-23fe-4cd7-bf15-c95c7250448c", + "name": "longPressed", + "displayName": "Long pressed" + } + ] + }, { "id": "3e311ef1-60c4-4b0e-a2fb-186bff9bd792", "displayName": "Counter", @@ -253,6 +378,13 @@ "type": "int", "defaultValue": -1 }, + { + "id": "8745fbd1-d904-4551-93f4-0f923fcee9b5", + "name": "activeLow", + "displayName": "Active low", + "type": "bool", + "defaultValue": false + }, { "id": "cba6a527-9f5c-4c05-8602-60e0c920fd26", "name": "description", diff --git a/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-de.ts b/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-de.ts index 29434158..99deba49 100644 --- a/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-de.ts +++ b/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-de.ts @@ -4,20 +4,14 @@ GpioController - + Gpio Controller The name of the plugin GpioController ({127ead55-996a-44ac-ba82-fc3c634e018a}) GPIO-Controller - - Raspberry Pi 2/3 - The name of the vendor ({f0d00b66-bbd8-4a07-8591-ea48a61b229e}) - Raspberry Pi 2/3 - - - - + + GPIO Output The name of the ThingClass ({75d54a59-f9b0-4bc4-a86c-6b1fc47e0663}) ---------- @@ -25,12 +19,12 @@ The name of the ThingClass ({3885c520-e202-4435-88f6-3c35c362b2e6}) - - - - - - + + + + + + Counter The name of the ParamType (ThingClass: counterBbb, EventType: counter, ID: {fb5181d0-644b-4ab7-afa0-b7ddc8951526}) ---------- @@ -46,8 +40,35 @@ The name of the ThingClass ({75b13371-a064-47a7-bb82-e9d93a5b5027}) - - + + + + + + + + + Active low + The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {8745fbd1-d904-4551-93f4-0f923fcee9b5}) +---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {bd3fefb3-1204-41ed-8452-1b9d11f265a0}) +---------- +The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {7b4b7c74-ed0d-4add-8e10-1a356a76c0e7}) +---------- +The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {c7114a64-b9de-4d51-a58d-9d5c604a6f32}) +---------- +The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {2b57c0ed-a7e5-4198-a82a-75c2cf3ca710}) +---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {ad7b1641-bc7a-46d3-b029-d2f7628eb790}) +---------- +The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {d877b7cd-0440-4f49-a6d6-5c679d9f3cc3}) +---------- +The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {4dfddecc-d41c-4b31-bf4a-04297097bd5c}) + + + + + Counter changed The name of the EventType ({fb5181d0-644b-4ab7-afa0-b7ddc8951526}) of ThingClass counterBbb ---------- @@ -55,101 +76,122 @@ The name of the EventType ({891bc1ce-2f9b-4518-aed9-90e78bc2409e}) of ThingClass - - - - - - + + + + + + + + GPIO The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {68bc0f3b-18c3-4a60-a2df-85bc0605caec}) ---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {7a5ad4d6-2aa3-496f-9fb9-ae46eb8b4376}) +---------- The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {20773255-4576-4c8e-8c8b-051902919761}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {62a9596d-fc7d-4554-9f45-9803635da619}) ---------- The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {a6feb722-1dc9-4262-96b0-96489507508f}) ---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {234538be-710d-4a0b-9cb9-ac57b47ab14d}) +---------- The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {b45ca4a8-c67a-411c-957c-0e78e1f12c0b}) ---------- The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {9eda783f-6d9f-4d39-986d-d2cbfff5a7dd}) - - Long press time - The name of the ParamType (ThingClass: gpioController, Type: plugin, ID: {bfb31f88-b481-49e1-9a0a-41b156b64efe}) - - - - - + + Long pressed - The name of the EventType ({6b439e89-2cac-482a-b012-452c7c665acb}) of ThingClass gpioInputBbb + The name of the EventType ({11ffeeed-23fe-4cd7-bf15-c95c7250448c}) of ThingClass gpioButtonBbb ---------- -The name of the EventType ({0df945d3-38df-4560-b42a-12b05545904d}) of ThingClass gpioInputRpi +The name of the EventType ({5ad39e3d-b155-4091-a7ef-d843c00d75aa}) of ThingClass gpioButtonRpi - - - - - - + + + + + + + + Pin number The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {f9da4a22-b010-4823-9b1c-d1f422c3ad2b}) ---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {4c24d8f5-8b87-457f-a64b-aa52f7f81dc0}) +---------- The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {f383bf1d-3ac0-4808-a82c-18748baf085d}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {14f65be0-ee84-42e4-8fcb-d98a9926a247}) ---------- The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {b2c194bd-1aef-4851-a290-dd45269cc592}) ---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {90735212-d518-43c0-8fe9-aaa5362a512d}) +---------- The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {efd3df4a-d2b6-44f3-9095-7bba07891735}) ---------- The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {2204d278-7bc7-407f-ac82-ce3ae1d5779c}) - - - - - - + + + + + + + + Description The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {cba6a527-9f5c-4c05-8602-60e0c920fd26}) ---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {fc7850b7-3b9c-4df9-8153-40f3582213ea}) +---------- The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {da746cde-2380-4ee5-bf2c-017249fcdeef}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {760aa4ed-d933-4188-aec8-16285d763aa5}) ---------- The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {f7b82516-ed2c-4d73-86fa-957b8b6737e4}) ---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {5ea2fbf9-fd20-4bd7-b0ed-08f72f18157f}) +---------- The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {720bb37e-56e6-419e-878e-8c80aaf7ce32}) ---------- The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {504798eb-1faa-4703-a57a-2778e4bf9a67}) - - + + + Power changed - The name of the EventType ({82b567c6-a33c-484e-b5e7-e04795498d00}) of ThingClass gpioOutputBbb + The name of the EventType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb +---------- +The name of the EventType ({82b567c6-a33c-484e-b5e7-e04795498d00}) of ThingClass gpioOutputBbb ---------- The name of the EventType ({06843766-358e-44b0-8d52-2b46ef98459a}) of ThingClass gpioOutputRpi - - - - - - + + + + + + + + Power - The name of the ParamType (ThingClass: gpioOutputBbb, ActionType: power, ID: {82b567c6-a33c-484e-b5e7-e04795498d00}) + The name of the ParamType (ThingClass: gpioInputBbb, EventType: power, ID: {22440876-417a-4d57-8e01-efe26ef9f235}) +---------- +The name of the StateType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb +---------- +The name of the ParamType (ThingClass: gpioOutputBbb, ActionType: power, ID: {82b567c6-a33c-484e-b5e7-e04795498d00}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, EventType: power, ID: {82b567c6-a33c-484e-b5e7-e04795498d00}) ---------- @@ -163,8 +205,17 @@ The name of the StateType ({06843766-358e-44b0-8d52-2b46ef98459a}) of ThingClass - - + + + GPIO Button + The name of the ThingClass ({4a4b79b9-7e43-4fd7-840f-31108bef0ee2}) +---------- +The name of the ThingClass ({1abd4dad-0757-4160-8df1-75c45bd61e6e}) + + + + + GPIO Input The name of the ThingClass ({ffd2aa29-55cc-4824-ba95-c311784f7824}) ---------- @@ -172,8 +223,29 @@ The name of the ThingClass ({6aff228b-0410-4ef9-9593-51e8639aacea}) - - + + + Powered + The name of the ParamType (ThingClass: gpioInputRpi, EventType: power, ID: {57f1b7cc-26c8-434b-ba04-d3077dc886c8}) +---------- +The name of the StateType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi + + + + + Powered changed + The name of the EventType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi + + + + + Raspberry Pi + The name of the vendor ({f0d00b66-bbd8-4a07-8591-ea48a61b229e}) + + + + + Set power The name of the ActionType ({82b567c6-a33c-484e-b5e7-e04795498d00}) of ThingClass gpioOutputBbb ---------- @@ -181,31 +253,16 @@ The name of the ActionType ({06843766-358e-44b0-8d52-2b46ef98459a}) of ThingClas - - - Pressed changed - The name of the EventType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb ----------- -The name of the EventType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi - - - - - - - + + Pressed - The name of the ParamType (ThingClass: gpioInputBbb, EventType: pressed, ID: {22440876-417a-4d57-8e01-efe26ef9f235}) + The name of the EventType ({d02b16a8-a242-41f5-b4e0-d3209849f25e}) of ThingClass gpioButtonBbb ---------- -The name of the StateType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb ----------- -The name of the ParamType (ThingClass: gpioInputRpi, EventType: pressed, ID: {57f1b7cc-26c8-434b-ba04-d3077dc886c8}) ----------- -The name of the StateType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi +The name of the EventType ({28330833-158c-4f99-9f6e-407ee8f29a4e}) of ThingClass gpioButtonRpi - + Beaglebone Black The name of the vendor ({7835d14b-b455-49bd-9f31-72c6e8c3033d}) @@ -214,27 +271,33 @@ The name of the StateType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass IntegrationPluginGpio - + No GPIOs found on this system. Error setting up GPIO thing - + Exporting GPIO failed. Error setting up GPIO thing - + Configuring output GPIO failed. Error setting up GPIO thing - - - + + Configuring GPIO active low failed. + Error setting up GPIO thing + + + + + + Setting GPIO value failed. Error setting up GPIO thing ---------- @@ -242,20 +305,25 @@ Error executing GPIO action - - + + Enabling GPIO monitor failed. Error setting up GPIO thing - + + Enabling GPIO button failed. + + + + No GPIOs available on this system. Error discovering GPIO devices - + GPIO not found Error executing GPIO action diff --git a/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-en_US.ts b/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-en_US.ts index 09294fde..6fcc4804 100644 --- a/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-en_US.ts +++ b/gpio/translations/127ead55-996a-44ac-ba82-fc3c634e018a-en_US.ts @@ -4,20 +4,14 @@ GpioController - + Gpio Controller The name of the plugin GpioController ({127ead55-996a-44ac-ba82-fc3c634e018a}) - - Raspberry Pi 2/3 - The name of the vendor ({f0d00b66-bbd8-4a07-8591-ea48a61b229e}) - - - - - + + GPIO Output The name of the ThingClass ({75d54a59-f9b0-4bc4-a86c-6b1fc47e0663}) ---------- @@ -25,12 +19,12 @@ The name of the ThingClass ({3885c520-e202-4435-88f6-3c35c362b2e6}) - - - - - - + + + + + + Counter The name of the ParamType (ThingClass: counterBbb, EventType: counter, ID: {fb5181d0-644b-4ab7-afa0-b7ddc8951526}) ---------- @@ -46,8 +40,35 @@ The name of the ThingClass ({75b13371-a064-47a7-bb82-e9d93a5b5027}) - - + + + + + + + + + Active low + The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {8745fbd1-d904-4551-93f4-0f923fcee9b5}) +---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {bd3fefb3-1204-41ed-8452-1b9d11f265a0}) +---------- +The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {7b4b7c74-ed0d-4add-8e10-1a356a76c0e7}) +---------- +The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {c7114a64-b9de-4d51-a58d-9d5c604a6f32}) +---------- +The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {2b57c0ed-a7e5-4198-a82a-75c2cf3ca710}) +---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {ad7b1641-bc7a-46d3-b029-d2f7628eb790}) +---------- +The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {d877b7cd-0440-4f49-a6d6-5c679d9f3cc3}) +---------- +The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {4dfddecc-d41c-4b31-bf4a-04297097bd5c}) + + + + + Counter changed The name of the EventType ({fb5181d0-644b-4ab7-afa0-b7ddc8951526}) of ThingClass counterBbb ---------- @@ -55,101 +76,122 @@ The name of the EventType ({891bc1ce-2f9b-4518-aed9-90e78bc2409e}) of ThingClass - - - - - - + + + + + + + + GPIO The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {68bc0f3b-18c3-4a60-a2df-85bc0605caec}) ---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {7a5ad4d6-2aa3-496f-9fb9-ae46eb8b4376}) +---------- The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {20773255-4576-4c8e-8c8b-051902919761}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {62a9596d-fc7d-4554-9f45-9803635da619}) ---------- The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {a6feb722-1dc9-4262-96b0-96489507508f}) ---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {234538be-710d-4a0b-9cb9-ac57b47ab14d}) +---------- The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {b45ca4a8-c67a-411c-957c-0e78e1f12c0b}) ---------- The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {9eda783f-6d9f-4d39-986d-d2cbfff5a7dd}) - - Long press time - The name of the ParamType (ThingClass: gpioController, Type: plugin, ID: {bfb31f88-b481-49e1-9a0a-41b156b64efe}) - - - - - + + Long pressed - The name of the EventType ({6b439e89-2cac-482a-b012-452c7c665acb}) of ThingClass gpioInputBbb + The name of the EventType ({11ffeeed-23fe-4cd7-bf15-c95c7250448c}) of ThingClass gpioButtonBbb ---------- -The name of the EventType ({0df945d3-38df-4560-b42a-12b05545904d}) of ThingClass gpioInputRpi +The name of the EventType ({5ad39e3d-b155-4091-a7ef-d843c00d75aa}) of ThingClass gpioButtonRpi - - - - - - + + + + + + + + Pin number The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {f9da4a22-b010-4823-9b1c-d1f422c3ad2b}) ---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {4c24d8f5-8b87-457f-a64b-aa52f7f81dc0}) +---------- The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {f383bf1d-3ac0-4808-a82c-18748baf085d}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {14f65be0-ee84-42e4-8fcb-d98a9926a247}) ---------- The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {b2c194bd-1aef-4851-a290-dd45269cc592}) ---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {90735212-d518-43c0-8fe9-aaa5362a512d}) +---------- The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {efd3df4a-d2b6-44f3-9095-7bba07891735}) ---------- The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {2204d278-7bc7-407f-ac82-ce3ae1d5779c}) - - - - - - + + + + + + + + Description The name of the ParamType (ThingClass: counterBbb, Type: thing, ID: {cba6a527-9f5c-4c05-8602-60e0c920fd26}) ---------- +The name of the ParamType (ThingClass: gpioButtonBbb, Type: thing, ID: {fc7850b7-3b9c-4df9-8153-40f3582213ea}) +---------- The name of the ParamType (ThingClass: gpioInputBbb, Type: thing, ID: {da746cde-2380-4ee5-bf2c-017249fcdeef}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, Type: thing, ID: {760aa4ed-d933-4188-aec8-16285d763aa5}) ---------- The name of the ParamType (ThingClass: counterRpi, Type: thing, ID: {f7b82516-ed2c-4d73-86fa-957b8b6737e4}) ---------- +The name of the ParamType (ThingClass: gpioButtonRpi, Type: thing, ID: {5ea2fbf9-fd20-4bd7-b0ed-08f72f18157f}) +---------- The name of the ParamType (ThingClass: gpioInputRpi, Type: thing, ID: {720bb37e-56e6-419e-878e-8c80aaf7ce32}) ---------- The name of the ParamType (ThingClass: gpioOutputRpi, Type: thing, ID: {504798eb-1faa-4703-a57a-2778e4bf9a67}) - - + + + Power changed - The name of the EventType ({82b567c6-a33c-484e-b5e7-e04795498d00}) of ThingClass gpioOutputBbb + The name of the EventType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb +---------- +The name of the EventType ({82b567c6-a33c-484e-b5e7-e04795498d00}) of ThingClass gpioOutputBbb ---------- The name of the EventType ({06843766-358e-44b0-8d52-2b46ef98459a}) of ThingClass gpioOutputRpi - - - - - - + + + + + + + + Power - The name of the ParamType (ThingClass: gpioOutputBbb, ActionType: power, ID: {82b567c6-a33c-484e-b5e7-e04795498d00}) + The name of the ParamType (ThingClass: gpioInputBbb, EventType: power, ID: {22440876-417a-4d57-8e01-efe26ef9f235}) +---------- +The name of the StateType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb +---------- +The name of the ParamType (ThingClass: gpioOutputBbb, ActionType: power, ID: {82b567c6-a33c-484e-b5e7-e04795498d00}) ---------- The name of the ParamType (ThingClass: gpioOutputBbb, EventType: power, ID: {82b567c6-a33c-484e-b5e7-e04795498d00}) ---------- @@ -163,8 +205,17 @@ The name of the StateType ({06843766-358e-44b0-8d52-2b46ef98459a}) of ThingClass - - + + + GPIO Button + The name of the ThingClass ({4a4b79b9-7e43-4fd7-840f-31108bef0ee2}) +---------- +The name of the ThingClass ({1abd4dad-0757-4160-8df1-75c45bd61e6e}) + + + + + GPIO Input The name of the ThingClass ({ffd2aa29-55cc-4824-ba95-c311784f7824}) ---------- @@ -172,8 +223,29 @@ The name of the ThingClass ({6aff228b-0410-4ef9-9593-51e8639aacea}) - - + + + Powered + The name of the ParamType (ThingClass: gpioInputRpi, EventType: power, ID: {57f1b7cc-26c8-434b-ba04-d3077dc886c8}) +---------- +The name of the StateType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi + + + + + Powered changed + The name of the EventType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi + + + + + Raspberry Pi + The name of the vendor ({f0d00b66-bbd8-4a07-8591-ea48a61b229e}) + + + + + Set power The name of the ActionType ({82b567c6-a33c-484e-b5e7-e04795498d00}) of ThingClass gpioOutputBbb ---------- @@ -181,31 +253,16 @@ The name of the ActionType ({06843766-358e-44b0-8d52-2b46ef98459a}) of ThingClas - - - Pressed changed - The name of the EventType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb ----------- -The name of the EventType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi - - - - - - - + + Pressed - The name of the ParamType (ThingClass: gpioInputBbb, EventType: pressed, ID: {22440876-417a-4d57-8e01-efe26ef9f235}) + The name of the EventType ({d02b16a8-a242-41f5-b4e0-d3209849f25e}) of ThingClass gpioButtonBbb ---------- -The name of the StateType ({22440876-417a-4d57-8e01-efe26ef9f235}) of ThingClass gpioInputBbb ----------- -The name of the ParamType (ThingClass: gpioInputRpi, EventType: pressed, ID: {57f1b7cc-26c8-434b-ba04-d3077dc886c8}) ----------- -The name of the StateType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass gpioInputRpi +The name of the EventType ({28330833-158c-4f99-9f6e-407ee8f29a4e}) of ThingClass gpioButtonRpi - + Beaglebone Black The name of the vendor ({7835d14b-b455-49bd-9f31-72c6e8c3033d}) @@ -214,27 +271,33 @@ The name of the StateType ({57f1b7cc-26c8-434b-ba04-d3077dc886c8}) of ThingClass IntegrationPluginGpio - + No GPIOs found on this system. Error setting up GPIO thing - + Exporting GPIO failed. Error setting up GPIO thing - + Configuring output GPIO failed. Error setting up GPIO thing - - - + + Configuring GPIO active low failed. + Error setting up GPIO thing + + + + + + Setting GPIO value failed. Error setting up GPIO thing ---------- @@ -242,20 +305,25 @@ Error executing GPIO action - - + + Enabling GPIO monitor failed. Error setting up GPIO thing - + + Enabling GPIO button failed. + + + + No GPIOs available on this system. Error discovering GPIO devices - + GPIO not found Error executing GPIO action From b2963469458dbe96a3f620a369c77c8658b54f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 4 Sep 2021 16:58:20 +0200 Subject: [PATCH 2/5] Update readme --- gpio/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpio/README.md b/gpio/README.md index 0b6d3249..0ea0f540 100644 --- a/gpio/README.md +++ b/gpio/README.md @@ -2,7 +2,7 @@ This plugin allows to control GPIOs on different boards. -## Raspberry Pi 2/3 +## Raspberry Pi ![Raspberry Pi GPIO](https://raw.githubusercontent.com/guh/nymea-plugins/master/gpio/docs/images/Raspberry-Pi-2-GPIO.png "Raspberry Pi GPIO") From 506a14ea100c10100efcdfd2044ec1a280b4e8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 4 Sep 2021 17:26:10 +0200 Subject: [PATCH 3/5] Add gpio button settings and minor fixes --- gpio/integrationplugingpio.cpp | 37 +++++++++++++++++++++++++++++++-- gpio/integrationplugingpio.json | 34 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/gpio/integrationplugingpio.cpp b/gpio/integrationplugingpio.cpp index 9b86ed81..f77e5ce3 100644 --- a/gpio/integrationplugingpio.cpp +++ b/gpio/integrationplugingpio.cpp @@ -50,6 +50,7 @@ void IntegrationPluginGpio::init() m_gpioParamTypeIds.insert(gpioOutputBbbThingClassId, gpioOutputBbbThingGpioParamTypeId); m_gpioParamTypeIds.insert(gpioInputBbbThingClassId, gpioInputBbbThingGpioParamTypeId); m_gpioParamTypeIds.insert(counterBbbThingClassId, counterBbbThingGpioParamTypeId); + m_gpioParamTypeIds.insert(gpioButtonBbbThingClassId, gpioButtonBbbThingGpioParamTypeId); // Raspberry pi m_activeLowParamTypeIds.insert(gpioOutputRpiThingClassId, gpioOutputRpiThingActiveLowParamTypeId); @@ -61,6 +62,7 @@ void IntegrationPluginGpio::init() m_activeLowParamTypeIds.insert(gpioOutputBbbThingClassId, gpioOutputBbbThingActiveLowParamTypeId); m_activeLowParamTypeIds.insert(gpioInputBbbThingClassId, gpioInputBbbThingActiveLowParamTypeId); m_activeLowParamTypeIds.insert(counterBbbThingClassId, counterBbbThingActiveLowParamTypeId); + m_activeLowParamTypeIds.insert(gpioButtonBbbThingClassId, gpioButtonBbbThingActiveLowParamTypeId); } @@ -122,14 +124,17 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) } if (thing->thingClassId() == gpioInputRpiThingClassId || thing->thingClassId() == gpioInputBbbThingClassId) { - GpioMonitor *monitor = new GpioMonitor(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); + monitor->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool()); if (!monitor->enable()) { qCWarning(dcGpioController()) << "Could not enable gpio monitor for thing" << thing->name(); //: Error setting up GPIO thing + monitor->deleteLater(); return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed.")); } + + connect(monitor, &GpioMonitor::enabledChanged, thing, [this, thing](bool enabled){ if (thing->thingClassId() == gpioInputRpiThingClassId) { thing->setStateValue(gpioInputRpiPowerStateTypeId, enabled); @@ -156,8 +161,10 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) // Counter if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { GpioMonitor *monitor = new GpioMonitor(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); + monitor->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool()); if (!monitor->enable()) { qCWarning(dcGpioController()) << "Could not enable gpio monitor for thing" << thing->name(); + monitor->deleteLater(); //: Error setting up GPIO thing return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed.")); } @@ -183,14 +190,40 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) } // Button - if (thing->thingClassId() == gpioButtonRpiThingClassId) { + if (thing->thingClassId() == gpioButtonRpiThingClassId || thing->thingClassId() == gpioButtonBbbThingClassId) { GpioButton *button = new GpioButton(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); + button->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool()); + if (thing->thingClassId() == gpioButtonRpiThingClassId) { + button->setLongPressedTimeout(thing->setting(gpioButtonRpiSettingsLongPressedTimeoutParamTypeId).toUInt()); + button->setRepeateLongPressed(thing->setting(gpioButtonRpiSettingsRepeateLongPressedParamTypeId).toBool()); + } else if (thing->thingClassId() == gpioButtonBbbThingClassId) { + button->setLongPressedTimeout(thing->setting(gpioButtonBbbSettingsLongPressedTimeoutParamTypeId).toUInt()); + button->setRepeateLongPressed(thing->setting(gpioButtonBbbSettingsRepeateLongPressedParamTypeId).toBool()); + } + if (!button->enable()) { qCWarning(dcGpioController()) << "Could not enable button" << button; button->deleteLater(); return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO button failed.")); } + connect(thing, &Thing::settingChanged, this, [button, thing](const ParamTypeId ¶mTypeId, const QVariant &value){ + qCDebug(dcGpioController()) << button << "settings changed" << paramTypeId.toString() << value; + if (thing->thingClassId() == gpioButtonRpiThingClassId) { + if (paramTypeId == gpioButtonRpiSettingsRepeateLongPressedParamTypeId) { + button->setRepeateLongPressed(value.toBool()); + } else if (paramTypeId == gpioButtonRpiSettingsLongPressedTimeoutParamTypeId) { + button->setLongPressedTimeout(value.toUInt()); + } + } else if (thing->thingClassId() == gpioButtonBbbThingClassId) { + if (paramTypeId == gpioButtonBbbSettingsRepeateLongPressedParamTypeId) { + button->setRepeateLongPressed(value.toBool()); + } else if (paramTypeId == gpioButtonBbbSettingsLongPressedTimeoutParamTypeId) { + button->setLongPressedTimeout(value.toUInt()); + } + } + }); + connect(button, &GpioButton::clicked, this, [this, thing, button](){ qCDebug(dcGpioController()) << button << "clicked"; if (thing->thingClassId() == gpioButtonRpiThingClassId) { diff --git a/gpio/integrationplugingpio.json b/gpio/integrationplugingpio.json index 65751413..559010c7 100644 --- a/gpio/integrationplugingpio.json +++ b/gpio/integrationplugingpio.json @@ -142,6 +142,23 @@ "defaultValue": "-" } ], + "settingsTypes": [ + { + "id": "d826f02e-7528-4ad5-ac71-f49df988114d", + "name": "repeateLongPressed", + "displayName": "Repeat long pressed", + "type": "bool", + "defaultValue": false + }, + { + "id": "46a25783-3e96-4489-a3f0-15236d938f17", + "name": "longPressedTimeout", + "displayName": "Long pressed timeout [ms]", + "type": "uint", + "minValue": 200, + "defaultValue": 250 + } + ], "eventTypes": [ { "id": "28330833-158c-4f99-9f6e-407ee8f29a4e", @@ -344,6 +361,23 @@ "defaultValue": "-" } ], + "settingsTypes": [ + { + "id": "292bf500-b7ab-428b-908c-2fedae295ee2", + "name": "repeateLongPressed", + "displayName": "Repeat long pressed", + "type": "bool", + "defaultValue": false + }, + { + "id": "007be75a-bfcd-4039-b8ab-9bce25421894", + "name": "longPressedTimeout", + "displayName": "Long pressed timeout [ms]", + "type": "uint", + "minValue": 200, + "defaultValue": 250 + } + ], "eventTypes": [ { "id": "d02b16a8-a242-41f5-b4e0-d3209849f25e", From 0bb81cea4ab2adad5e33e4140fbc5eb1546fcdb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 4 Sep 2021 17:40:36 +0200 Subject: [PATCH 4/5] Remove initial set low for output gpio --- gpio/integrationplugingpio.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/gpio/integrationplugingpio.cpp b/gpio/integrationplugingpio.cpp index f77e5ce3..5f598bc3 100644 --- a/gpio/integrationplugingpio.cpp +++ b/gpio/integrationplugingpio.cpp @@ -105,12 +105,7 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Configuring GPIO active low failed.")); } - if (!gpio->setValue(Gpio::ValueLow)) { - qCWarning(dcGpioController()) << "Could not set gpio value for thing" << thing->name(); - gpio->deleteLater(); - //: Error setting up GPIO thing - return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Setting GPIO value failed.")); - } + // Note: the gpio value will be set to the previouse value in post setup m_gpioDevices.insert(gpio, thing); @@ -133,8 +128,6 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed.")); } - - connect(monitor, &GpioMonitor::enabledChanged, thing, [this, thing](bool enabled){ if (thing->thingClassId() == gpioInputRpiThingClassId) { thing->setStateValue(gpioInputRpiPowerStateTypeId, enabled); @@ -501,7 +494,7 @@ void IntegrationPluginGpio::postSetupThing(Thing *thing) if (!gpio) return; - // Note: reset the pin to the last cached value + // Note: restore the pin value to the last cached value if (thing->thingClassId() == gpioOutputRpiThingClassId) { if (thing->stateValue(gpioOutputRpiPowerStateTypeId).toBool()) { gpio->setValue(Gpio::ValueHigh); From 89db26e093ea50294d734cad966518b72b641948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sun, 5 Sep 2021 11:49:32 +0200 Subject: [PATCH 5/5] Fix reconfigure gpio buttons and minor bug fixes --- gpio/integrationplugingpio.cpp | 357 +++++++++++++++++---------------- gpio/integrationplugingpio.h | 6 +- 2 files changed, 186 insertions(+), 177 deletions(-) diff --git a/gpio/integrationplugingpio.cpp b/gpio/integrationplugingpio.cpp index 5f598bc3..eee69e7f 100644 --- a/gpio/integrationplugingpio.cpp +++ b/gpio/integrationplugingpio.cpp @@ -66,6 +66,116 @@ void IntegrationPluginGpio::init() } +void IntegrationPluginGpio::discoverThings(ThingDiscoveryInfo *info) +{ + ThingClassId deviceClassId = info->thingClassId(); + + // Check if GPIOs are available on this platform + if (!Gpio::isAvailable()) { + qCWarning(dcGpioController()) << "There are no GPIOs on this plattform"; + //: Error discovering GPIO devices + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No GPIOs available on this system.")); + } + + // Check which board / gpio configuration + const ThingClass deviceClass = supportedThings().findById(deviceClassId); + if (deviceClass.vendorId() == raspberryPiVendorId) { + // Create the list of available gpios + QList gpioDescriptors = raspberryPiGpioDescriptors(); + for (int i = 0; i < gpioDescriptors.count(); i++) { + const GpioDescriptor gpioDescriptor = gpioDescriptors.at(i); + + QString description; + if (gpioDescriptor.description().isEmpty()) { + description = QString("Pin %1").arg(gpioDescriptor.pin()); + } else { + description = QString("Pin %1 | %2").arg(gpioDescriptor.pin()).arg(gpioDescriptor.description()); + } + + ThingDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description); + ParamList parameters; + if (deviceClass.id() == gpioOutputRpiThingClassId) { + parameters.append(Param(gpioOutputRpiThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioOutputRpiThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioOutputRpiThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == gpioInputRpiThingClassId) { + parameters.append(Param(gpioInputRpiThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioInputRpiThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioInputRpiThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == gpioButtonRpiThingClassId) { + parameters.append(Param(gpioButtonRpiThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioButtonRpiThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioButtonRpiThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == counterRpiThingClassId) { + parameters.append(Param(counterRpiThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(counterRpiThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(counterRpiThingDescriptionParamTypeId, gpioDescriptor.description())); + } + descriptor.setParams(parameters); + + // Set device id for reconfigure + foreach (Thing *existingThing, myThings()) { + if (existingThing->paramValue(m_gpioParamTypeIds.value(deviceClass.id())).toInt() == gpioDescriptor.gpio()) { + descriptor.setThingId(existingThing->id()); + break; + } + } + info->addThingDescriptor(descriptor); + } + + return info->finish(Thing::ThingErrorNoError); + } + + if (deviceClass.vendorId() == beagleboneBlackVendorId) { + + // Create the list of available gpios + QList gpioDescriptors = beagleboneBlackGpioDescriptors(); + for (int i = 0; i < gpioDescriptors.count(); i++) { + const GpioDescriptor gpioDescriptor = gpioDescriptors.at(i); + + QString description; + if (gpioDescriptor.description().isEmpty()) { + description = QString("Pin %1").arg(gpioDescriptor.pin()); + } else { + description = QString("Pin %1 | %2").arg(gpioDescriptor.pin()).arg(gpioDescriptor.description()); + } + + ThingDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description); + ParamList parameters; + if (deviceClass.id() == gpioOutputBbbThingClassId) { + parameters.append(Param(gpioOutputBbbThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioOutputBbbThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioOutputBbbThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == gpioInputBbbThingClassId) { + parameters.append(Param(gpioInputBbbThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioInputBbbThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioInputBbbThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == gpioButtonBbbThingClassId) { + parameters.append(Param(gpioButtonBbbThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(gpioButtonBbbThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(gpioButtonBbbThingDescriptionParamTypeId, gpioDescriptor.description())); + } else if (deviceClass.id() == counterBbbThingClassId) { + parameters.append(Param(counterBbbThingGpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(counterBbbThingPinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(counterBbbThingDescriptionParamTypeId, gpioDescriptor.description())); + } + descriptor.setParams(parameters); + + // Set device id for reconfigure + foreach (Thing *existingThing, myThings()) { + if (existingThing->paramValue(m_gpioParamTypeIds.value(deviceClass.id())).toInt() == gpioDescriptor.gpio()) { + descriptor.setThingId(existingThing->id()); + break; + } + } + + info->addThingDescriptor(descriptor); + } + + return info->finish(Thing::ThingErrorNoError); + } +} + void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) { Thing *thing = info->thing(); @@ -105,7 +215,13 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Configuring GPIO active low failed.")); } - // Note: the gpio value will be set to the previouse value in post setup + // Make sure the pin is initially low, they will be restored in the post setup to the cached state + if (!gpio->setValue(Gpio::ValueLow)) { + qCWarning(dcGpioController()) << "Could not set gpio initially low for thing" << thing->name(); + gpio->deleteLater(); + //: Error setting up GPIO thing + return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Set GPIO low failed.")); + } m_gpioDevices.insert(gpio, thing); @@ -118,6 +234,7 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorNoError); } + // Gpio input if (thing->thingClassId() == gpioInputRpiThingClassId || thing->thingClassId() == gpioInputBbbThingClassId) { GpioMonitor *monitor = new GpioMonitor(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this); monitor->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool()); @@ -128,15 +245,11 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed.")); } - connect(monitor, &GpioMonitor::enabledChanged, thing, [this, thing](bool enabled){ + connect(monitor, &GpioMonitor::enabledChanged, thing, [thing](bool enabled){ if (thing->thingClassId() == gpioInputRpiThingClassId) { thing->setStateValue(gpioInputRpiPowerStateTypeId, enabled); } else if (thing->thingClassId() == gpioInputBbbThingClassId) { thing->setStateValue(gpioInputBbbPowerStateTypeId, enabled); - } else if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { - if (enabled) { - m_counterValues[thing->id()] += 1; - } } }); @@ -200,6 +313,7 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO button failed.")); } + // Settings connect(thing, &Thing::settingChanged, this, [button, thing](const ParamTypeId ¶mTypeId, const QVariant &value){ qCDebug(dcGpioController()) << button << "settings changed" << paramTypeId.toString() << value; if (thing->thingClassId() == gpioButtonRpiThingClassId) { @@ -217,21 +331,22 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) } }); + // Button signals connect(button, &GpioButton::clicked, this, [this, thing, button](){ qCDebug(dcGpioController()) << button << "clicked"; if (thing->thingClassId() == gpioButtonRpiThingClassId) { - emitEvent(Event(gpioButtonRpiPressedEventTypeId, thing->id())); + emit emitEvent(Event(gpioButtonRpiPressedEventTypeId, thing->id())); } else if (thing->thingClassId() == gpioButtonBbbThingClassId) { - emitEvent(Event(gpioButtonBbbPressedEventTypeId, thing->id())); + emit emitEvent(Event(gpioButtonBbbPressedEventTypeId, thing->id())); } }); connect(button, &GpioButton::longPressed, this, [this, thing, button](){ qCDebug(dcGpioController()) << button << "long pressed"; if (thing->thingClassId() == gpioButtonRpiThingClassId) { - emitEvent(Event(gpioButtonRpiLongPressedEventTypeId, thing->id())); + emit emitEvent(Event(gpioButtonRpiLongPressedEventTypeId, thing->id())); } else if (thing->thingClassId() == gpioButtonBbbThingClassId) { - emitEvent(Event(gpioButtonBbbLongPressedEventTypeId, thing->id())); + emit emitEvent(Event(gpioButtonBbbLongPressedEventTypeId, thing->id())); } }); @@ -244,123 +359,75 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info) m_beagleboneBlackGpioButtons.insert(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), button); } - return info->finish(Thing::ThingErrorNoError); } -void IntegrationPluginGpio::discoverThings(ThingDiscoveryInfo *info) +void IntegrationPluginGpio::postSetupThing(Thing *thing) { - ThingClassId deviceClassId = info->thingClassId(); + // Gpio output + if (thing->thingClassId() == gpioOutputRpiThingClassId || thing->thingClassId() == gpioOutputBbbThingClassId) { + Gpio *gpio = m_gpioDevices.key(thing); + if (!gpio) + return; - // Check if GPIOs are available on this platform - if (!Gpio::isAvailable()) { - qCWarning(dcGpioController()) << "There are no GPIOs on this plattform"; - //: Error discovering GPIO devices - return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No GPIOs available on this system.")); + // Note: restore the pin value to the last cached value + if (thing->thingClassId() == gpioOutputRpiThingClassId) { + qCDebug(dcGpioController()) << "Post setup: restore previouse output state" << gpio << thing->stateValue(gpioOutputRpiPowerStateTypeId).toBool(); + if (thing->stateValue(gpioOutputRpiPowerStateTypeId).toBool()) { + gpio->setValue(Gpio::ValueHigh); + } else { + gpio->setValue(Gpio::ValueLow); + } + } + + if (thing->thingClassId() == gpioOutputBbbThingClassId) { + qCDebug(dcGpioController()) << "Post setup: restore previouse output state" << gpio << thing->stateValue(gpioOutputRpiPowerStateTypeId).toBool(); + if (thing->stateValue(gpioOutputBbbPowerStateTypeId).toBool()) { + gpio->setValue(Gpio::ValueHigh); + } else { + gpio->setValue(Gpio::ValueLow); + } + } } - // Check which board / gpio configuration - const ThingClass deviceClass = supportedThings().findById(deviceClassId); - if (deviceClass.vendorId() == raspberryPiVendorId) { - // Create the list of available gpios - QList gpioDescriptors = raspberryPiGpioDescriptors(); - for (int i = 0; i < gpioDescriptors.count(); i++) { - const GpioDescriptor gpioDescriptor = gpioDescriptors.at(i); + // Gpio input + if (thing->thingClassId() == gpioInputRpiThingClassId || thing->thingClassId() == gpioInputBbbThingClassId) { + GpioMonitor *monitor = m_monitorDevices.key(thing); + if (!monitor) + return; - // Offer only gpios which arn't in use already - if (m_raspberryPiGpios.keys().contains(gpioDescriptor.gpio())) - continue; + if (thing->thingClassId() == gpioInputRpiThingClassId) { + thing->setStateValue(gpioInputRpiPowerStateTypeId, monitor->value()); + } else if (thing->thingClassId() == gpioInputBbbThingClassId) { + thing->setStateValue(gpioInputBbbPowerStateTypeId, monitor->value()); + } + } - if (m_raspberryPiGpioMoniors.keys().contains(gpioDescriptor.gpio())) - continue; - - if (m_raspberryPiGpioButtons.keys().contains(gpioDescriptor.gpio())) - continue; - - QString description; - if (gpioDescriptor.description().isEmpty()) { - description = QString("Pin %1").arg(gpioDescriptor.pin()); - } else { - description = QString("Pin %1 | %2").arg(gpioDescriptor.pin()).arg(gpioDescriptor.description()); - } - - ThingDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description); - ParamList parameters; - if (deviceClass.id() == gpioOutputRpiThingClassId) { - parameters.append(Param(gpioOutputRpiThingGpioParamTypeId, gpioDescriptor.gpio())); - parameters.append(Param(gpioOutputRpiThingPinParamTypeId, gpioDescriptor.pin())); - parameters.append(Param(gpioOutputRpiThingDescriptionParamTypeId, gpioDescriptor.description())); - } else if (deviceClass.id() == gpioInputRpiThingClassId) { - parameters.append(Param(gpioInputRpiThingGpioParamTypeId, gpioDescriptor.gpio())); - parameters.append(Param(gpioInputRpiThingPinParamTypeId, gpioDescriptor.pin())); - parameters.append(Param(gpioInputRpiThingDescriptionParamTypeId, gpioDescriptor.description())); - } else if (deviceClass.id() == gpioButtonRpiThingClassId) { - parameters.append(Param(gpioButtonRpiThingGpioParamTypeId, gpioDescriptor.gpio())); - parameters.append(Param(gpioButtonRpiThingPinParamTypeId, gpioDescriptor.pin())); - parameters.append(Param(gpioButtonRpiThingDescriptionParamTypeId, gpioDescriptor.description())); - } - descriptor.setParams(parameters); - - foreach (Thing *existingThing, myThings()) { - if (existingThing->paramValue(m_gpioParamTypeIds.value(deviceClass.id())).toInt() == gpioDescriptor.gpio()) { - descriptor.setThingId(existingThing->id()); - break; + // Counter + if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { + if (!m_counterTimer) { + m_counterTimer = hardwareManager()->pluginTimerManager()->registerTimer(1); + connect(m_counterTimer, &PluginTimer::timeout, this, [this](){ + foreach (Thing *thing, myThings()) { + if (thing->thingClassId() == counterRpiThingClassId) { + int counterValue = m_counterValues.value(thing->id()); + thing->setStateValue(counterRpiCounterStateTypeId, counterValue); + m_counterValues[thing->id()] = 0; + } + if (thing->thingClassId() == counterBbbThingClassId) { + int counterValue = m_counterValues.value(thing->id()); + thing->setStateValue(counterBbbCounterStateTypeId, counterValue); + } } - } - info->addThingDescriptor(descriptor); + }); } - - return info->finish(Thing::ThingErrorNoError); - } - - if (deviceClass.vendorId() == beagleboneBlackVendorId) { - - // Create the list of available gpios - QList gpioDescriptors = beagleboneBlackGpioDescriptors(); - for (int i = 0; i < gpioDescriptors.count(); i++) { - const GpioDescriptor gpioDescriptor = gpioDescriptors.at(i); - - // Offer only gpios which arn't in use already - if (m_beagleboneBlackGpios.keys().contains(gpioDescriptor.gpio())) - continue; - - if (m_beagleboneBlackGpioMoniors.keys().contains(gpioDescriptor.gpio())) - continue; - - QString description; - if (gpioDescriptor.description().isEmpty()) { - description = QString("Pin %1").arg(gpioDescriptor.pin()); - } else { - description = QString("Pin %1 | %2").arg(gpioDescriptor.pin()).arg(gpioDescriptor.description()); - } - - ThingDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description); - ParamList parameters; - if (deviceClass.id() == gpioOutputBbbThingClassId) { - parameters.append(Param(gpioOutputBbbThingGpioParamTypeId, gpioDescriptor.gpio())); - parameters.append(Param(gpioOutputBbbThingPinParamTypeId, gpioDescriptor.pin())); - parameters.append(Param(gpioOutputBbbThingDescriptionParamTypeId, gpioDescriptor.description())); - } else if (deviceClass.id() == gpioInputBbbThingClassId) { - parameters.append(Param(gpioInputBbbThingGpioParamTypeId, gpioDescriptor.gpio())); - parameters.append(Param(gpioInputBbbThingPinParamTypeId, gpioDescriptor.pin())); - parameters.append(Param(gpioInputBbbThingDescriptionParamTypeId, gpioDescriptor.description())); - } else if (deviceClass.id() == gpioButtonBbbThingClassId) { - parameters.append(Param(gpioButtonBbbThingGpioParamTypeId, gpioDescriptor.gpio())); - parameters.append(Param(gpioButtonBbbThingPinParamTypeId, gpioDescriptor.pin())); - parameters.append(Param(gpioButtonBbbThingDescriptionParamTypeId, gpioDescriptor.description())); - } - descriptor.setParams(parameters); - - info->addThingDescriptor(descriptor); - } - - return info->finish(Thing::ThingErrorNoError); } } void IntegrationPluginGpio::thingRemoved(Thing *thing) { - if (m_gpioDevices.values().contains(thing)) { + const QList gpioThings = m_gpioDevices.values(); + if (gpioThings.contains(thing)) { Gpio *gpio = m_gpioDevices.key(thing); if (!gpio) return; @@ -376,7 +443,8 @@ void IntegrationPluginGpio::thingRemoved(Thing *thing) delete gpio; } - if (m_monitorDevices.values().contains(thing)) { + const QList monitorThings = m_monitorDevices.values(); + if (monitorThings.contains(thing)) { GpioMonitor *monitor = m_monitorDevices.key(thing); if (!monitor) return; @@ -384,7 +452,7 @@ void IntegrationPluginGpio::thingRemoved(Thing *thing) m_monitorDevices.remove(monitor); if (m_raspberryPiGpioMoniors.values().contains(monitor)) - m_raspberryPiGpios.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); + m_raspberryPiGpioMoniors.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); if (m_beagleboneBlackGpioMoniors.values().contains(monitor)) m_beagleboneBlackGpioMoniors.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); @@ -392,7 +460,8 @@ void IntegrationPluginGpio::thingRemoved(Thing *thing) delete monitor; } - if (m_buttonDevices.values().contains(thing)) { + const QList buttonThings = m_buttonDevices.values(); + if (buttonThings.contains(thing)) { GpioButton *button = m_buttonDevices.key(thing); if (!button) return; @@ -400,7 +469,7 @@ void IntegrationPluginGpio::thingRemoved(Thing *thing) m_buttonDevices.remove(button); if (m_raspberryPiGpioButtons.values().contains(button)) - m_raspberryPiGpios.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); + m_raspberryPiGpioButtons.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); if (m_beagleboneBlackGpioButtons.values().contains(button)) m_beagleboneBlackGpioButtons.remove(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt()); @@ -487,64 +556,6 @@ void IntegrationPluginGpio::executeAction(ThingActionInfo *info) info->finish(Thing::ThingErrorNoError); } -void IntegrationPluginGpio::postSetupThing(Thing *thing) -{ - if (thing->thingClassId() == gpioOutputRpiThingClassId || thing->thingClassId() == gpioOutputBbbThingClassId) { - Gpio *gpio = m_gpioDevices.key(thing); - if (!gpio) - return; - - // Note: restore the pin value to the last cached value - if (thing->thingClassId() == gpioOutputRpiThingClassId) { - if (thing->stateValue(gpioOutputRpiPowerStateTypeId).toBool()) { - gpio->setValue(Gpio::ValueHigh); - } else { - gpio->setValue(Gpio::ValueLow); - } - } - - if (thing->thingClassId() == gpioOutputBbbThingClassId) { - if (thing->stateValue(gpioOutputBbbPowerStateTypeId).toBool()) { - gpio->setValue(Gpio::ValueHigh); - } else { - gpio->setValue(Gpio::ValueLow); - } - } - } - - if (thing->thingClassId() == gpioInputRpiThingClassId || thing->thingClassId() == gpioInputBbbThingClassId) { - GpioMonitor *monitor = m_monitorDevices.key(thing); - if (!monitor) - return; - - if (thing->thingClassId() == gpioInputRpiThingClassId) { - thing->setStateValue(gpioInputRpiPowerStateTypeId, monitor->value()); - } else if (thing->thingClassId() == gpioInputBbbThingClassId) { - thing->setStateValue(gpioInputBbbPowerStateTypeId, monitor->value()); - } - } - - if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { - if (!m_counterTimer) { - m_counterTimer = hardwareManager()->pluginTimerManager()->registerTimer(1); - connect(m_counterTimer, &PluginTimer::timeout, this, [this] (){ - - foreach (Thing *thing, myThings()) { - if (thing->thingClassId() == counterRpiThingClassId) { - int counterValue = m_counterValues.value(thing->id()); - thing->setStateValue(counterRpiCounterStateTypeId, counterValue); - m_counterValues[thing->id()] = 0; - } - if (thing->thingClassId() == counterBbbThingClassId) { - int counterValue = m_counterValues.value(thing->id()); - thing->setStateValue(counterBbbCounterStateTypeId, counterValue); - } - } - }); - } - } -} - QList IntegrationPluginGpio::raspberryPiGpioDescriptors() { // Note: http://www.raspberrypi-spy.co.uk/wp-content/uploads/2012/06/Raspberry-Pi-GPIO-Layout-Model-B-Plus-rotated-2700x900.png diff --git a/gpio/integrationplugingpio.h b/gpio/integrationplugingpio.h index a8cc6718..ac215d83 100644 --- a/gpio/integrationplugingpio.h +++ b/gpio/integrationplugingpio.h @@ -40,8 +40,6 @@ #include "gpiomonitor.h" #include "gpiobutton.h" -#include - class IntegrationPluginGpio : public IntegrationPlugin { Q_OBJECT @@ -53,12 +51,12 @@ public: explicit IntegrationPluginGpio(); void init() override; - void setupThing(ThingSetupInfo *info) override; void discoverThings(ThingDiscoveryInfo *info) override; + void setupThing(ThingSetupInfo *info) override; + void postSetupThing(Thing *thing) override; void thingRemoved(Thing *thing) override; void executeAction(ThingActionInfo *info) override; - void postSetupThing(Thing *thing) override; private: QHash m_gpioParamTypeIds;