Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zwift Play (within Zwift Ride) Two buttons for shifting gears #2999 #3008

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/devices/bike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,20 @@ double bike::gearsZwiftRatio() {
}
return 1;
}


void bike::chainRingUp() {
setGears(gearTable.chainRingUp(m_gears));
}

void bike::chainRingDown() {
setGears(gearTable.chainRingDown(m_gears));
}

void bike::cassetteUp() {
setGears(gearTable.cassetteUp(m_gears));
}

void bike::cassetteDown() {
setGears(gearTable.cassetteDown(m_gears));
}
6 changes: 6 additions & 0 deletions src/devices/bike.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "devices/bluetoothdevice.h"
#include "virtualdevices/virtualbike.h"
#include "wheelcircumference.h"
#include <QObject>

class bike : public bluetoothdevice {
Expand Down Expand Up @@ -43,6 +44,7 @@ class bike : public bluetoothdevice {
void setSpeedLimit(double speed) { m_speedLimit = speed; }
double speedLimit() { return m_speedLimit; }
virtual bool ifitCompatible() {return false;}
wheelCircumference::GearTable gearTable;

/**
* @brief currentSteeringAngle Gets a metric object to get or set the current steering angle
Expand Down Expand Up @@ -75,6 +77,10 @@ class bike : public bluetoothdevice {
setGears(gears() - (gears_zwift_ratio ? 1 :
settings.value(QZSettings::gears_gain, QZSettings::default_gears_gain).toDouble()));
}
void chainRingUp();
void chainRingDown();
void cassetteUp();
void cassetteDown();

Q_SIGNALS:
void bikeStarted();
Expand Down
4 changes: 4 additions & 0 deletions src/devices/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,10 @@ void bluetooth::connectedAndDiscovered() {
connect(zwiftPlayDevice.last(), &zwiftclickremote::debug, this, &bluetooth::debug);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::plus, (bike*)this->device(), &bike::gearUp);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::minus, (bike*)this->device(), &bike::gearDown);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::chainRingUp, (bike*)this->device(), &bike::chainRingUp);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::chainRingDown, (bike*)this->device(), &bike::chainRingDown);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::cassetteUp, (bike*)this->device(), &bike::cassetteUp);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::cassetteDown, (bike*)this->device(), &bike::cassetteDown);
if((zwiftPlayDevice.last()->typeZap == AbstractZapDevice::LEFT && !zwiftplay_swap) ||
(zwiftPlayDevice.last()->typeZap == AbstractZapDevice::RIGHT && zwiftplay_swap)) {
connect((bike*)this->device(), &bike::gearOkUp, this, &bluetooth::gearUp);
Expand Down
9 changes: 3 additions & 6 deletions src/devices/ftmsbike/ftmsbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "keepawakehelper.h"
#endif
#include <chrono>
#include "wheelcircumference.h"

#ifdef Q_OS_IOS
extern quint8 QZ_EnableDiscoveryCharsAndDescripttors;
Expand All @@ -36,8 +35,7 @@ ftmsbike::ftmsbike(bool noWriteResistance, bool noHeartService, int8_t bikeResis
initDone = false;
connect(refresh, &QTimer::timeout, this, &ftmsbike::update);
refresh->start(settings.value(QZSettings::poll_device_time, QZSettings::default_poll_device_time).toInt());
wheelCircumference::GearTable g;
g.printTable();
gearTable.printTable();
}

void ftmsbike::writeCharacteristicZwiftPlay(uint8_t *data, uint8_t data_len, const QString &info, bool disable_log,
Expand Down Expand Up @@ -327,8 +325,7 @@ void ftmsbike::update() {

if(zwiftPlayService && gears_zwift_ratio && lastGearValue != gears()) {
QSettings settings;
wheelCircumference::GearTable table;
wheelCircumference::GearTable::GearInfo g = table.getGear((int)gears());
wheelCircumference::GearTable::GearInfo g = gearTable.getGear((int)gears());
double original_ratio = ((double)settings.value(QZSettings::gear_crankset_size, QZSettings::default_gear_crankset_size).toDouble()) /
((double)settings.value(QZSettings::gear_cog_size, QZSettings::default_gear_cog_size).toDouble());

Expand Down Expand Up @@ -1329,7 +1326,7 @@ double ftmsbike::maxGears() {

if((zwiftPlayService != nullptr || DIRETO_XR) && gears_zwift_ratio) {
wheelCircumference::GearTable g;
return g.maxGears;
return gearTable.maxGears;
} else if(WATTBIKE) {
return 22;
} else {
Expand Down
1 change: 0 additions & 1 deletion src/devices/ftmsbike/ftmsbike.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QObject>
#include <QString>

#include "wheelcircumference.h"
#include "devices/bike.h"

#ifdef Q_OS_IOS
Expand Down
2 changes: 0 additions & 2 deletions src/devices/technogymbike/technogymbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ technogymbike::technogymbike(bool noWriteResistance, bool noHeartService, int8_t
initDone = false;
connect(refresh, &QTimer::timeout, this, &technogymbike::update);
refresh->start(settings.value(QZSettings::poll_device_time, QZSettings::default_poll_device_time).toInt());
wheelCircumference::GearTable g;
g.printTable();
}

bool technogymbike::writeCharacteristic(uint8_t *data, uint8_t data_len, const QString &info, bool disable_log,
Expand Down
1 change: 0 additions & 1 deletion src/devices/technogymbike/technogymbike.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QObject>
#include <QString>

#include "wheelcircumference.h"
#include "devices/bike.h"

#ifdef Q_OS_IOS
Expand Down
6 changes: 2 additions & 4 deletions src/devices/wahookickrsnapbike/wahookickrsnapbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ wahookickrsnapbike::wahookickrsnapbike(bool noWriteResistance, bool noHeartServi
connect(refresh, &QTimer::timeout, this, &wahookickrsnapbike::update);
QSettings settings;
refresh->start(settings.value(QZSettings::poll_device_time, QZSettings::default_poll_device_time).toInt());
wheelCircumference::GearTable g;
g.printTable();
gearTable.printTable();
}

bool wahookickrsnapbike::writeCharacteristic(uint8_t *data, uint8_t data_len, QString info, bool disable_log,
Expand Down Expand Up @@ -880,8 +879,7 @@ bool wahookickrsnapbike::inclinationAvailableByHardware() {
}

double wahookickrsnapbike::maxGears() {
wheelCircumference::GearTable g;
return g.maxGears;
return gearTable.maxGears;
}

double wahookickrsnapbike::minGears() {
Expand Down
1 change: 0 additions & 1 deletion src/devices/wahookickrsnapbike/wahookickrsnapbike.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QObject>
#include <QString>

#include "wheelcircumference.h"
#include "devices/bike.h"
#include "virtualdevices/virtualbike.h"

Expand Down
4 changes: 3 additions & 1 deletion src/qzsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,9 @@ const QString QZSettings::iconsole_rower = QStringLiteral("iconsole_rower");
const QString QZSettings::proform_treadmill_1500_pro = QStringLiteral("proform_treadmill_1500_pro");
const QString QZSettings::proform_505_cst_80_44 = QStringLiteral("proform_505_cst_80_44");
const QString QZSettings::proform_trainer_8_0 = QStringLiteral("proform_trainer_8_0");
const QString QZSettings::shift_style = QStringLiteral("shift_style");

const uint32_t allSettingsCount = 683;
const uint32_t allSettingsCount = 684;

QVariant allSettings[allSettingsCount][2] = {
{QZSettings::cryptoKeySettingsProfiles, QZSettings::default_cryptoKeySettingsProfiles},
Expand Down Expand Up @@ -1500,6 +1501,7 @@ QVariant allSettings[allSettingsCount][2] = {
{QZSettings::proform_treadmill_1500_pro, QZSettings::default_proform_treadmill_1500_pro},
{QZSettings::proform_505_cst_80_44, QZSettings::default_proform_505_cst_80_44},
{QZSettings::proform_trainer_8_0, QZSettings::default_proform_trainer_8_0},
{QZSettings::shift_style, QZSettings::default_shift_style},
};

void QZSettings::qDebugAllSettings(bool showDefaults) {
Expand Down
8 changes: 8 additions & 0 deletions src/qzsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,14 @@ class QZSettings {
static const QString proform_trainer_8_0;
static constexpr bool default_proform_trainer_8_0 = false;

static const QString shift_style;
static constexpr int default_shift_style = 0;

static const int SHIFT_STYLE_SEQUENTIAL = 0;
static const int SHIFT_STYLE_SHIMANO_A = 1;
static const int SHIFT_STYLE_SHIMANO_B = 2;
static const int SHIFT_STYLE_SRAM = 3;

/**
* @brief Write the QSettings values using the constants from this namespace.
* @param showDefaults Optionally indicates if the default should be shown with the key.
Expand Down
49 changes: 49 additions & 0 deletions src/settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ import QtQuick.Dialogs 1.0

// from version 2.18.16
property bool proform_trainer_8_0: false
property int shift_style: 0
}

function paddingZeros(text, limit) {
Expand Down Expand Up @@ -10098,6 +10099,54 @@ import QtQuick.Dialogs 1.0
onClicked: { settings.zwift_play = checked; window.settings_restart_to_apply = true; }
}

RowLayout {
spacing: 10
Label {
text: qsTr("Shift Style:")
Layout.fillWidth: true
}
ComboBox {
id: shiftStyleTextField
model: [ "Sequential", "Shimano A", "Shimano B", "SRAM" ]
displayText: {
switch(settings.shift_style) {
case 0: return "Sequential"
case 1: return "Shimano A"
case 2: return "Shimano B"
case 3: return "SRAM"
default: return "Sequential"
}
}
Layout.fillHeight: false
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
onActivated: {
displayText = shiftStyleTextField.currentValue
}
}
Button {
text: "OK"
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
onClicked: {
settings.shift_style = shiftStyleTextField.currentIndex
toast.show("Setting saved!")
window.settings_restart_to_apply = true
}
}
}

Label {
text: qsTr("Choose how the gears should shift: Sequential (standard), Shimano (both hands) or SRAM style. All trademarks, service marks, trade names, and logos referenced herein are the property of their respective owners.")
font.bold: true
font.italic: true
font.pixelSize: Qt.application.font.pixelSize - 2
textFormat: Text.PlainText
wrapMode: Text.WordWrap
verticalAlignment: Text.AlignVCenter
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillWidth: true
color: Material.color(Material.Lime)
}

Label {
text: qsTr("Use it to change the gears on QZ!")
font.bold: true
Expand Down
82 changes: 82 additions & 0 deletions src/wheelcircumference.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,88 @@ class wheelCircumference : public QObject {
loadGearSettings();
}

int cassetteUp(int currentGear) {
GearTable table;
GearTable::GearInfo currentGearInfo = table.getGear(currentGear);
if (currentGearInfo.gear == 0) return currentGear;

int nextGear = currentGear;
int smallestValidCog = INT_MAX;

for (int i = 1; i <= maxGears; i++) {
GearTable::GearInfo gear = table.getGear(i);
if (gear.gear != 0 &&
gear.crankset == currentGearInfo.crankset &&
gear.rearCog > currentGearInfo.rearCog &&
gear.rearCog < smallestValidCog) {
smallestValidCog = gear.rearCog;
nextGear = gear.gear;
}
}
return nextGear;
}

int cassetteDown(int currentGear) {
GearTable table;
GearTable::GearInfo currentGearInfo = table.getGear(currentGear);
if (currentGearInfo.gear == 0) return currentGear;

int nextGear = currentGear;
int largestValidCog = 0;

for (int i = 1; i <= maxGears; i++) {
GearTable::GearInfo gear = table.getGear(i);
if (gear.gear != 0 &&
gear.crankset == currentGearInfo.crankset &&
gear.rearCog < currentGearInfo.rearCog &&
gear.rearCog > largestValidCog) {
largestValidCog = gear.rearCog;
nextGear = gear.gear;
}
}
return nextGear;
}

int chainRingUp(int currentGear) {
GearTable table;
GearTable::GearInfo currentGearInfo = table.getGear(currentGear);
if (currentGearInfo.gear == 0) return currentGear;

int nextGear = currentGear;
int smallestValidCrankset = INT_MAX;

for (int i = 1; i <= maxGears; i++) {
GearTable::GearInfo gear = table.getGear(i);
if (gear.gear != 0 &&
gear.crankset > currentGearInfo.crankset &&
gear.crankset < smallestValidCrankset) {
smallestValidCrankset = gear.crankset;
nextGear = gear.gear;
}
}
return nextGear;
}

int chainRingDown(int currentGear) {
GearTable table;
GearTable::GearInfo currentGearInfo = table.getGear(currentGear);
if (currentGearInfo.gear == 0) return currentGear;

int nextGear = currentGear;
int largestValidCrankset = 0;

for (int i = 1; i <= maxGears; i++) {
GearTable::GearInfo gear = table.getGear(i);
if (gear.gear != 0 &&
gear.crankset < currentGearInfo.crankset &&
gear.crankset > largestValidCrankset) {
largestValidCrankset = gear.crankset;
nextGear = gear.gear;
}
}
return nextGear;
}

private:
std::vector<GearInfo> gears;
};
Expand Down
Loading
Loading