Skip to content

Commit

Permalink
Garmin power sensor over bluetooth (#1347)
Browse files Browse the repository at this point in the history
* trying to fix it (it shows as connectable but the metrics are 0)

* trying a different approach on power data

* it works!

* Update lockscreen.mm

* handled both apple fitness on watch and garmin!
  • Loading branch information
cagnulein authored Jan 2, 2024
1 parent d8ed66e commit ab63a29
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 178 deletions.
2 changes: 1 addition & 1 deletion src/ios/lockscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class lockscreen {
void virtualbike_setHeartRate(unsigned char heartRate);
void virtualbike_setCadence(unsigned short crankRevolutions, unsigned short lastCrankEventTime);

void virtualbike_zwift_ios(bool disable_hr);
void virtualbike_zwift_ios(bool disable_hr, bool garmin_bluetooth_compatibility);
double virtualbike_getCurrentSlope();
double virtualbike_getCurrentCRR();
double virtualbike_getCurrentCW();
Expand Down
4 changes: 2 additions & 2 deletions src/ios/lockscreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@
[_virtualbike updateCadenceWithCrankRevolutions:crankRevolutions LastCrankEventTime:lastCrankEventTime];
}

void lockscreen::virtualbike_zwift_ios(bool disable_hr)
void lockscreen::virtualbike_zwift_ios(bool disable_hr, bool garmin_bluetooth_compatibility)
{
_virtualbike_zwift = [[virtualbike_zwift alloc] initWithDisable_hr: disable_hr];
_virtualbike_zwift = [[virtualbike_zwift alloc] initWithDisable_hr:disable_hr garmin_bluetooth_compatibility:garmin_bluetooth_compatibility];
}

void lockscreen::virtualrower_ios()
Expand Down
369 changes: 198 additions & 171 deletions src/ios/virtualbike_zwift.swift

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/qzsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,9 @@ const QString QZSettings::zwift_username = QStringLiteral("zwift_username");
const QString QZSettings::default_zwift_username = QStringLiteral("");
const QString QZSettings::zwift_password = QStringLiteral("zwift_password");
const QString QZSettings::default_zwift_password = QStringLiteral("");
const QString QZSettings::garmin_bluetooth_compatibility = QStringLiteral("garmin_bluetooth_compatibility");

const uint32_t allSettingsCount = 581;
const uint32_t allSettingsCount = 582;

QVariant allSettings[allSettingsCount][2] = {
{QZSettings::cryptoKeySettingsProfiles, QZSettings::default_cryptoKeySettingsProfiles},
Expand Down Expand Up @@ -1283,6 +1284,7 @@ QVariant allSettings[allSettingsCount][2] = {
{QZSettings::proformtdf1ip, QZSettings::default_proformtdf1ip},
{QZSettings::zwift_username, QZSettings::default_zwift_username},
{QZSettings::zwift_password, QZSettings::default_zwift_password},
{QZSettings::garmin_bluetooth_compatibility, QZSettings::default_garmin_bluetooth_compatibility},

};

Expand Down
3 changes: 3 additions & 0 deletions src/qzsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,9 @@ class QZSettings {
static const QString zwift_password;
static const QString default_zwift_password;

static const QString garmin_bluetooth_compatibility;
static constexpr bool default_garmin_bluetooth_compatibility = false;


/**
* @brief Write the QSettings values using the constants from this namespace.
Expand Down
32 changes: 31 additions & 1 deletion src/settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@ import QtQuick.Dialogs 1.0
property string proformtdf1ip: ""
property string zwift_username: ""
property string zwift_password: ""

// from version 2.16.31
property bool garmin_bluetooth_compatibility: false
}

function paddingZeros(text, limit) {
Expand Down Expand Up @@ -4574,13 +4577,40 @@ import QtQuick.Dialogs 1.0
}

AccordionElement {
title: qsTr("Garmin Companion Options") + "\uD83E\uDD47"
title: qsTr("Garmin Options") + "\uD83E\uDD47"
indicatRectColor: Material.color(Material.Grey)
textColor: Material.color(Material.Grey)
color: Material.backgroundColor
accordionContent: ColumnLayout {
spacing: 0

SwitchDelegate {
text: qsTr("Garmin Bluetooth Sensor")
spacing: 0
bottomPadding: 0
topPadding: 0
rightPadding: 0
leftPadding: 0
clip: false
checked: settings.garmin_bluetooth_compatibility
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillWidth: true
onClicked: { settings.garmin_bluetooth_compatibility = checked; window.settings_restart_to_apply = true; }
}

Label {
text: qsTr("If you want to send metrics to your Garmin device from your Mac, enable this. Otherwise leave it disabled.")
font.bold: true
font.italic: true
font.pixelSize: 9
textFormat: Text.PlainText
wrapMode: Text.WordWrap
verticalAlignment: Text.AlignVCenter
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillWidth: true
color: Material.color(Material.Lime)
}

SwitchDelegate {
text: qsTr("Enable Companion App")
spacing: 0
Expand Down
5 changes: 3 additions & 2 deletions src/virtualbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear
bool echelon =
settings.value(QZSettings::virtual_device_echelon, QZSettings::default_virtual_device_echelon).toBool();
bool ifit = settings.value(QZSettings::virtual_device_ifit, QZSettings::default_virtual_device_ifit).toBool();
bool garmin_bluetooth_compatibility = settings.value(QZSettings::garmin_bluetooth_compatibility, QZSettings::default_garmin_bluetooth_compatibility).toBool();

if (settings.value(QZSettings::dircon_yes, QZSettings::default_dircon_yes).toBool()) {
dirconManager = new DirconManager(Bike, bikeResistanceOffset, bikeResistanceGain, this);
Expand All @@ -53,12 +54,12 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear
#ifndef IO_UNDER_QT
bool ios_peloton_workaround =
settings.value(QZSettings::ios_peloton_workaround, QZSettings::default_ios_peloton_workaround).toBool();
if (ios_peloton_workaround && !cadence && !echelon && !ifit && !heart_only && !power) {
if ((ios_peloton_workaround && !cadence && !echelon && !ifit && !heart_only) || garmin_bluetooth_compatibility) {

qDebug() << "ios_zwift_workaround activated!";
h = new lockscreen();
h->virtualbike_zwift_ios(
settings.value(QZSettings::bike_heartrate_service, QZSettings::default_bike_heartrate_service).toBool());
settings.value(QZSettings::bike_heartrate_service, QZSettings::default_bike_heartrate_service).toBool(), garmin_bluetooth_compatibility);
} else

#endif
Expand Down

0 comments on commit ab63a29

Please sign in to comment.