diff --git a/src/devices/ftmsbike/ftmsbike.cpp b/src/devices/ftmsbike/ftmsbike.cpp index 1696010df..1b0c936ac 100644 --- a/src/devices/ftmsbike/ftmsbike.cpp +++ b/src/devices/ftmsbike/ftmsbike.cpp @@ -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)); @@ -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; @@ -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)); diff --git a/src/devices/ftmsbike/ftmsbike.h b/src/devices/ftmsbike/ftmsbike.h index 539f791fe..974d84b71 100644 --- a/src/devices/ftmsbike/ftmsbike.h +++ b/src/devices/ftmsbike/ftmsbike.h @@ -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; diff --git a/src/devices/tacxneo2/tacxneo2.cpp b/src/devices/tacxneo2/tacxneo2.cpp index 0d2d35b56..4fdca8c06 100644 --- a/src/devices/tacxneo2/tacxneo2.cpp +++ b/src/devices/tacxneo2/tacxneo2.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "wheelcircumference.h" #ifdef Q_OS_ANDROID #include "keepawakehelper.h" #include @@ -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() { @@ -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 && @@ -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)) { @@ -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); @@ -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(); } } diff --git a/src/devices/tacxneo2/tacxneo2.h b/src/devices/tacxneo2/tacxneo2.h index 15df84cfe..6e8f00a0c 100644 --- a/src/devices/tacxneo2/tacxneo2.h +++ b/src/devices/tacxneo2/tacxneo2.h @@ -80,6 +80,7 @@ class tacxneo2 : public bike { double lastGearValue = -1; bool resistance_received = false; + bool resistance_sent = false; bool THINK_X = false;