@@ -7081,34 +7081,74 @@ void homeform::update() {
70817081 }
70827082 }
70837083 } else if (bluetoothManager->device()->deviceType() == BIKE) {
7084- double step = 1;
7085- bool ergMode = ((bike*)bluetoothManager->device())->ergModeSupportedAvailableBySoftware();
7084+ bool ergMode = ((bike*)bluetoothManager->device())->ergModeSupportedAvailableByHardware();
7085+ bool inclinationAvailable = ((bike*)bluetoothManager->device())->inclinationAvailableBySoftware();
7086+
70867087 if(ergMode) {
7087- step = settings.value(QZSettings::pid_heart_zone_erg_mode_watt_step, QZSettings::default_pid_heart_zone_erg_mode_watt_step).toInt();
7088- }
7089- resistance_t currentResistance =
7090- ((bike *)bluetoothManager->device())->currentResistance().value();
7091- double current_target_watt = ((bike *)bluetoothManager->device())->lastRequestedPower().value();
7092- if (zone < ((uint8_t)currentHRZone)) {
7093- if(ergMode)
7088+ // Use power control for bikes with erg mode support
7089+ double step = settings.value(QZSettings::pid_heart_zone_erg_mode_watt_step, QZSettings::default_pid_heart_zone_erg_mode_watt_step).toInt();
7090+ double current_target_watt = ((bike *)bluetoothManager->device())->lastRequestedPower().value();
7091+ if (zone < ((uint8_t)currentHRZone)) {
70947092 ((bike *)bluetoothManager->device())->changePower(current_target_watt - step);
7095- else
7096- ((bike *)bluetoothManager->device())->changeResistance(currentResistance - step);
7097- pid_heart_zone_small_inc_counter = 0;
7098- } else if (zone > ((uint8_t)currentHRZone) && ((maxResistance >= currentResistance + step && !ergMode) || ergMode)) {
7099- if(ergMode)
7093+ pid_heart_zone_small_inc_counter = 0;
7094+ } else if (zone > ((uint8_t)currentHRZone)) {
71007095 ((bike *)bluetoothManager->device())->changePower(current_target_watt + step);
7101- else
7102- ((bike *)bluetoothManager->device())->changeResistance(currentResistance + step);
7103- pid_heart_zone_small_inc_counter = 0;
7104- } else if(trainprogram_pid_pushy) {
7105- pid_heart_zone_small_inc_counter++;
7106- if (pid_heart_zone_small_inc_counter > (5 * fabs(((float)zone) - currentHRZone))) {
7096+ pid_heart_zone_small_inc_counter = 0;
7097+ } else if(trainprogram_pid_pushy) {
7098+ pid_heart_zone_small_inc_counter++;
7099+ if (pid_heart_zone_small_inc_counter > (5 * fabs(((float)zone) - currentHRZone))) {
7100+ ((bike *)bluetoothManager->device())->changePower(current_target_watt + step);
7101+ pid_heart_zone_small_inc_counter = 0;
7102+ }
7103+ }
7104+ } else if(inclinationAvailable) {
7105+ // Use inclination control for bikes without erg mode but with inclination support (e.g., ftmsbike)
7106+ double step = 0.5;
7107+ double currentInclination = ((bike *)bluetoothManager->device())->currentInclination().value();
7108+ if (zone < ((uint8_t)currentHRZone)) {
7109+ ((bike *)bluetoothManager->device())->changeInclination(currentInclination - step, currentInclination - step);
7110+ pid_heart_zone_small_inc_counter = 0;
7111+ } else if (zone > ((uint8_t)currentHRZone)) {
7112+ ((bike *)bluetoothManager->device())->changeInclination(currentInclination + step, currentInclination + step);
7113+ pid_heart_zone_small_inc_counter = 0;
7114+ } else if(trainprogram_pid_pushy) {
7115+ pid_heart_zone_small_inc_counter++;
7116+ if (pid_heart_zone_small_inc_counter > (5 * fabs(((float)zone) - currentHRZone))) {
7117+ ((bike *)bluetoothManager->device())->changeInclination(currentInclination + step, currentInclination + step);
7118+ pid_heart_zone_small_inc_counter = 0;
7119+ }
7120+ }
7121+ } else {
7122+ // Fallback to resistance control for bikes without erg mode or inclination
7123+ double step = 1;
7124+ bool ergMode = ((bike*)bluetoothManager->device())->ergModeSupportedAvailableBySoftware();
7125+ if(ergMode) {
7126+ step = settings.value(QZSettings::pid_heart_zone_erg_mode_watt_step, QZSettings::default_pid_heart_zone_erg_mode_watt_step).toInt();
7127+ }
7128+ resistance_t currentResistance =
7129+ ((bike *)bluetoothManager->device())->currentResistance().value();
7130+ double current_target_watt = ((bike *)bluetoothManager->device())->lastRequestedPower().value();
7131+ if (zone < ((uint8_t)currentHRZone)) {
7132+ if(ergMode)
7133+ ((bike *)bluetoothManager->device())->changePower(current_target_watt - step);
7134+ else
7135+ ((bike *)bluetoothManager->device())->changeResistance(currentResistance - step);
7136+ pid_heart_zone_small_inc_counter = 0;
7137+ } else if (zone > ((uint8_t)currentHRZone) && ((maxResistance >= currentResistance + step && !ergMode) || ergMode)) {
71077138 if(ergMode)
71087139 ((bike *)bluetoothManager->device())->changePower(current_target_watt + step);
71097140 else
71107141 ((bike *)bluetoothManager->device())->changeResistance(currentResistance + step);
71117142 pid_heart_zone_small_inc_counter = 0;
7143+ } else if(trainprogram_pid_pushy) {
7144+ pid_heart_zone_small_inc_counter++;
7145+ if (pid_heart_zone_small_inc_counter > (5 * fabs(((float)zone) - currentHRZone))) {
7146+ if(ergMode)
7147+ ((bike *)bluetoothManager->device())->changePower(current_target_watt + step);
7148+ else
7149+ ((bike *)bluetoothManager->device())->changeResistance(currentResistance + step);
7150+ pid_heart_zone_small_inc_counter = 0;
7151+ }
71127152 }
71137153 }
71147154 } else if (bluetoothManager->device()->deviceType() == ROWING) {
@@ -7229,24 +7269,63 @@ void homeform::update() {
72297269 }
72307270 } else if (bluetoothManager->device()->deviceType() == BIKE) {
72317271
7232- const int step = 1;
7233- resistance_t currentResistance =
7234- ((bike *)bluetoothManager->device())->currentResistance().value();
7235- qDebug() << QStringLiteral("BIKE PID HR - currentResistance:") << currentResistance
7236- << QStringLiteral("maxResistance:") << maxResistance;
7272+ bool ergMode = ((bike*)bluetoothManager->device())->ergModeSupportedAvailableByHardware();
7273+ bool inclinationAvailable = ((bike*)bluetoothManager->device())->inclinationAvailableBySoftware();
72377274
7238- if (hrmax < bluetoothManager->device()->currentHeart().average20s()) {
7239- qDebug() << QStringLiteral("BIKE PID HR - HR > HRmax, DECREASING resistance from")
7240- << currentResistance << QStringLiteral("to") << (currentResistance - step);
7241- ((bike *)bluetoothManager->device())->changeResistance(currentResistance - step);
7242- } else if (hrmin > bluetoothManager->device()->currentHeart().average20s() &&
7243- currentResistance < maxResistance) {
7244- resistance_t newResistance = std::min(static_cast<resistance_t>(currentResistance + step), static_cast<resistance_t>(maxResistance));
7245- qDebug() << QStringLiteral("BIKE PID HR - HR < HRmin, INCREASING resistance from")
7246- << currentResistance << QStringLiteral("to") << newResistance;
7247- ((bike *)bluetoothManager->device())->changeResistance(newResistance);
7275+ if (ergMode) {
7276+ // Use power control for bikes with erg mode support
7277+ const int step = settings.value(QZSettings::pid_heart_zone_erg_mode_watt_step, QZSettings::default_pid_heart_zone_erg_mode_watt_step).toInt();
7278+ double current_target_watt = ((bike *)bluetoothManager->device())->lastRequestedPower().value();
7279+ qDebug() << QStringLiteral("BIKE PID HR - ergMode enabled, currentPower:") << current_target_watt;
7280+
7281+ if (hrmax < bluetoothManager->device()->currentHeart().average20s()) {
7282+ qDebug() << QStringLiteral("BIKE PID HR - HR > HRmax, DECREASING power from")
7283+ << current_target_watt << QStringLiteral("to") << (current_target_watt - step);
7284+ ((bike *)bluetoothManager->device())->changePower(current_target_watt - step);
7285+ } else if (hrmin > bluetoothManager->device()->currentHeart().average20s()) {
7286+ qDebug() << QStringLiteral("BIKE PID HR - HR < HRmin, INCREASING power from")
7287+ << current_target_watt << QStringLiteral("to") << (current_target_watt + step);
7288+ ((bike *)bluetoothManager->device())->changePower(current_target_watt + step);
7289+ } else {
7290+ qDebug() << QStringLiteral("BIKE PID HR - No action taken (in zone or at limits)");
7291+ }
7292+ } else if (inclinationAvailable) {
7293+ // Use inclination control for bikes without erg mode but with inclination support (e.g., ftmsbike)
7294+ const double step = 0.5;
7295+ double currentInclination = ((bike *)bluetoothManager->device())->currentInclination().value();
7296+ qDebug() << QStringLiteral("BIKE PID HR - Using inclination control, currentInclination:") << currentInclination;
7297+
7298+ if (hrmax < bluetoothManager->device()->currentHeart().average20s()) {
7299+ qDebug() << QStringLiteral("BIKE PID HR - HR > HRmax, DECREASING inclination from")
7300+ << currentInclination << QStringLiteral("to") << (currentInclination - step);
7301+ ((bike *)bluetoothManager->device())->changeInclination(currentInclination - step, currentInclination - step);
7302+ } else if (hrmin > bluetoothManager->device()->currentHeart().average20s()) {
7303+ qDebug() << QStringLiteral("BIKE PID HR - HR < HRmin, INCREASING inclination from")
7304+ << currentInclination << QStringLiteral("to") << (currentInclination + step);
7305+ ((bike *)bluetoothManager->device())->changeInclination(currentInclination + step, currentInclination + step);
7306+ } else {
7307+ qDebug() << QStringLiteral("BIKE PID HR - No action taken (in zone or at limits)");
7308+ }
72487309 } else {
7249- qDebug() << QStringLiteral("BIKE PID HR - No action taken (in zone or at limits)");
7310+ const int step = 1;
7311+ resistance_t currentResistance =
7312+ ((bike *)bluetoothManager->device())->currentResistance().value();
7313+ qDebug() << QStringLiteral("BIKE PID HR - currentResistance:") << currentResistance
7314+ << QStringLiteral("maxResistance:") << maxResistance;
7315+
7316+ if (hrmax < bluetoothManager->device()->currentHeart().average20s()) {
7317+ qDebug() << QStringLiteral("BIKE PID HR - HR > HRmax, DECREASING resistance from")
7318+ << currentResistance << QStringLiteral("to") << (currentResistance - step);
7319+ ((bike *)bluetoothManager->device())->changeResistance(currentResistance - step);
7320+ } else if (hrmin > bluetoothManager->device()->currentHeart().average20s() &&
7321+ currentResistance < maxResistance) {
7322+ resistance_t newResistance = std::min(static_cast<resistance_t>(currentResistance + step), static_cast<resistance_t>(maxResistance));
7323+ qDebug() << QStringLiteral("BIKE PID HR - HR < HRmin, INCREASING resistance from")
7324+ << currentResistance << QStringLiteral("to") << newResistance;
7325+ ((bike *)bluetoothManager->device())->changeResistance(newResistance);
7326+ } else {
7327+ qDebug() << QStringLiteral("BIKE PID HR - No action taken (in zone or at limits)");
7328+ }
72507329 }
72517330 } else if (bluetoothManager->device()->deviceType() == ROWING) {
72527331
0 commit comments