added long press event
This commit is contained in:
parent
b995c9f9bb
commit
4072d0f1fc
@ -192,7 +192,6 @@ Device::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId &devic
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,6 +279,12 @@ void DevicePluginGpio::deviceRemoved(Device *device)
|
|||||||
delete monitor;
|
delete monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_longPressTimers.contains(device)) {
|
||||||
|
QTimer *timer = m_longPressTimers.take(device);
|
||||||
|
timer->stop();
|
||||||
|
timer->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_counterValues.contains(device->id())) {
|
if (m_counterValues.contains(device->id())) {
|
||||||
m_counterValues.remove(device->id());
|
m_counterValues.remove(device->id());
|
||||||
}
|
}
|
||||||
@ -370,6 +375,10 @@ void DevicePluginGpio::postSetupDevice(Device *device)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (device->deviceClassId() == gpioInputRpiDeviceClassId || device->deviceClassId() == gpioInputBbbDeviceClassId) {
|
if (device->deviceClassId() == gpioInputRpiDeviceClassId || device->deviceClassId() == gpioInputBbbDeviceClassId) {
|
||||||
|
QTimer *timer = new QTimer(this);
|
||||||
|
timer->setSingleShot(true);
|
||||||
|
m_longPressTimers.insert(device, timer);
|
||||||
|
|
||||||
GpioMonitor *monitor = m_monitorDevices.key(device);
|
GpioMonitor *monitor = m_monitorDevices.key(device);
|
||||||
if (!monitor)
|
if (!monitor)
|
||||||
return;
|
return;
|
||||||
@ -399,8 +408,6 @@ void DevicePluginGpio::postSetupDevice(Device *device)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,9 +529,37 @@ void DevicePluginGpio::onGpioValueChanged(const bool &value)
|
|||||||
if (device->deviceClassId() == gpioInputRpiDeviceClassId) {
|
if (device->deviceClassId() == gpioInputRpiDeviceClassId) {
|
||||||
device->setStateValue(gpioInputRpiPressedStateTypeId, value);
|
device->setStateValue(gpioInputRpiPressedStateTypeId, value);
|
||||||
//start longpresss timer
|
//start longpresss timer
|
||||||
|
QTimer *timer = m_longPressTimers.value(device);
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (device->deviceClassId() == gpioInputBbbDeviceClassId) {
|
} else if (device->deviceClassId() == gpioInputBbbDeviceClassId) {
|
||||||
device->setStateValue(gpioInputBbbPressedStateTypeId, value);
|
device->setStateValue(gpioInputBbbPressedStateTypeId, value);
|
||||||
//start longpress timer
|
//start longpresss timer
|
||||||
|
QTimer *timer = m_longPressTimers.value(device);
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (device->deviceClassId() == counterRpiDeviceClassId || device->deviceClassId() == counterBbbDeviceClassId) {
|
} else if (device->deviceClassId() == counterRpiDeviceClassId || device->deviceClassId() == counterBbbDeviceClassId) {
|
||||||
if (value) {
|
if (value) {
|
||||||
m_counterValues[device->id()] += 1;
|
m_counterValues[device->id()] += 1;
|
||||||
@ -532,3 +567,20 @@ void DevicePluginGpio::onGpioValueChanged(const bool &value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DevicePluginGpio::onLongPressedTimeout()
|
||||||
|
{
|
||||||
|
QTimer *timer = static_cast<QTimer *>(sender());
|
||||||
|
qCDebug(dcGpioController()) << "Button long pressed";
|
||||||
|
timer->stop();
|
||||||
|
Device *device = m_longPressTimers.key(timer);
|
||||||
|
if (!device)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (device->deviceClassId() == gpioInputRpiDeviceClassId){
|
||||||
|
emitEvent(Event(gpioInputRpiLongPressedEventTypeId, device->id()));
|
||||||
|
} else if (device->deviceClassId() == gpioInputBbbDeviceClassId){
|
||||||
|
emitEvent(Event(gpioInputBbbLongPressedEventTypeId, device->id()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
#include "devices/deviceplugin.h"
|
#include "devices/deviceplugin.h"
|
||||||
#include "plugintimer.h"
|
#include "plugintimer.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class DevicePluginGpio : public DevicePlugin
|
class DevicePluginGpio : public DevicePlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -61,10 +63,11 @@ private:
|
|||||||
QList<GpioDescriptor> beagleboneBlackGpioDescriptors();
|
QList<GpioDescriptor> beagleboneBlackGpioDescriptors();
|
||||||
PluginTimer *m_counterTimer = nullptr;
|
PluginTimer *m_counterTimer = nullptr;
|
||||||
QHash<DeviceId, int> m_counterValues;
|
QHash<DeviceId, int> m_counterValues;
|
||||||
|
QHash<Device *, QTimer *> m_longPressTimers;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onGpioValueChanged(const bool &value);
|
void onGpioValueChanged(const bool &value);
|
||||||
|
void onLongPressedTimeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEPLUGINGPIO_H
|
#endif // DEVICEPLUGINGPIO_H
|
||||||
|
|||||||
@ -2,6 +2,16 @@
|
|||||||
"displayName": "Gpio Controller",
|
"displayName": "Gpio Controller",
|
||||||
"name": "GpioController",
|
"name": "GpioController",
|
||||||
"id": "127ead55-996a-44ac-ba82-fc3c634e018a",
|
"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": [
|
"vendors": [
|
||||||
{
|
{
|
||||||
"displayName": "Raspberry Pi 2/3",
|
"displayName": "Raspberry Pi 2/3",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user