flowercare: Add Qt6 support

master
Simon Stürz 2025-08-08 13:32:16 +02:00
parent 3e2dc2940a
commit d46177e1eb
5 changed files with 40 additions and 12 deletions

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -89,7 +89,11 @@ void FlowerCare::onSensorServiceStateChanged(const QLowEnergyService::ServiceSta
}
QByteArray value = batteryFirmwareCharacteristic.value();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QDataStream stream(&value, QDataStream::ReadOnly);
#else
QDataStream stream(&value, QIODevice::ReadOnly);
#endif
stream.setByteOrder(QDataStream::LittleEndian);
stream >> m_batteryLevel;
@ -110,7 +114,11 @@ void FlowerCare::onSensorServiceStateChanged(const QLowEnergyService::ServiceSta
}
// Enable notifications
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QLowEnergyDescriptor notificationDescriptor = m_sensorDataCharacteristic.descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration);
#else
QLowEnergyDescriptor notificationDescriptor = m_sensorDataCharacteristic.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
#endif
m_sensorService->writeDescriptor(notificationDescriptor, QByteArray::fromHex("0100"));
// Read the data manually
@ -122,7 +130,11 @@ void FlowerCare::onSensorServiceStateChanged(const QLowEnergyService::ServiceSta
void FlowerCare::onSensorServiceCharacteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
qCDebug(dcFlowerCare()) << "Characteristic read" << characteristic.uuid().toString() << value.toHex();
#else
qCDebug(dcFlowerCare()) << "Characteristic read" << QString::number(characteristic.handle(), 16) << value.toHex();
#endif
if (characteristic != m_sensorDataCharacteristic) {
return;
}
@ -131,7 +143,11 @@ void FlowerCare::onSensorServiceCharacteristicRead(const QLowEnergyCharacteristi
void FlowerCare::onSensorServiceCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
qCDebug(dcFlowerCare()) << "Notification received" << characteristic.uuid().toString() << value.toHex();
#else
qCDebug(dcFlowerCare()) << "Notification received" << QString::number(characteristic.handle(), 16) << value.toHex();
#endif
if (characteristic != m_sensorDataCharacteristic) {
return;
}
@ -142,9 +158,17 @@ void FlowerCare::onSensorServiceCharacteristicChanged(const QLowEnergyCharacteri
void FlowerCare::printServiceDetails(QLowEnergyService *service) const
{
foreach (const QLowEnergyCharacteristic &characteristic, service->characteristics()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
qCDebug(dcFlowerCare()).nospace() << "C: --> " << characteristic.uuid().toString() << " (" << " Name: " << characteristic.name() << "): " << characteristic.value() << ", " << characteristic.value().toHex();
#else
qCDebug(dcFlowerCare()).nospace() << "C: --> " << characteristic.uuid().toString() << " (" << characteristic.handle() << " Name: " << characteristic.name() << "): " << characteristic.value() << ", " << characteristic.value().toHex();
#endif
foreach (const QLowEnergyDescriptor &descriptor, characteristic.descriptors()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
qCDebug(dcFlowerCare()).nospace() << "D: --> " << descriptor.uuid().toString() << " (" << " Name: " << descriptor.name() << "): " << descriptor.value() << ", " << descriptor.value().toHex();
#else
qCDebug(dcFlowerCare()).nospace() << "D: --> " << descriptor.uuid().toString() << " (" << descriptor.handle() << " Name: " << descriptor.name() << "): " << descriptor.value() << ", " << descriptor.value().toHex();
#endif
}
}
}
@ -152,7 +176,11 @@ void FlowerCare::printServiceDetails(QLowEnergyService *service) const
void FlowerCare::processSensorData(const QByteArray &data)
{
QByteArray copy = data;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QDataStream stream(&copy, QDataStream::ReadOnly);
#else
QDataStream stream(&copy, QIODevice::ReadOnly);
#endif
stream.setByteOrder(QDataStream::LittleEndian);
qint16 temp;
stream >> temp;

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -33,7 +33,7 @@
#include <QObject>
#include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h"
#include <hardware/bluetoothlowenergy/bluetoothlowenergydevice.h>
static QBluetoothUuid sensorServiceUuid = QBluetoothUuid(QUuid("00001204-0000-1000-8000-00805f9b34fb"));

View File

@ -1,8 +1,6 @@
include(../plugins.pri)
QT += bluetooth
TARGET = $$qtLibraryTarget(nymea_integrationpluginflowercare)
QT *= bluetooth
SOURCES += \
integrationpluginflowercare.cpp \

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -37,8 +37,10 @@
* {0000fe95-0000-1000-8000-00805f9b34fb}
* {0000fef5-0000-1000-8000-00805f9b34fb}
*/
#include <hardware/bluetoothlowenergy/bluetoothlowenergymanager.h>
#include "plugininfo.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergymanager.h"
#include "integrationpluginflowercare.h"
#include "flowercare.h"

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -31,12 +31,12 @@
#ifndef INTEGRATIONPLUGINFLOWERCARE_H
#define INTEGRATIONPLUGINFLOWERCARE_H
#include <integrations/integrationplugin.h>
#include <plugintimer.h>
#include <hardware/bluetoothlowenergy/bluetoothlowenergydevice.h>
#include <QPointer>
#include <QHash>
#include "integrations/integrationplugin.h"
#include "plugintimer.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h"
class FlowerCare;