diff --git a/src/Train/BT40Controller.h b/src/Train/BT40Controller.h index 8d7a70a67..1d860f478 100644 --- a/src/Train/BT40Controller.h +++ b/src/Train/BT40Controller.h @@ -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&); diff --git a/src/Train/BT40Device.cpp b/src/Train/BT40Device.cpp index 06efc5bbd..60e12b50d 100644 --- a/src/Train/BT40Device.cpp +++ b/src/Train/BT40Device.cpp @@ -21,7 +21,8 @@ #include "BT40Controller.h" QList BT40Device::supportedServiceUuids = QList() - << 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(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(parent)->setWatts(power); + } } void BT40Device::serviceError(QLowEnergyService::ServiceError e)