added long press event
parent
b995c9f9bb
commit
4072d0f1fc
|
|
@ -192,7 +192,6 @@ Device::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId &devic
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
deviceDescriptors.append(descriptor);
|
||||
}
|
||||
|
||||
|
|
@ -280,6 +279,12 @@ void DevicePluginGpio::deviceRemoved(Device *device)
|
|||
delete monitor;
|
||||
}
|
||||
|
||||
if (m_longPressTimers.contains(device)) {
|
||||
QTimer *timer = m_longPressTimers.take(device);
|
||||
timer->stop();
|
||||
timer->deleteLater();
|
||||
}
|
||||
|
||||
if (m_counterValues.contains(device->id())) {
|
||||
m_counterValues.remove(device->id());
|
||||
}
|
||||
|
|
@ -370,6 +375,10 @@ void DevicePluginGpio::postSetupDevice(Device *device)
|
|||
}
|
||||
|
||||
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);
|
||||
if (!monitor)
|
||||
return;
|
||||
|
|
@ -399,8 +408,6 @@ void DevicePluginGpio::postSetupDevice(Device *device)
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -522,9 +529,37 @@ void DevicePluginGpio::onGpioValueChanged(const bool &value)
|
|||
if (device->deviceClassId() == gpioInputRpiDeviceClassId) {
|
||||
device->setStateValue(gpioInputRpiPressedStateTypeId, value);
|
||||
//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) {
|
||||
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) {
|
||||
if (value) {
|
||||
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 "plugintimer.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
class DevicePluginGpio : public DevicePlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -61,10 +63,11 @@ private:
|
|||
QList<GpioDescriptor> beagleboneBlackGpioDescriptors();
|
||||
PluginTimer *m_counterTimer = nullptr;
|
||||
QHash<DeviceId, int> m_counterValues;
|
||||
QHash<Device *, QTimer *> m_longPressTimers;
|
||||
|
||||
private slots:
|
||||
void onGpioValueChanged(const bool &value);
|
||||
|
||||
void onLongPressedTimeout();
|
||||
};
|
||||
|
||||
#endif // DEVICEPLUGINGPIO_H
|
||||
|
|
|
|||
|
|
@ -2,6 +2,16 @@
|
|||
"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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue