Skip to content

Commit 4fcff21

Browse files
cagnuleinclaude
andcommitted
fix: KickRun speed display and rapid-press accumulation
- Override changeSpeed() to base subsequent rapid presses on the already-pending requestSpeed rather than the stale telemetry speed. This prevents multiple quick taps all sending the same speed value. - After sending a BLE speed command, set Speed = requestSpeed optimistically and set paddlePending = true. This makes the speed tile update immediately in the UI instead of waiting for the belt to physically move. - While paddlePending is true, telemetry speed notifications are ignored so they don't overwrite the displayed commanded speed. paddlePending is cleared when the KICKR RUN issues its paddle-push challenge (FD E0 01). - Changed the speed-equality check to use abs() > 0.01 (km/h) to avoid repeated BLE writes caused by floating-point rounding in the telemetry µm/s conversion. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 760feda commit 4fcff21

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/devices/wahookickruntreadmill/wahookickruntreadmill.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ void wahookickruntreadmill::forceSpeed(double speed) {
9090
QStringLiteral("forceSpeed ") + QString::number(speed));
9191
}
9292

93+
void wahookickruntreadmill::changeSpeed(double speed) {
94+
if (requestSpeed >= 0) {
95+
// Another command is already pending (not yet sent by update()).
96+
// Accumulate from the pending speed rather than the (stale) telemetry speed.
97+
double step = speed - currentSpeed().value();
98+
requestSpeed = qMax(0.0, requestSpeed + step);
99+
RequestedSpeed = requestSpeed;
100+
} else {
101+
treadmill::changeSpeed(speed);
102+
}
103+
}
104+
93105
void wahookickruntreadmill::update() {
94106
if (!m_control || m_control->state() == QLowEnergyController::UnconnectedState) {
95107
emit disconnected();
@@ -120,9 +132,13 @@ void wahookickruntreadmill::update() {
120132
update_metrics(true, watts(settings.value(QZSettings::weight, QZSettings::default_weight).toFloat()));
121133

122134
if (requestSpeed != -1) {
123-
if (requestSpeed != currentSpeed().value() && requestSpeed >= 0) {
135+
if (std::abs(requestSpeed - currentSpeed().value()) > 0.01 && requestSpeed >= 0) {
124136
emit debug(QStringLiteral("writing speed ") + QString::number(requestSpeed));
125137
forceSpeed(requestSpeed);
138+
// Show commanded speed immediately; suppress telemetry overwrite until paddle push.
139+
Speed = requestSpeed;
140+
lastSpeed = requestSpeed;
141+
paddlePending = true;
126142
}
127143
requestSpeed = -1;
128144
}
@@ -132,6 +148,7 @@ void wahookickruntreadmill::update() {
132148
if (lastSpeed == 0.0)
133149
lastSpeed = 0.5;
134150
forceSpeed(lastSpeed);
151+
paddlePending = true;
135152
requestStart = -1;
136153
emit tapeStarted();
137154
}
@@ -171,6 +188,7 @@ void wahookickruntreadmill::characteristicChanged(const QLowEnergyCharacteristic
171188
// FD E0 01 [code_hi] [code_lo] → paddle pushed, treadmill issued challenge
172189
if (len >= 5 && (uint8_t)newValue.at(0) == 0xFD && (uint8_t)newValue.at(1) == 0xE0 &&
173190
(uint8_t)newValue.at(2) == 0x01) {
191+
paddlePending = false; // paddle was pushed; telemetry can now reflect actual belt speed
174192
QByteArray confirm;
175193
confirm.append((char)0xE0);
176194
confirm.append(newValue.at(3));
@@ -197,9 +215,13 @@ void wahookickruntreadmill::characteristicChanged(const QLowEnergyCharacteristic
197215

198216
emit debug(QStringLiteral("KickRun speed=") + QString::number(tgt_kmh, 'f', 2));
199217

200-
if (Speed.value() != tgt_kmh)
201-
emit speedChanged(tgt_kmh);
202-
Speed = tgt_kmh;
218+
// While waiting for the user to push the paddle, suppress telemetry overwrites
219+
// so the UI keeps showing the commanded speed rather than the old belt speed.
220+
if (!paddlePending) {
221+
if (Speed.value() != tgt_kmh)
222+
emit speedChanged(tgt_kmh);
223+
Speed = tgt_kmh;
224+
}
203225

204226
if (tgt_kmh > 0) {
205227
lastSpeed = tgt_kmh;

src/devices/wahookickruntreadmill/wahookickruntreadmill.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class wahookickruntreadmill : public treadmill {
5252
bool connected() override;
5353
bool autoPauseWhenSpeedIsZero() override;
5454
bool autoStartWhenSpeedIsGreaterThenZero() override;
55+
void changeSpeed(double speed) override;
5556

5657
private:
5758
void writeCharacteristic(const QByteArray &data, const QString &info);
@@ -68,6 +69,7 @@ class wahookickruntreadmill : public treadmill {
6869

6970
QByteArray deviceId; // 4-byte device ID from the 0x86 init response
7071
bool deviceIdReceived = false;
72+
bool paddlePending = false; // speed command sent, waiting for paddle push
7173

7274
QTimer *refresh;
7375
QList<QLowEnergyService *> gattServices;

0 commit comments

Comments
 (0)