Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/devices/horizontreadmill/horizontreadmill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,13 @@ void horizontreadmill::update() {
requestSpeed = -1;

if (requestSpeed != -1) {
bool minSpeed =
fabs(requestSpeed - float_one_point_round(currentSpeed().value())) >= (minStepSpeed() - 0.09);
bool forceSpeedNeed = checkIfForceSpeedNeeding(requestSpeed);
qDebug() << "requestSpeed=" << requestSpeed << minSpeed << forceSpeedNeed
<< float_one_point_round(currentSpeed().value());
if (float_one_point_round(requestSpeed) != float_one_point_round(currentSpeed().value()) && minSpeed && requestSpeed >= 0 && requestSpeed <= 22 &&
forceSpeedNeed) {
emit debug(QStringLiteral("writing speed ") + QString::number(requestSpeed));
forceSpeed(float_one_point_round(requestSpeed));
// DEBUG BUILD: always skip the .1 rounding and the minStepSpeed threshold so a raw
// 0.01 km/h delta actually reaches forceSpeed()/FTMS instead of being filtered out.
if (requestSpeed >= 0 && requestSpeed <= 22 && requestSpeed != currentSpeed().value()) {
qDebug() << "[QZ_DEBUG_SPEED_001_STEP]" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs)
<< "forcing raw requestSpeed=" << requestSpeed
<< "currentSpeed=" << currentSpeed().value();
forceSpeed(requestSpeed);
}
requestSpeed = -1;
}
Expand Down Expand Up @@ -1237,6 +1235,12 @@ void horizontreadmill::forceSpeed(double requestSpeed) {
write[12] = datas[2];
write[13] = datas[3];

qDebug() << "[QZ_DEBUG_SPEED_001_STEP]" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs)
<< "raw Horizon custom-protocol bytes="
<< QByteArray((const char *)write, sizeof(write)).toHex(' ')
<< "requestSpeed=" << requestSpeed
<< "(note: this protocol only has 0.1 km/h resolution, a 0.01 step won't change the bytes)";

writeCharacteristic(gattCustomService, gattWriteCharCustomService, write, sizeof(write),
QStringLiteral("forceSpeed"), false, true);
} else {
Expand All @@ -1261,6 +1265,12 @@ void horizontreadmill::forceSpeed(double requestSpeed) {
initData02_paragon[11] = datas[1];
initData02_paragon[12] = datas[2];

qDebug() << "[QZ_DEBUG_SPEED_001_STEP]" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs)
<< "raw Horizon Paragon-X custom-protocol bytes="
<< QByteArray((const char *)initData02_paragon, sizeof(initData02_paragon)).toHex(' ')
<< "requestSpeed=" << requestSpeed
<< "(note: this protocol only has 0.1 km/h resolution, a 0.01 step won't change the bytes)";

writeCharacteristic(gattCustomService, gattWriteCharCustomService, initData02_paragon,
sizeof(initData02_paragon), QStringLiteral("forceSpeed"), false, false);
}
Expand Down Expand Up @@ -1289,6 +1299,11 @@ void horizontreadmill::forceSpeed(double requestSpeed) {
writeS[1] = speed_int & 0xFF;
writeS[2] = speed_int >> 8;

qDebug() << "[QZ_DEBUG_SPEED_001_STEP]" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs)
<< "raw FTMS SetTargetSpeed bytes="
<< QByteArray((const char *)writeS, sizeof(writeS)).toHex(' ')
<< "requestSpeed=" << requestSpeed;

writeCharacteristic(gattFTMSService, gattWriteCharControlPointId, writeS, sizeof(writeS),
QStringLiteral("forceSpeed"), false, false);
}
Expand Down
20 changes: 6 additions & 14 deletions src/homeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QByteArray>
#include <QClipboard>
#include <QCryptographicHash>
#include <QDateTime>
#include <QDesktopServices>
#include <QDir>
#include <QDirIterator>
Expand Down Expand Up @@ -5222,20 +5223,11 @@ void homeform::Plus(const QString &name) {
speed = targetspeed;
if (requestedspeed != -1)
speed = requestedspeed;
double minStepSpeed = ((treadmill *)bluetoothManager->device())->minStepSpeed();
double step =
settings.value(QZSettings::treadmill_step_speed, QZSettings::default_treadmill_step_speed).toDouble();
if (!miles)
step = ((double)qRound(step * 10.0)) / 10.0;
if (step > minStepSpeed)
minStepSpeed = step;
int rest = 0;
if (!miles)
rest = (minStepSpeed * 10.0) - (((int)(speed * 10.0)) % (uint8_t)(minStepSpeed * 10.0));
if (rest == 5 || rest == 0)
speed = speed + minStepSpeed;
else
speed = speed + (((double)rest) / 10.0);
// DEBUG BUILD: always forces a raw 0.01 km/h increment per tap to probe how the
// treadmill firmware reacts to the smallest possible FTMS set-speed step.
speed = speed + 0.01;
qDebug() << "[QZ_DEBUG_SPEED_001_STEP]" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs)
<< "plus tapped, requesting speed =" << speed;

((treadmill *)bluetoothManager->device())->changeSpeed(speed);
}
Expand Down
Loading