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

Ftms wheel diamater for gears #2715

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -4068,7 +4068,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 919;
CURRENT_PROJECT_VERSION = 922;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = "ADB_HOST=1";
Expand Down Expand Up @@ -4259,7 +4259,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 919;
CURRENT_PROJECT_VERSION = 922;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -4486,7 +4486,7 @@
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 919;
CURRENT_PROJECT_VERSION = 922;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -4582,7 +4582,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 919;
CURRENT_PROJECT_VERSION = 922;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = YES;
Expand Down Expand Up @@ -4674,7 +4674,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 919;
CURRENT_PROJECT_VERSION = 922;
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
ENABLE_BITCODE = YES;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -4788,7 +4788,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 919;
CURRENT_PROJECT_VERSION = 922;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
ENABLE_BITCODE = YES;
Expand Down
8 changes: 8 additions & 0 deletions src/devices/bike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ void bike::setGears(double gears) {
qDebug() << "new gear value ignored because of gears_zwift_ratio setting!";
return;
}
if(gears > maxGears()) {
qDebug() << "new gear value ignored because of maxGears" << maxGears();
return;
}
if(gears < minGears()) {
qDebug() << "new gear value ignored because of minGears" << minGears();
return;
}
m_gears = gears;
if(homeform::singleton()) {
homeform::singleton()->updateGearsValue();
Expand Down
2 changes: 2 additions & 0 deletions src/devices/bike.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class bike : public bluetoothdevice {
double currentCrankRevolutions() override;
uint16_t lastCrankEventTime() override;
bool connected() override;
virtual double maxGears() { return 9999.0; }
virtual double minGears() { return -9999.0; }
virtual uint16_t watts();
virtual resistance_t pelotonToBikeResistance(int pelotonResistance);
virtual resistance_t resistanceFromPowerRequest(uint16_t power);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,6 @@ void bluetooth::deviceDiscovered(const QBluetoothDeviceInfo &device) {
(b.name().toUpper().startsWith(ftmsAccessoryName.toUpper()) &&
settings.value(QZSettings::ss2k_peloton, QZSettings::default_ss2k_peloton)
.toBool()) || // ss2k on a peloton bike
((b.name().toUpper().startsWith("KICKR CORE")) && deviceHasService(b, QBluetoothUuid((quint16)0x1826))) ||
(b.name().toUpper().startsWith("MERACH-MR667-")) ||
(b.name().toUpper().startsWith("DS60-")) ||
(b.name().toUpper().startsWith("BIKE-")) ||
Expand Down Expand Up @@ -1562,6 +1561,7 @@ void bluetooth::deviceDiscovered(const QBluetoothDeviceInfo &device) {
this->signalBluetoothDeviceConnected(ftmsBike);
} else if ((b.name().toUpper().startsWith("KICKR SNAP") || b.name().toUpper().startsWith("KICKR BIKE") ||
b.name().toUpper().startsWith("KICKR ROLLR") ||
b.name().toUpper().startsWith("KICKR CORE") ||
(b.name().toUpper().startsWith("HAMMER ") && saris_trainer) ||
(b.name().toUpper().startsWith("WAHOO KICKR"))) &&
!wahooKickrSnapBike && !ftmsBike && filter) {
Expand Down
29 changes: 20 additions & 9 deletions src/devices/ftmsbike/ftmsbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ 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();
}

void ftmsbike::writeCharacteristicZwiftPlay(uint8_t *data, uint8_t data_len, const QString &info, bool disable_log,
Expand Down Expand Up @@ -170,6 +172,18 @@ void ftmsbike::zwiftPlayInit() {
}
}

void ftmsbike::setWheelDiameter(double diameter) {
uint8_t write[] = {FTMS_SET_WHEEL_CIRCUMFERENCE, 0x00, 0x00};

diameter = diameter * 10.0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why setting circumference as diameter*10, no mistake here?


write[1] = ((uint16_t)diameter) & 0xFF;
write[2] = ((uint16_t)diameter) >> 8;

writeCharacteristic(write, sizeof(write), QStringLiteral("setWheelCircumference ") + QString::number(diameter));
}


void ftmsbike::forcePower(int16_t requestPower) {
if(resistance_lvl_mode) {
forceResistance(resistanceFromPowerRequest(requestPower));
Expand Down Expand Up @@ -285,14 +299,16 @@ void ftmsbike::update() {
if (((virtualBike && !virtualBike->ftmsDeviceConnected()) || !virtualBike) &&
(requestPower == 0 || requestPower == -1)) {
init();
forceResistance(requestResistance + (gears() * 5));
if(requestResistance != - 1)
forceResistance(requestResistance + (gears() * 5));
else
setWheelDiameter(wheelCircumference::gearsToWheelDiameter(gears()));
}
}
requestResistance = -1;
}
if((virtualBike && virtualBike->ftmsDeviceConnected()) && lastGearValue != gears() && lastRawRequestedInclinationValue != -100 && lastPacketFromFTMS.length() >= 7) {
qDebug() << "injecting fake ftms frame in order to send the new gear value ASAP" << lastPacketFromFTMS.toHex(' ');
ftmsCharacteristicChanged(QLowEnergyCharacteristic(), lastPacketFromFTMS);
setWheelDiameter(wheelCircumference::gearsToWheelDiameter(gears()));
}

QSettings settings;
Expand Down Expand Up @@ -1065,13 +1081,8 @@ void ftmsbike::ftmsCharacteristicChanged(const QLowEnergyCharacteristic &charact
lastPacketFromFTMS.append(b.at(i));
qDebug() << "lastPacketFromFTMS" << lastPacketFromFTMS.toHex(' ');
int16_t slope = (((uint8_t)b.at(3)) + (b.at(4) << 8));
if (gears() != 0) {
slope += (gears() * 50);
}
b[3] = slope & 0xFF;
b[4] = slope >> 8;

qDebug() << "applying gears mod" << gears() << slope;
b[4] = slope >> 8;
/*} else if(b.at(0) == FTMS_SET_INDOOR_BIKE_SIMULATION_PARAMS && zwiftPlayService != nullptr && gears_zwift_ratio) {
int16_t slope = (((uint8_t)b.at(3)) + (b.at(4) << 8));
uint8_t gear2[] = {0x04, 0x22, 0x02, 0x10, 0x00};
Expand Down
2 changes: 2 additions & 0 deletions src/devices/ftmsbike/ftmsbike.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QObject>
#include <QString>

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

#ifdef Q_OS_IOS
Expand Down Expand Up @@ -85,6 +86,7 @@ class ftmsbike : public bike {
void init();
void forceResistance(resistance_t requestResistance);
void forcePower(int16_t requestPower);
void setWheelDiameter(double diameter);
uint16_t wattsFromResistance(double resistance);

QTimer *refresh;
Expand Down
25 changes: 22 additions & 3 deletions src/devices/wahookickrsnapbike/wahookickrsnapbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ wahookickrsnapbike::wahookickrsnapbike(bool noWriteResistance, bool noHeartServi
initDone = false;
connect(refresh, &QTimer::timeout, this, &wahookickrsnapbike::update);
refresh->start(200ms);
wheelCircumference::GearTable g;
g.printTable();
}

bool wahookickrsnapbike::writeCharacteristic(uint8_t *data, uint8_t data_len, QString info, bool disable_log,
Expand Down Expand Up @@ -192,10 +194,16 @@ void wahookickrsnapbike::update() {
}
QThread::msleep(700);

QByteArray d = setWheelCircumference(wheelCircumference::gearsToWheelDiameter(gears()));
uint8_t e[20];
setGears(1);
memcpy(e, d.constData(), d.length());
writeCharacteristic(e, d.length(), "setWheelCircumference", false, true);

// required to the SS2K only one time
Resistance = 0;
emit resistanceRead(Resistance.value());
initRequest = false;
initRequest = false;
} else if (bluetoothDevice.isValid() &&
m_control->state() == QLowEnergyController::DiscoveredState //&&
// gattCommunicationChannelService &&
Expand Down Expand Up @@ -259,7 +267,10 @@ void wahookickrsnapbike::update() {
memcpy(b, a.constData(), a.length());
writeCharacteristic(b, a.length(), "setResistance", false, true);
} else if (virtualBike && virtualBike->ftmsDeviceConnected() && lastGearValue != gears()) {
inclinationChanged(lastGrade, lastGrade);
QByteArray a = setWheelCircumference(wheelCircumference::gearsToWheelDiameter(gears()));
uint8_t b[20];
memcpy(b, a.constData(), a.length());
writeCharacteristic(b, a.length(), "setWheelCircumference", false, true);
}
lastGearValue = gears();
requestResistance = -1;
Expand Down Expand Up @@ -823,7 +834,6 @@ void wahookickrsnapbike::inclinationChanged(double grade, double percentage) {
emit debug(QStringLiteral("writing inclination ") + QString::number(grade));
QSettings settings;
double g = grade;
g += gears();
QByteArray a = setSimGrade(g);
uint8_t b[20];
memcpy(b, a.constData(), a.length());
Expand All @@ -833,3 +843,12 @@ void wahookickrsnapbike::inclinationChanged(double grade, double percentage) {
bool wahookickrsnapbike::inclinationAvailableByHardware() {
return KICKR_BIKE;
}

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

double wahookickrsnapbike::minGears() {
return 1;
}
7 changes: 5 additions & 2 deletions src/devices/wahookickrsnapbike/wahookickrsnapbike.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QObject>
#include <QString>

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

Expand All @@ -42,6 +43,8 @@ class wahookickrsnapbike : public bike {
bool connected() override;
resistance_t maxResistance() override { return 100; }
bool inclinationAvailableByHardware() override;
double maxGears() override;
double minGears() override;

enum OperationCode : uint8_t {
_unlock = 32,
Expand All @@ -56,7 +59,7 @@ class wahookickrsnapbike : public bike {
_setWheelCircumference = 72,
};

private:
private:
QByteArray unlockCommand();
QByteArray setResistanceMode(double resistance);
QByteArray setStandardMode(uint8_t level);
Expand Down Expand Up @@ -107,7 +110,7 @@ class wahookickrsnapbike : public bike {

volatile int notificationSubscribed = 0;

resistance_t lastForcedResistance = -1;
resistance_t lastForcedResistance = -1;

#ifdef Q_OS_IOS
lockscreen *h = 0;
Expand Down
Loading
Loading