Skip to content

Commit

Permalink
Min and Max inclination for treadmill (#1962)
Browse files Browse the repository at this point in the history
* That the treadmill always has a minimum slope (Issue #1960)

* Update qzsettings.h

* Update qzsettings.h

* Update treadmill.cpp
  • Loading branch information
cagnulein authored Jan 8, 2024
1 parent ee1201c commit 397379a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/qzsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/qzsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
74 changes: 74 additions & 0 deletions src/settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/treadmill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 397379a

Please sign in to comment.