Skip to content

Commit

Permalink
Garmin Cadence Sensor not sending data (Issue #1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoviola-systemelectronics committed Oct 18, 2023
1 parent 64d40b5 commit 8d8b1c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/cscbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ void cscbike::update() {
/*initDone*/) {
update_metrics(true, watts());

if(lastGoodCadence.secsTo(QDateTime::currentDateTime()) > 5 && !charNotified) {
readMethod = true;
qDebug() << "no cadence for 5 secs, switching to reading method";
}

if(readMethod && cadenceService) {
cadenceService->readCharacteristic(cadenceChar);
}

// updating the treadmill console every second
if (sec1Update++ == (500 / refresh->interval())) {
sec1Update = 0;
Expand Down Expand Up @@ -141,6 +150,8 @@ void cscbike::characteristicChanged(const QLowEnergyCharacteristic &characterist
double _WheelRevs = 0;
uint8_t battery = 0;

charNotified = true;

emit debug(QStringLiteral(" << ") + newValue.toHex(' '));

if (characteristic.uuid() == QBluetoothUuid((quint16)0x2A19)) {
Expand Down Expand Up @@ -311,8 +322,16 @@ void cscbike::stateChanged(QLowEnergyService::ServiceState state) {

qDebug() << QStringLiteral("all services discovered!");

QBluetoothUuid CyclingSpeedAndCadence(QBluetoothUuid::CyclingSpeedAndCadence);

for (QLowEnergyService *s : qAsConst(gattCommunicationChannelService)) {
if (s->state() == QLowEnergyService::ServiceDiscovered) {

if(s->serviceUuid() == CyclingSpeedAndCadence) {
qDebug() << "CyclingSpeedAndCadence found";
cadenceService = s;
}

// establish hook into notifications
connect(s, &QLowEnergyService::characteristicChanged, this, &cscbike::characteristicChanged);
connect(s, &QLowEnergyService::characteristicWritten, this, &cscbike::characteristicWritten);
Expand All @@ -327,7 +346,11 @@ void cscbike::stateChanged(QLowEnergyService::ServiceState state) {

auto characteristics_list = s->characteristics();
for (const QLowEnergyCharacteristic &c : qAsConst(characteristics_list)) {
qDebug() << QStringLiteral("char uuid") << c.uuid() << QStringLiteral("handle") << c.handle();
if(c.uuid() == QBluetoothUuid((quint16)0x2A5B)) {
qDebug() << "CyclingSpeedAndCadence char found";
cadenceChar = c;
}
qDebug() << QStringLiteral("char uuid") << c.uuid() << QStringLiteral("handle") << c.handle() << QStringLiteral("properties") << c.properties();
auto descriptors_list = c.descriptors();
for (const QLowEnergyDescriptor &d : qAsConst(descriptors_list)) {
qDebug() << QStringLiteral("descriptor uuid") << d.uuid() << QStringLiteral("handle") << d.handle();
Expand Down Expand Up @@ -424,6 +447,8 @@ void cscbike::characteristicWritten(const QLowEnergyCharacteristic &characterist

void cscbike::characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue) {
qDebug() << QStringLiteral("characteristicRead ") << characteristic.uuid() << newValue.toHex(' ');

characteristicChanged(characteristic, newValue);
}

void cscbike::serviceScanDone(void) {
Expand Down
6 changes: 5 additions & 1 deletion src/cscbike.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ class cscbike : public bike {
QTimer *refresh;

QList<QLowEnergyService *> gattCommunicationChannelService;
// QLowEnergyCharacteristic gattNotify1Characteristic;
QLowEnergyService* cadenceService = nullptr;
QLowEnergyCharacteristic cadenceChar;

uint8_t sec1Update = 0;
QByteArray lastPacket;
QDateTime lastRefreshCharacteristicChanged = QDateTime::currentDateTime();
QDateTime lastGoodCadence = QDateTime::currentDateTime();
uint8_t firstStateChanged = 0;
bool charNotified = false;

bool initDone = false;
bool initRequest = false;
Expand All @@ -62,6 +64,8 @@ class cscbike : public bike {
bool noHeartService = false;
bool noVirtualDevice = false;

bool readMethod = false;

uint16_t oldLastCrankEventTime = 0;
uint16_t oldCrankRevs = 0;

Expand Down

0 comments on commit 8d8b1c1

Please sign in to comment.