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

Tacx wheel diameter #2734

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
05d598f
first raw version
cagnulein Oct 21, 2024
49c7a96
Merge branch 'master' into Custom-gearing-ranges/ratios-(Discussion-#…
cagnulein Oct 22, 2024
cc7757b
Update project.pbxproj
cagnulein Oct 22, 2024
2d13644
Update virtualbike_zwift.swift
cagnulein Oct 22, 2024
1c06260
Merge branch 'master' into Custom-gearing-ranges/ratios-(Discussion-#…
cagnulein Oct 23, 2024
d712621
fixing formula
cagnulein Oct 23, 2024
2da194f
Merge branch 'master' into Custom-gearing-ranges/ratios-(Discussion-#…
cagnulein Oct 24, 2024
89808ae
fixing casting to double
cagnulein Oct 24, 2024
ed1599c
need to center the values in the table
cagnulein Oct 24, 2024
0f14944
Update gears.qml
cagnulein Oct 25, 2024
527396e
Revert "Update gears.qml"
cagnulein Oct 28, 2024
74c37f5
Update gears.qml
cagnulein Oct 28, 2024
f85f743
i need to save the first 3 static objects and use it in the wahoo module
cagnulein Oct 28, 2024
8d07d7c
Merge branch 'master' into Custom-gearing-ranges/ratios-(Discussion-#…
cagnulein Oct 28, 2024
6fac977
qml finally saves the settings correctly
cagnulein Oct 28, 2024
2f2989f
completed?
cagnulein Oct 28, 2024
379cf8d
Update project.pbxproj
cagnulein Oct 29, 2024
64b9ec9
fixing gear conversion
cagnulein Oct 29, 2024
d7c3a84
adding max and minGears
cagnulein Oct 29, 2024
a7b8e63
fixing UI and settings
cagnulein Oct 29, 2024
82a6afe
kickr core to wahookickr class
cagnulein Oct 29, 2024
9cc02de
ftms wheel circumference for gears
cagnulein Oct 30, 2024
ad802f7
Merge branch 'master' into tacx_wheel_diameter
cagnulein Nov 4, 2024
dbb9ba3
implementing
cagnulein Nov 4, 2024
0625399
Update wahookickrsnapbike.cpp
cagnulein Nov 4, 2024
f3d8b39
Merge branch 'master' into tacx_wheel_diameter
cagnulein Nov 9, 2024
056424e
Merge branch 'master' into tacx_wheel_diameter
cagnulein Dec 10, 2024
0c3051c
Merge branch 'master' into tacx_wheel_diameter
cagnulein Dec 11, 2024
f350837
inclination is always requires for changing gears
cagnulein Dec 11, 2024
824d2e2
Merge branch 'master' into tacx_wheel_diameter
cagnulein Dec 11, 2024
438782a
fixing wheel changing sending a fake inclination on init
cagnulein Dec 11, 2024
47b0b05
Update tacxneo2.cpp
cagnulein Dec 11, 2024
fae60c1
fixing first resistance?
cagnulein Dec 13, 2024
c996212
Merge branch 'master' into tacx_wheel_diameter
cagnulein Dec 13, 2024
5f0ebd3
Update tacxneo2.cpp
cagnulein Dec 13, 2024
401e721
Merge branch 'master' into tacx_wheel_diameter
cagnulein Dec 13, 2024
83c6e7c
Merge branch 'master' into tacx_wheel_diameter
cagnulein Dec 13, 2024
97d6556
Update tacxneo2.cpp
cagnulein Dec 13, 2024
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
22 changes: 18 additions & 4 deletions src/devices/ftmsbike/ftmsbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ void ftmsbike::zwiftPlayInit() {
}
}

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

diameter = diameter * 10.0;

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 @@ -297,14 +309,16 @@ void ftmsbike::update() {
if (((virtualBike && !virtualBike->ftmsDeviceConnected()) || !virtualBike || resistance_lvl_mode) &&
(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 @@ -1055,7 +1069,7 @@ void ftmsbike::ftmsCharacteristicChanged(const QLowEnergyCharacteristic &charact

b[3] = slope & 0xFF;
b[4] = slope >> 8;

qDebug() << "applying gears mod" << gears() << slope;
} 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));
Expand Down
1 change: 1 addition & 0 deletions src/devices/ftmsbike/ftmsbike.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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
23 changes: 18 additions & 5 deletions src/devices/tacxneo2/tacxneo2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QSettings>
#include <QThread>
#include <math.h>
#include "wheelcircumference.h"
#ifdef Q_OS_ANDROID
#include "keepawakehelper.h"
#include <QLowEnergyConnectionParameters>
Expand Down Expand Up @@ -91,6 +92,7 @@ void tacxneo2::forceInclination(double inclination) {
inc[12]++;

writeCharacteristic(inc, sizeof(inc), QStringLiteral("changeInclination"), false, false);
resistance_sent = true;
}

void tacxneo2::update() {
Expand All @@ -106,6 +108,7 @@ void tacxneo2::update() {
settings.value(QZSettings::tacx_neo2_peloton, QZSettings::default_tacx_neo2_peloton).toBool();
if (tacx_neo2_peloton)
requestInclination = 0;
initDone = true;
} else if (bluetoothDevice.isValid() &&
m_control->state() == QLowEnergyController::DiscoveredState //&&
// gattCommunicationChannelService &&
Expand All @@ -123,7 +126,7 @@ void tacxneo2::update() {
auto virtualBike = this->VirtualBike();

if (requestResistance != -1) {
if (requestResistance != currentResistance().value() || lastGearValue != gears()) {
if (requestResistance != currentResistance().value()) {
emit debug(QStringLiteral("writing resistance ") + QString::number(requestResistance));
if (((virtualBike && !virtualBike->ftmsDeviceConnected()) || !virtualBike) &&
(requestPower == 0 || requestPower == -1)) {
Expand All @@ -135,16 +138,25 @@ void tacxneo2::update() {
}
if (requestInclination != -100) {
emit debug(QStringLiteral("writing inclination ") + QString::number(requestInclination));
forceInclination(requestInclination + gears()); // since this bike doesn't have the concept of resistance,
forceInclination(requestInclination); // since this bike doesn't have the concept of resistance,
// i'm using the gears in the inclination
requestInclination = -100;
} else if((virtualBike && virtualBike->ftmsDeviceConnected()) && lastGearValue != gears() && lastRawRequestedInclinationValue != -100) {
} else if((virtualBike && virtualBike->ftmsDeviceConnected()) && lastRawRequestedInclinationValue != -100) {
// in order to send the new gear value ASAP
forceInclination(lastRawRequestedInclinationValue + gears()); // since this bike doesn't have the concept of resistance,
forceInclination(lastRawRequestedInclinationValue); // since this bike doesn't have the concept of resistance,
// i'm using the gears in the inclination
}

lastGearValue = gears();
if(lastGearValue != gears()) {
if(Cadence.value() > 0) { // this trainer can change gears only if the wattage is greater than 0 and if you send at least once an inclination
if(!resistance_sent) {
forceInclination(1.0);
} else {
setUserConfiguration(wheelCircumference::gearsToWheelDiameter(gears()), 1);
lastGearValue = gears();
}
}
}

if (requestPower != -1) {
changePower(requestPower);
Expand Down Expand Up @@ -947,6 +959,7 @@ void tacxneo2::controllerStateChanged(QLowEnergyController::ControllerState stat
if (state == QLowEnergyController::UnconnectedState && m_control) {
qDebug() << QStringLiteral("trying to connect back again...");
initDone = false;
resistance_sent = false;
m_control->connectToDevice();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/devices/tacxneo2/tacxneo2.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class tacxneo2 : public bike {

double lastGearValue = -1;
bool resistance_received = false;
bool resistance_sent = false;

bool THINK_X = false;

Expand Down
Loading