added long press events
This commit is contained in:
parent
3bf9ca94c7
commit
9e0afd600a
@ -73,8 +73,9 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
|
|||||||
BluetoothLowEnergyDevice *bluetoothDevice = hardwareManager()->bluetoothLowEnergyManager()->registerDevice(deviceInfo, QLowEnergyController::RandomAddress);
|
BluetoothLowEnergyDevice *bluetoothDevice = hardwareManager()->bluetoothLowEnergyManager()->registerDevice(deviceInfo, QLowEnergyController::RandomAddress);
|
||||||
|
|
||||||
Nuimo *nuimo = new Nuimo(bluetoothDevice, this);
|
Nuimo *nuimo = new Nuimo(bluetoothDevice, this);
|
||||||
|
nuimo->setLongPressTime(configValue(senicPluginLongPressTimeParamTypeId).toInt());
|
||||||
connect(nuimo, &Nuimo::buttonPressed, this, &DevicePluginSenic::onButtonPressed);
|
connect(nuimo, &Nuimo::buttonPressed, this, &DevicePluginSenic::onButtonPressed);
|
||||||
connect(nuimo, &Nuimo::buttonReleased, this, &DevicePluginSenic::onButtonReleased);
|
connect(nuimo, &Nuimo::buttonLongPressed, this, &DevicePluginSenic::onButtonLongPressed);
|
||||||
connect(nuimo, &Nuimo::swipeDetected, this, &DevicePluginSenic::onSwipeDetected);
|
connect(nuimo, &Nuimo::swipeDetected, this, &DevicePluginSenic::onSwipeDetected);
|
||||||
connect(nuimo, &Nuimo::rotationValueChanged, this, &DevicePluginSenic::onRotationValueChanged);
|
connect(nuimo, &Nuimo::rotationValueChanged, this, &DevicePluginSenic::onRotationValueChanged);
|
||||||
connect(nuimo, &Nuimo::connectedChanged, this, &DevicePluginSenic::onConnectedChanged);
|
connect(nuimo, &Nuimo::connectedChanged, this, &DevicePluginSenic::onConnectedChanged);
|
||||||
@ -194,7 +195,6 @@ void DevicePluginSenic::onConnectedChanged(bool connected)
|
|||||||
{
|
{
|
||||||
Nuimo *nuimo = static_cast<Nuimo *>(sender());
|
Nuimo *nuimo = static_cast<Nuimo *>(sender());
|
||||||
Device *device = m_nuimos.value(nuimo);
|
Device *device = m_nuimos.value(nuimo);
|
||||||
|
|
||||||
device->setStateValue(nuimoConnectedStateTypeId, connected);
|
device->setStateValue(nuimoConnectedStateTypeId, connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,15 +205,21 @@ void DevicePluginSenic::onButtonPressed()
|
|||||||
Device *device = m_nuimos.value(nuimo);
|
Device *device = m_nuimos.value(nuimo);
|
||||||
emitEvent(Event(nuimoPressedEventTypeId, device->id(), ParamList() << Param(nuimoPressedEventButtonNameParamTypeId, "•")));
|
emitEvent(Event(nuimoPressedEventTypeId, device->id(), ParamList() << Param(nuimoPressedEventButtonNameParamTypeId, "•")));
|
||||||
|
|
||||||
if(m_autoSymbolMode) {
|
if (m_autoSymbolMode) {
|
||||||
nuimo->showImage(Nuimo::MatrixType::MatrixTypeCircle);
|
nuimo->showImage(Nuimo::MatrixTypeCircle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DevicePluginSenic::onButtonReleased()
|
void DevicePluginSenic::onButtonLongPressed()
|
||||||
{
|
{
|
||||||
// ENHANCEMENT: user timer to detekt long press events
|
Nuimo *nuimo = static_cast<Nuimo *>(sender());
|
||||||
|
Device *device = m_nuimos.value(nuimo);
|
||||||
|
emitEvent(Event(nuimoLongPressedEventTypeId, device->id()));
|
||||||
|
|
||||||
|
if (m_autoSymbolMode) {
|
||||||
|
nuimo->showImage(Nuimo::MatrixTypeFilledCircle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -284,6 +290,13 @@ void DevicePluginSenic::onPluginConfigurationChanged(const ParamTypeId ¶mTyp
|
|||||||
qCDebug(dcSenic()) << "Auto symbol mode" << (value.toBool() ? "enabled." : "disabled.");
|
qCDebug(dcSenic()) << "Auto symbol mode" << (value.toBool() ? "enabled." : "disabled.");
|
||||||
m_autoSymbolMode = value.toBool();
|
m_autoSymbolMode = value.toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (paramTypeId == senicPluginLongPressTimeParamTypeId) {
|
||||||
|
qCDebug(dcSenic()) << "Long press time" << value.toUInt();
|
||||||
|
foreach(Nuimo *nuimo, m_nuimos.keys()) {
|
||||||
|
nuimo->setLongPressTime(value.toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginSenic::onBatteryValueChanged(const uint &percentage)
|
void DevicePluginSenic::onBatteryValueChanged(const uint &percentage)
|
||||||
|
|||||||
@ -59,7 +59,7 @@ private slots:
|
|||||||
void onConnectedChanged(bool connected);
|
void onConnectedChanged(bool connected);
|
||||||
void onBatteryValueChanged(const uint &percentage);
|
void onBatteryValueChanged(const uint &percentage);
|
||||||
void onButtonPressed();
|
void onButtonPressed();
|
||||||
void onButtonReleased();
|
void onButtonLongPressed();
|
||||||
void onSwipeDetected(const Nuimo::SwipeDirection &direction);
|
void onSwipeDetected(const Nuimo::SwipeDirection &direction);
|
||||||
void onRotationValueChanged(const uint &value);
|
void onRotationValueChanged(const uint &value);
|
||||||
void onDeviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision);
|
void onDeviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision);
|
||||||
|
|||||||
@ -9,6 +9,13 @@
|
|||||||
"displayName": "Automatically display symbols",
|
"displayName": "Automatically display symbols",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": true
|
"defaultValue": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "f9900dfe-310b-462b-b09d-a999df441075",
|
||||||
|
"name": "longPressTime",
|
||||||
|
"displayName": "Long press time",
|
||||||
|
"type": "int",
|
||||||
|
"defaultValue": 250
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"vendors": [
|
"vendors": [
|
||||||
@ -22,7 +29,7 @@
|
|||||||
"name": "nuimo",
|
"name": "nuimo",
|
||||||
"displayName": "Nuimo",
|
"displayName": "Nuimo",
|
||||||
"createMethods": ["discovery"],
|
"createMethods": ["discovery"],
|
||||||
"interfaces": ["simplemultibutton", "connectable", "batterylevel"],
|
"interfaces": ["simplemultibutton", "longpressbutton", "connectable", "batterylevel"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
{
|
||||||
"id": "71553f6a-2ed4-4896-bb7b-52e7dca948b2",
|
"id": "71553f6a-2ed4-4896-bb7b-52e7dca948b2",
|
||||||
@ -141,6 +148,11 @@
|
|||||||
"allowedValues": ["•", "←", "↑", "→", "↓"]
|
"allowedValues": ["•", "←", "↑", "→", "↓"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "a2f4add5-f76a-4dca-ae68-4107533bee0e",
|
||||||
|
"name": "longPressed",
|
||||||
|
"displayName": "Button long pressed"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,12 @@ Nuimo::Nuimo(BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent) :
|
|||||||
{
|
{
|
||||||
connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::connectedChanged, this, &Nuimo::onConnectedChanged);
|
connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::connectedChanged, this, &Nuimo::onConnectedChanged);
|
||||||
connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::servicesDiscoveryFinished, this, &Nuimo::onServiceDiscoveryFinished);
|
connect(m_bluetoothDevice, &BluetoothLowEnergyDevice::servicesDiscoveryFinished, this, &Nuimo::onServiceDiscoveryFinished);
|
||||||
|
|
||||||
|
if (!m_longPressTimer) {
|
||||||
|
m_longPressTimer = new QTimer(this);
|
||||||
|
m_longPressTimer->setSingleShot(true);
|
||||||
|
}
|
||||||
|
connect(m_longPressTimer, &QTimer::timeout, this, &Nuimo::onLongPressTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -210,6 +216,19 @@ void Nuimo::showImage(const Nuimo::MatrixType &matrixType)
|
|||||||
" ");
|
" ");
|
||||||
time = 5;
|
time = 5;
|
||||||
break;
|
break;
|
||||||
|
case MatrixTypeFilledCircle:
|
||||||
|
matrix = QByteArray(
|
||||||
|
" "
|
||||||
|
" "
|
||||||
|
" *** "
|
||||||
|
" ***** "
|
||||||
|
" ***** "
|
||||||
|
" ***** "
|
||||||
|
" *** "
|
||||||
|
" "
|
||||||
|
" ");
|
||||||
|
time = 5;
|
||||||
|
break;
|
||||||
case MatrixTypeLight:
|
case MatrixTypeLight:
|
||||||
matrix = QByteArray(
|
matrix = QByteArray(
|
||||||
" "
|
" "
|
||||||
@ -228,6 +247,11 @@ void Nuimo::showImage(const Nuimo::MatrixType &matrixType)
|
|||||||
showMatrix(matrix, time);
|
showMatrix(matrix, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Nuimo::setLongPressTime(int milliSeconds)
|
||||||
|
{
|
||||||
|
m_longPressTime = milliSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
void Nuimo::showMatrix(const QByteArray &matrix, const int &seconds)
|
void Nuimo::showMatrix(const QByteArray &matrix, const int &seconds)
|
||||||
{
|
{
|
||||||
if (!m_ledMatrixService)
|
if (!m_ledMatrixService)
|
||||||
@ -264,11 +288,22 @@ void Nuimo::printService(QLowEnergyService *service)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Nuimo::onLongPressTimer()
|
||||||
|
{
|
||||||
|
if (m_buttonPressed) {
|
||||||
|
emit buttonLongPressed();
|
||||||
|
} else {
|
||||||
|
emit buttonPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Nuimo::onConnectedChanged(const bool &connected)
|
void Nuimo::onConnectedChanged(const bool &connected)
|
||||||
{
|
{
|
||||||
qCDebug(dcSenic()) << m_bluetoothDevice->name() << m_bluetoothDevice->address().toString() << (connected ? "connected" : "disconnected");
|
qCDebug(dcSenic()) << m_bluetoothDevice->name() << m_bluetoothDevice->address().toString() << (connected ? "connected" : "disconnected");
|
||||||
|
|
||||||
|
m_longPressTimer->stop();
|
||||||
emit connectedChanged(connected);
|
emit connectedChanged(connected);
|
||||||
|
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
@ -468,12 +503,15 @@ void Nuimo::onInputServiceStateChanged(const QLowEnergyService::ServiceState &st
|
|||||||
void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
|
void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
|
||||||
{
|
{
|
||||||
if (characteristic.uuid() == m_inputButtonCharacteristic.uuid()) {
|
if (characteristic.uuid() == m_inputButtonCharacteristic.uuid()) {
|
||||||
bool pressed = (bool)value.toHex().toUInt(nullptr, 16);
|
m_buttonPressed = (bool)value.toHex().toUInt(nullptr, 16);
|
||||||
qCDebug(dcSenic()) << "Button:" << (pressed ? "pressed": "released");
|
qCDebug(dcSenic()) << "Button:" << (m_buttonPressed ? "pressed": "released");
|
||||||
if (pressed) {
|
if (m_buttonPressed) {
|
||||||
emit buttonPressed();
|
//emit buttonPressed();
|
||||||
|
m_longPressTimer->start(m_longPressTime);
|
||||||
} else {
|
} else {
|
||||||
emit buttonReleased();
|
if (!m_longPressTimer->isActive())
|
||||||
|
m_longPressTimer->stop();
|
||||||
|
emit buttonLongPressed();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
#define NUIMO_H
|
#define NUIMO_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
#include <QBluetoothUuid>
|
#include <QBluetoothUuid>
|
||||||
|
|
||||||
#include "typeutils.h"
|
#include "typeutils.h"
|
||||||
@ -53,14 +54,15 @@ public:
|
|||||||
MatrixTypeNext,
|
MatrixTypeNext,
|
||||||
MatrixTypePrevious,
|
MatrixTypePrevious,
|
||||||
MatrixTypeCircle,
|
MatrixTypeCircle,
|
||||||
|
MatrixTypeFilledCircle,
|
||||||
MatrixTypeLight
|
MatrixTypeLight
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Nuimo(BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent = nullptr);
|
explicit Nuimo(BluetoothLowEnergyDevice *bluetoothDevice, QObject *parent = nullptr);
|
||||||
|
|
||||||
BluetoothLowEnergyDevice *bluetoothDevice();
|
BluetoothLowEnergyDevice *bluetoothDevice();
|
||||||
|
|
||||||
void showImage(const MatrixType &matrixType);
|
void showImage(const MatrixType &matrixType);
|
||||||
|
void setLongPressTime(int milliSeconds);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BluetoothLowEnergyDevice *m_bluetoothDevice = nullptr;
|
BluetoothLowEnergyDevice *m_bluetoothDevice = nullptr;
|
||||||
@ -78,14 +80,18 @@ private:
|
|||||||
QLowEnergyCharacteristic m_inputRotationCharacteristic;
|
QLowEnergyCharacteristic m_inputRotationCharacteristic;
|
||||||
|
|
||||||
uint m_rotationValue;
|
uint m_rotationValue;
|
||||||
|
QTimer *m_longPressTimer = nullptr;
|
||||||
|
int m_longPressTime = 250;
|
||||||
|
bool m_buttonPressed = false;
|
||||||
|
|
||||||
void showMatrix(const QByteArray &matrix, const int &seconds);
|
void showMatrix(const QByteArray &matrix, const int &seconds);
|
||||||
void printService(QLowEnergyService *service);
|
void printService(QLowEnergyService *service);
|
||||||
|
void onLongPressTimer();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectedChanged(bool connected);
|
void connectedChanged(bool connected);
|
||||||
void buttonPressed();
|
void buttonPressed();
|
||||||
void buttonReleased();
|
void buttonLongPressed();
|
||||||
void batteryValueChanged(const uint &percentage);
|
void batteryValueChanged(const uint &percentage);
|
||||||
void swipeDetected(const SwipeDirection &direction);
|
void swipeDetected(const SwipeDirection &direction);
|
||||||
void rotationValueChanged(const uint &value);
|
void rotationValueChanged(const uint &value);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user