Skip to content

Commit 50d56ea

Browse files
committed
Fix: Preserve direction-change commands when stopping motors
1 parent 494c252 commit 50d56ea

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/components/EscDshotDirection/EscDshotDirectionComponent.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ class EscDshotDirectionComponent {
419419
return;
420420
}
421421

422-
// SPACEBAR RELEASE: Stop motors immediately
422+
// SPACEBAR RELEASE: Stop motors (preserves pending direction changes)
423+
// Motors stop immediately unless direction change is in progress (~100ms delay)
423424
if (event.code === "Space") {
424425
event.preventDefault();
425426
event.stopPropagation();
@@ -475,11 +476,11 @@ class EscDshotDirectionComponent {
475476
this._deactivateWizardMotorButtons();
476477
}
477478

478-
// Stop motors (this adds stop commands to the queue)
479+
// Stop motors - adds stop commands to end of queue (preserves pending direction changes)
479480
this._motorDriver.stopAllMotorsNow();
480481

481-
// Deactivate motor driver - this tells queue to stop AFTER processing current commands
482-
// This is critical - it allows direction change + save commands to complete
482+
// Deactivate motor driver - prevents new commands and stops queue when empty
483+
// Queue will drain naturally, completing any pending direction change + save commands
483484
this._motorDriver.deactivate();
484485

485486
// Clear wizard flag after motor driver deactivation

src/components/EscDshotDirection/EscDshotDirectionMotorDriver.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ class EscDshotDirectionMotorDriver {
4646
}
4747

4848
stopAllMotorsNow() {
49-
this._EscDshotCommandQueue.clear();
49+
// Adds stop command to END of queue without clearing pending commands
50+
// This preserves critical direction-change + save commands that must complete
51+
//
52+
// Expected behavior:
53+
// - Normal case: Motors stop immediately (no pending commands)
54+
// - Edge case: If direction change is in progress when called, queue contains:
55+
// [stop, pause, direction+save, resume, STOP] - motor may briefly spin for
56+
// ~100ms (one queue interval) between resume and final stop
57+
//
58+
// This trade-off ensures direction changes are never lost while maintaining
59+
// prompt motor stopping for safety
5060
this._spinAllMotors(this._motorStopValue);
5161
}
5262

0 commit comments

Comments
 (0)