Skip to content

Commit

Permalink
handling ERG mode for VFSPINBIKE
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnulein committed Dec 20, 2024
1 parent 8002e47 commit e881ce5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/devices/bluetoothdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void bluetoothdevice::setVirtualDevice(virtualdevice *virtualDevice, VIRTUAL_DEV
}

// keiser m3i has a separate management of this, so please check it
void bluetoothdevice::update_metrics(bool watt_calc, const double watts, const bool from_accessory) {
void bluetoothdevice::update_metrics(bool watt_calc, const double watts, const bool from_accessory, double resistance) {

QDateTime current = QDateTime::currentDateTime();
double deltaTime = (((double)_lastTimeUpdate.msecsTo(current)) / ((double)1000.0));
Expand All @@ -188,7 +188,7 @@ void bluetoothdevice::update_metrics(bool watt_calc, const double watts, const b
watt_calc = false;

if(deviceType() == bluetoothdevice::BIKE && !from_accessory) // append only if it's coming from the bike, not from the power sensor
_ergTable.collectData(Cadence.value(), m_watt.value(), Resistance.value());
_ergTable.collectData(Cadence.value(), m_watt.value(), resistance);

if (!_firstUpdate && !paused) {
if (currentSpeed().value() > 0.0 || settings.value(QZSettings::continuous_moving, true).toBool()) {
Expand Down
2 changes: 1 addition & 1 deletion src/devices/bluetoothdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ class bluetoothdevice : public QObject {
* @param watt_calc ??
* @param watts ?. Unit: watts
*/
void update_metrics(bool watt_calc, const double watts, const bool from_accessory = false);
void update_metrics(bool watt_calc, const double watts, const bool from_accessory = false, double resistance = Resistance.value());

/**
* @brief update_hr_from_external Updates heart rate from Garmin Companion App or Apple Watch
Expand Down
17 changes: 13 additions & 4 deletions src/devices/ftmsbike/ftmsbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ void ftmsbike::update() {
// gattWriteCharacteristic.isValid() &&
// gattNotify1Characteristic.isValid() &&
/*initDone*/) {
update_metrics(false, watts());
// here the bike that doesn't have ERG mode, so i'm using inclination to recreate a resistance value
update_metrics(false, watts(), false, (VFSPINBIKE ? Inclination.value() * 10.0 : Resistance.value()));

// updating the treadmill console every second
if (sec1Update++ == (500 / refresh->interval())) {
Expand Down Expand Up @@ -362,9 +363,11 @@ void ftmsbike::update() {
lastGearValue = gears();

if (requestPower != -1) {
qDebug() << QStringLiteral("writing power") << requestPower;
init();
forcePower(requestPower);
if(!VFSPINBIKE) { // this bike doesn't handle ERG mode
qDebug() << QStringLiteral("writing power") << requestPower;
init();
forcePower(requestPower);
}
requestPower = -1;
}
if (requestStart != -1) {
Expand Down Expand Up @@ -1111,6 +1114,12 @@ void ftmsbike::ftmsCharacteristicChanged(const QLowEnergyCharacteristic &charact
b[1] = power & 0xFF;
b[2] = power >> 8;
qDebug() << "applying gears mod" << gears() << gearsZwiftRatio() << power;

// this bike doesn't handle erg mode
if(VFSPINBIKE) {
forceResistance(((double)resistanceFromPowerRequest(power)) / 10.0);
return;
}
}

writeCharacteristic((uint8_t*)b.data(), b.length(), "injectWrite ", false, true);
Expand Down

0 comments on commit e881ce5

Please sign in to comment.