Skip to content

Commit c2b0ebb

Browse files
committed
Solution to get Octane Zero Runner ZR8 Elliptical working with Zwift #1338
1 parent 68a8169 commit c2b0ebb

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ google_test/*
4848
!build-qdomyos-zwift-Qt_*_for_iOS-Debug # Needed for Apple Watch
4949
src/inner_templates/googlemaps/cesium-key.js
5050
*.autosave
51+
.vscode/settings.json

src/octanetreadmill.cpp

+37-4
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ octanetreadmill::octanetreadmill(uint32_t pollDeviceTime, bool noConsole, bool n
174174
actualPaceSign.append(0x23);
175175
actualPace2Sign.append(0x01);
176176
actualPace2Sign.append(0x23);
177+
cadenceSign.append(0x2c);
178+
cadenceSign.append(0x01);
179+
cadenceSign.append(0x3A);
177180

178181
m_watt.setType(metric::METRIC_WATT);
179182
Speed.setType(metric::METRIC_SPEED);
@@ -337,14 +340,28 @@ void octanetreadmill::characteristicChanged(const QLowEnergyCharacteristic &char
337340

338341
emit packetReceived();
339342

340-
if (lastTimeCharacteristicChanged.secsTo(QDateTime::currentDateTime()) > 5) {
343+
if (ZR8 == false && lastTimeCharacteristicChanged.secsTo(QDateTime::currentDateTime()) > 5) {
341344
emit debug(QStringLiteral("resetting speed"));
342345
Speed = 0;
346+
Cadence = 0;
347+
} else if(ZR8 == true && Speed.lastChanged().secsTo(QDateTime::currentDateTime()) > 15 && Cadence.lastChanged().secsTo(QDateTime::currentDateTime()) > 15) {
348+
emit debug(QStringLiteral("resetting speed"));
349+
Speed = 0;
350+
Cadence = 0;
343351
}
344352

345353
if ((newValue.length() != 20))
346354
return;
347355

356+
if(ZR8 && newValue.contains(cadenceSign)) {
357+
int16_t i = newValue.indexOf(cadenceSign) + 3;
358+
359+
if (i >= newValue.length())
360+
return;
361+
362+
Cadence = ((uint8_t)packet.at(i));
363+
}
364+
348365
if ((uint8_t)newValue[0] == 0xa5 && newValue[1] == 0x17)
349366
return;
350367

@@ -368,8 +385,16 @@ void octanetreadmill::characteristicChanged(const QLowEnergyCharacteristic &char
368385
else
369386
#endif
370387
{
371-
/*if(heartRateBeltName.startsWith("Disabled"))
372-
Heart = value.at(18);*/
388+
#ifdef Q_OS_IOS
389+
#ifndef IO_UNDER_QT
390+
lockscreen h;
391+
long appleWatchHeartRate = h.heartRate();
392+
h.setKcal(KCal.value());
393+
h.setDistance(Distance.value());
394+
Heart = appleWatchHeartRate;
395+
debug("Current Heart from Apple Watch: " + QString::number(appleWatchHeartRate));
396+
#endif
397+
#endif
373398
}
374399
emit debug(QStringLiteral("Current speed: ") + QString::number(speed));
375400

@@ -404,7 +429,9 @@ void octanetreadmill::characteristicChanged(const QLowEnergyCharacteristic &char
404429
(1000.0 / (lastTimeCharacteristicChanged.msecsTo(QDateTime::currentDateTime()))));
405430
}
406431

407-
cadenceFromAppleWatch();
432+
// ZR8 has builtin cadence sensor
433+
if(!ZR8)
434+
cadenceFromAppleWatch();
408435

409436
emit debug(QStringLiteral("Current Distance Calculated: ") + QString::number(Distance.value()));
410437
emit debug(QStringLiteral("Current KCal: ") + QString::number(KCal.value()));
@@ -504,6 +531,12 @@ void octanetreadmill::deviceDiscovered(const QBluetoothDeviceInfo &device) {
504531
device.address().toString() + ')');
505532
{
506533
bluetoothDevice = device;
534+
535+
if(device.name().toUpper().startsWith(QLatin1String("ZR8"))) {
536+
ZR8 = true;
537+
qDebug() << "ZR8 workaround activated";
538+
}
539+
507540
m_control = QLowEnergyController::createCentral(bluetoothDevice, this);
508541
connect(m_control, &QLowEnergyController::serviceDiscovered, this, &octanetreadmill::serviceDiscovered);
509542
connect(m_control, &QLowEnergyController::discoveryFinished, this, &octanetreadmill::serviceScanDone);

src/octanetreadmill.h

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class octanetreadmill : public treadmill {
6666

6767
QByteArray actualPaceSign;
6868
QByteArray actualPace2Sign;
69+
QByteArray cadenceSign;
6970

7071
QTimer *refresh;
7172
virtualtreadmill *virtualTreadMill = nullptr;
@@ -77,6 +78,8 @@ class octanetreadmill : public treadmill {
7778
bool initDone = false;
7879
bool initRequest = false;
7980

81+
bool ZR8 = false;
82+
8083
Q_SIGNALS:
8184
void disconnected();
8285
void debug(QString string);

0 commit comments

Comments
 (0)