fix long pressed event

master
nymea 2019-08-08 17:19:48 +02:00
parent 9e0afd600a
commit 575203aeaf
3 changed files with 9 additions and 12 deletions

View File

@ -80,6 +80,7 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
connect(nuimo, &Nuimo::rotationValueChanged, this, &DevicePluginSenic::onRotationValueChanged);
connect(nuimo, &Nuimo::connectedChanged, this, &DevicePluginSenic::onConnectedChanged);
connect(nuimo, &Nuimo::deviceInformationChanged, this, &DevicePluginSenic::onDeviceInformationChanged);
connect(nuimo, &Nuimo::batteryValueChanged, this, &DevicePluginSenic::onBatteryValueChanged);
m_nuimos.insert(nuimo, device);
nuimo->bluetoothDevice()->connectDevice();

View File

@ -290,11 +290,7 @@ void Nuimo::printService(QLowEnergyService *service)
void Nuimo::onLongPressTimer()
{
if (m_buttonPressed) {
emit buttonLongPressed();
} else {
emit buttonPressed();
}
emit buttonLongPressed();
}
@ -503,15 +499,16 @@ void Nuimo::onInputServiceStateChanged(const QLowEnergyService::ServiceState &st
void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
{
if (characteristic.uuid() == m_inputButtonCharacteristic.uuid()) {
m_buttonPressed = (bool)value.toHex().toUInt(nullptr, 16);
qCDebug(dcSenic()) << "Button:" << (m_buttonPressed ? "pressed": "released");
if (m_buttonPressed) {
//emit buttonPressed();
bool pressed = (bool)value.toHex().toUInt(nullptr, 16);
qCDebug(dcSenic()) << "Button:" << (pressed ? "pressed": "released");
if (pressed) {
m_longPressTimer->start(m_longPressTime);
} else {
if (!m_longPressTimer->isActive())
if (m_longPressTimer->isActive()) {
m_longPressTimer->stop();
emit buttonLongPressed();
emit buttonPressed();
}
// else the time run out and has the long pressed event emittted
}
return;
}

View File

@ -82,7 +82,6 @@ private:
uint m_rotationValue;
QTimer *m_longPressTimer = nullptr;
int m_longPressTime = 250;
bool m_buttonPressed = false;
void showMatrix(const QByteArray &matrix, const int &seconds);
void printService(QLowEnergyService *service);