From 397379ad9b316a424474583622aeeab5d1298573 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Mon, 8 Jan 2024 09:31:36 +0100 Subject: [PATCH] Min and Max inclination for treadmill (#1962) * That the treadmill always has a minimum slope (Issue #1960) * Update qzsettings.h * Update qzsettings.h * Update treadmill.cpp --- src/qzsettings.cpp | 6 +++- src/qzsettings.h | 6 ++++ src/settings.qml | 74 ++++++++++++++++++++++++++++++++++++++++++++++ src/treadmill.cpp | 12 ++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) diff --git a/src/qzsettings.cpp b/src/qzsettings.cpp index 66dc7e8be..12088ab60 100644 --- a/src/qzsettings.cpp +++ b/src/qzsettings.cpp @@ -697,8 +697,10 @@ const QString QZSettings::default_zwift_password = QStringLiteral(""); const QString QZSettings::garmin_bluetooth_compatibility = QStringLiteral("garmin_bluetooth_compatibility"); const QString QZSettings::norditrack_s25_treadmill = QStringLiteral("norditrack_s25_treadmill"); const QString QZSettings::proform_8_5_treadmill = QStringLiteral("proform_8_5_treadmill"); +const QString QZSettings::treadmill_incline_min = QStringLiteral("treadmill_incline_min"); +const QString QZSettings::treadmill_incline_max = QStringLiteral("treadmill_incline_max"); -const uint32_t allSettingsCount = 584; +const uint32_t allSettingsCount = 586; QVariant allSettings[allSettingsCount][2] = { {QZSettings::cryptoKeySettingsProfiles, QZSettings::default_cryptoKeySettingsProfiles}, @@ -1289,6 +1291,8 @@ QVariant allSettings[allSettingsCount][2] = { {QZSettings::garmin_bluetooth_compatibility, QZSettings::default_garmin_bluetooth_compatibility}, {QZSettings::norditrack_s25_treadmill, QZSettings::default_norditrack_s25_treadmill}, {QZSettings::proform_8_5_treadmill, QZSettings::default_proform_8_5_treadmill}, + {QZSettings::treadmill_incline_min, QZSettings::default_treadmill_incline_min}, + {QZSettings::treadmill_incline_max, QZSettings::default_treadmill_incline_max}, }; void QZSettings::qDebugAllSettings(bool showDefaults) { diff --git a/src/qzsettings.h b/src/qzsettings.h index 3bff1afed..e684d207c 100644 --- a/src/qzsettings.h +++ b/src/qzsettings.h @@ -1953,6 +1953,12 @@ class QZSettings { static const QString proform_8_5_treadmill; static constexpr int default_proform_8_5_treadmill = false; + static const QString treadmill_incline_min; + static constexpr float default_treadmill_incline_min = -100.0; + + static const QString treadmill_incline_max; + static constexpr float default_treadmill_incline_max = 100.0; + /** * @brief Write the QSettings values using the constants from this namespace. * @param showDefaults Optionally indicates if the default should be shown with the key. diff --git a/src/settings.qml b/src/settings.qml index a3ae60701..cd5adbb44 100644 --- a/src/settings.qml +++ b/src/settings.qml @@ -866,6 +866,8 @@ import QtQuick.Dialogs 1.0 property bool garmin_bluetooth_compatibility: false property bool norditrack_s25_treadmill: false property bool proform_8_5_treadmill: false + property real treadmill_incline_min: -100 + property real treadmill_incline_max: 100 } function paddingZeros(text, limit) { @@ -5426,6 +5428,78 @@ import QtQuick.Dialogs 1.0 color: Material.color(Material.Lime) } + RowLayout { + spacing: 10 + Label { + text: qsTr("Min. Inclination:") + Layout.fillWidth: true + } + TextField { + id: treadmillInclinationMinTextField + text: settings.treadmill_incline_min + horizontalAlignment: Text.AlignRight + Layout.fillHeight: false + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter + //inputMethodHints: Qt.ImhDigitsOnly + onAccepted: settings.treadmill_incline_min = text + onActiveFocusChanged: if(this.focus) this.cursorPosition = this.text.length + } + Button { + text: "OK" + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter + onClicked: { settings.treadmill_incline_min = treadmillInclinationMinTextField.text; toast.show("Setting saved!"); } + } + } + + Label { + text: qsTr("This overrides the minimum inclination value of your treadmill (in order to reduce the inclination movement). Default is -100") + font.bold: true + font.italic: true + font.pixelSize: 9 + textFormat: Text.PlainText + wrapMode: Text.WordWrap + verticalAlignment: Text.AlignVCenter + Layout.alignment: Qt.AlignLeft | Qt.AlignTop + Layout.fillWidth: true + color: Material.color(Material.Lime) + } + + RowLayout { + spacing: 10 + Label { + text: qsTr("Max. Inclination:") + Layout.fillWidth: true + } + TextField { + id: treadmillInclinationMaxTextField + text: settings.treadmill_incline_max + horizontalAlignment: Text.AlignRight + Layout.fillHeight: false + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter + //inputMethodHints: Qt.ImhDigitsOnly + onAccepted: settings.treadmill_incline_max = text + onActiveFocusChanged: if(this.focus) this.cursorPosition = this.text.length + } + Button { + text: "OK" + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter + onClicked: { settings.treadmill_incline_max = treadmillInclinationMaxTextField.text; toast.show("Setting saved!"); } + } + } + + Label { + text: qsTr("This overrides the maximum inclination value of your treadmill (in order to reduce the inclination movement). Default is -100") + font.bold: true + font.italic: true + font.pixelSize: 9 + textFormat: Text.PlainText + wrapMode: Text.WordWrap + verticalAlignment: Text.AlignVCenter + Layout.alignment: Qt.AlignLeft | Qt.AlignTop + Layout.fillWidth: true + color: Material.color(Material.Lime) + } + NewPageElement { title: qsTr("Inclination Overrides") indicatRectColor: Material.color(Material.Grey) diff --git a/src/treadmill.cpp b/src/treadmill.cpp index 60241868c..fac76d1f3 100644 --- a/src/treadmill.cpp +++ b/src/treadmill.cpp @@ -17,6 +17,18 @@ void treadmill::changeSpeed(double speed) { requestSpeed = (speed * m_difficult) + m_difficult_offset; } void treadmill::changeInclination(double grade, double inclination) { + QSettings settings; + double treadmill_incline_min = settings.value(QZSettings::treadmill_incline_min, QZSettings::default_treadmill_incline_min).toDouble(); + double treadmill_incline_max = settings.value(QZSettings::treadmill_incline_max, QZSettings::default_treadmill_incline_max).toDouble(); + + if(grade < treadmill_incline_min) { + grade = treadmill_incline_min; + qDebug() << "grade override due to treadmill_incline_min" << grade; + } else if(grade > treadmill_incline_max) { + grade = treadmill_incline_max; + qDebug() << "grade override due to treadmill_incline_max" << grade; + } + m_lastRawInclinationRequested = grade; Q_UNUSED(inclination); qDebug() << "changeInclination" << grade << autoResistanceEnable << m_inclination_difficult