From 02eb9c67283caa784e76574c8abdb45edc7e7584 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 17 Jan 2021 15:43:23 +0100 Subject: [PATCH] GPIO: Remove button interface from GPIO input That doesn't make sense in most cases... --- gpio/integrationplugingpio.cpp | 66 ++------------------------------- gpio/integrationplugingpio.h | 2 - gpio/integrationplugingpio.json | 28 +++----------- 3 files changed, 10 insertions(+), 86 deletions(-) diff --git a/gpio/integrationplugingpio.cpp b/gpio/integrationplugingpio.cpp index 5b66f01a..08fd6a7f 100644 --- a/gpio/integrationplugingpio.cpp +++ b/gpio/integrationplugingpio.cpp @@ -287,12 +287,6 @@ void IntegrationPluginGpio::thingRemoved(Thing *thing) delete monitor; } - if (m_longPressTimers.contains(thing)) { - QTimer *timer = m_longPressTimers.take(thing); - timer->stop(); - timer->deleteLater(); - } - if (m_counterValues.contains(thing->id())) { m_counterValues.remove(thing->id()); } @@ -389,18 +383,14 @@ void IntegrationPluginGpio::postSetupThing(Thing *thing) } if (thing->thingClassId() == gpioInputRpiThingClassId || thing->thingClassId() == gpioInputBbbThingClassId) { - QTimer *timer = new QTimer(this); - timer->setSingleShot(true); - m_longPressTimers.insert(thing, timer); - GpioMonitor *monitor = m_monitorDevices.key(thing); if (!monitor) return; if (thing->thingClassId() == gpioInputRpiThingClassId) { - thing->setStateValue(gpioInputRpiPressedStateTypeId, monitor->value()); + thing->setStateValue(gpioInputRpiPowerStateTypeId, monitor->value()); } else if (thing->thingClassId() == gpioInputBbbThingClassId) { - thing->setStateValue(gpioInputBbbPressedStateTypeId, monitor->value()); + thing->setStateValue(gpioInputBbbPowerStateTypeId, monitor->value()); } } @@ -541,60 +531,12 @@ void IntegrationPluginGpio::onGpioValueChanged(const bool &value) return; if (thing->thingClassId() == gpioInputRpiThingClassId) { - thing->setStateValue(gpioInputRpiPressedStateTypeId, value); - //start longpresss timer - QTimer *timer = m_longPressTimers.value(thing); - if (!timer){ - qWarning(dcGpioController()) << "Long press timer not available"; - return; - } - if (value) { - int seconds = configValue( gpioControllerPluginLongPressTimeParamTypeId).toInt(); - timer->start(seconds * 1000); - } else { - if (timer->isActive()) { - timer->stop(); - //emit timer pressed - } - } + thing->setStateValue(gpioInputRpiPowerStateTypeId, value); } else if (thing->thingClassId() == gpioInputBbbThingClassId) { - thing->setStateValue(gpioInputBbbPressedStateTypeId, value); - //start longpresss timer - QTimer *timer = m_longPressTimers.value(thing); - if (!timer){ - qWarning(dcGpioController()) << "Long press timer not available"; - return; - } - if (value) { - int seconds = configValue( gpioControllerPluginLongPressTimeParamTypeId).toInt(); - timer->start(seconds * 1000); - } else { - if (timer->isActive()) { - timer->stop(); - //emit timer pressed - } - } + thing->setStateValue(gpioInputBbbPowerStateTypeId, value); } else if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) { if (value) { m_counterValues[thing->id()] += 1; } } } - - -void IntegrationPluginGpio::onLongPressedTimeout() -{ - QTimer *timer = static_cast(sender()); - qCDebug(dcGpioController()) << "Button long pressed"; - timer->stop(); - Thing *thing = m_longPressTimers.key(timer); - if (!thing) - return; - - if (thing->thingClassId() == gpioInputRpiThingClassId){ - emitEvent(Event(gpioInputRpiLongPressedEventTypeId, thing->id())); - } else if (thing->thingClassId() == gpioInputBbbThingClassId){ - emitEvent(Event(gpioInputBbbLongPressedEventTypeId, thing->id())); - } -} - diff --git a/gpio/integrationplugingpio.h b/gpio/integrationplugingpio.h index 1987a8a7..68b396c7 100644 --- a/gpio/integrationplugingpio.h +++ b/gpio/integrationplugingpio.h @@ -71,11 +71,9 @@ private: QList beagleboneBlackGpioDescriptors(); PluginTimer *m_counterTimer = nullptr; QHash m_counterValues; - QHash m_longPressTimers; private slots: void onGpioValueChanged(const bool &value); - void onLongPressedTimeout(); }; #endif // INTEGRATIONPLUGINGPIO_H diff --git a/gpio/integrationplugingpio.json b/gpio/integrationplugingpio.json index 77c28a2d..bf3a9bc9 100644 --- a/gpio/integrationplugingpio.json +++ b/gpio/integrationplugingpio.json @@ -66,7 +66,6 @@ "displayName": "GPIO Input", "name": "gpioInputRpi", "createMethods": ["discovery"], - "interfaces": ["longpressbutton"], "paramTypes": [ { "id": "b45ca4a8-c67a-411c-957c-0e78e1f12c0b", @@ -93,20 +92,13 @@ "stateTypes": [ { "id": "57f1b7cc-26c8-434b-ba04-d3077dc886c8", - "name": "pressed", - "displayName": "Pressed", + "name": "power", + "displayName": "Powered", "type": "bool", "defaultValue": false, - "displayNameEvent": "Pressed changed", + "displayNameEvent": "Powered changed", "ioType": "digitalInput" } - ], - "eventTypes": [ - { - "id": "0df945d3-38df-4560-b42a-12b05545904d", - "name": "longPressed", - "displayName": "Long pressed" - } ] }, { @@ -205,7 +197,6 @@ "displayName": "GPIO Input", "name": "gpioInputBbb", "createMethods": ["discovery"], - "interfaces": ["longpressbutton"], "paramTypes": [ { "id": "20773255-4576-4c8e-8c8b-051902919761", @@ -232,20 +223,13 @@ "stateTypes": [ { "id": "22440876-417a-4d57-8e01-efe26ef9f235", - "name": "pressed", - "displayName": "Pressed", + "name": "power", + "displayName": "Power", "type": "bool", "defaultValue": false, - "displayNameEvent": "Pressed changed", + "displayNameEvent": "Power changed", "ioType": "digitalInput" } - ], - "eventTypes": [ - { - "id": "6b439e89-2cac-482a-b012-452c7c665acb", - "name": "longPressed", - "displayName": "Long pressed" - } ] }, {