Add support for BTLE power sensors

This commit is contained in:
Arto Jantunen
2016-04-24 19:52:46 +03:00
parent 7fdd378d17
commit aa2b45fc08
2 changed files with 17 additions and 1 deletions

View File

@@ -53,6 +53,9 @@ public:
void setBPM(float x) {
telemetry.setHr(x);
}
void setWatts(double watts) {
telemetry.setWatts(watts);
}
private slots:
void addDevice(const QBluetoothDeviceInfo&);

View File

@@ -21,7 +21,8 @@
#include "BT40Controller.h"
QList<QBluetoothUuid> BT40Device::supportedServiceUuids = QList<QBluetoothUuid>()
<< QBluetoothUuid(QBluetoothUuid::HeartRate);
<< QBluetoothUuid(QBluetoothUuid::HeartRate)
<< QBluetoothUuid(QBluetoothUuid::CyclingPower);
BT40Device::BT40Device(QObject *parent, QBluetoothDeviceInfo devinfo) : parent(parent), m_currentDevice(devinfo)
@@ -102,6 +103,10 @@ void BT40Device::serviceStateChanged(QLowEnergyService::ServiceState s)
characteristic = service->characteristic(
QBluetoothUuid(QBluetoothUuid::HeartRateMeasurement));
}
else if (service->serviceUuid() == QBluetoothUuid(QBluetoothUuid::CyclingPower)) {
characteristic = service->characteristic(
QBluetoothUuid(QBluetoothUuid::CyclingPowerMeasurement));
}
if (characteristic.isValid()) {
const QLowEnergyDescriptor notificationDesc = characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
@@ -136,6 +141,14 @@ void BT40Device::updateValue(const QLowEnergyCharacteristic &c,
}
dynamic_cast<BT40Controller*>(parent)->setBPM(hr);
}
else if (c.uuid() == QBluetoothUuid(QBluetoothUuid::CyclingPowerMeasurement)) {
quint16 flags;
ds >> flags;
qint16 tmp_pwr;
ds >> tmp_pwr;
double power = (double) tmp_pwr;
dynamic_cast<BT40Controller*>(parent)->setWatts(power);
}
}
void BT40Device::serviceError(QLowEnergyService::ServiceError e)