Repository navigation
fix: stop ultrasonic trigger pulses when measurement is interrupted - #314
YashAnand69 wants to merge 1 commit into
Conversation
|
Sorry @YashAnand69, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 1 day and 18 hours by commenting |
Reviewer's GuideThe PR makes HC-SR04 measurement cleanup exception-safe by placing the existing wait in a try/finally that drives the trigger LOW, and adds controlled-interface tests covering interrupted waits, both trigger pins, command ordering, and existing success/error outcomes. Sequence diagram for exception-safe HC-SR04 measurement cleanupsequenceDiagram
participant Caller
participant HCSR04
participant PWM
participant Timer
participant LogicAnalyzer
Caller->>HCSR04: estimate_distance(average)
HCSR04->>PWM: set_state(trigger HIGH, duty_cycles)
HCSR04->>Timer: sleep(measure_period * (average + 1))
alt wait completes
Timer-->>HCSR04: return
else wait interrupted
Timer-->>HCSR04: raise interruption
end
HCSR04->>PWM: set_state(trigger LOW)
alt wait was interrupted
HCSR04-->>Caller: propagate original interruption
else wait completed
HCSR04->>LogicAnalyzer: fetch_data()
HCSR04-->>Caller: return distance
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk | ⚪ Minimal · up to
|
Interrupting HC-SR04 distance measurement with Ctrl+C during its acquisition wait leaves the recurring trigger pulses enabled. The command that returns the trigger output LOW is skipped when the wait raises.
Put the existing wait in try/finally so the LOW command is attempted before propagating the interruption. Successful capture timing, pulse settings, command order and distance calculation remain unchanged. The logic analyzer is not stopped or reconfigured by this change.
Validation: four interruption regressions fail on unchanged main; four normal/error controls pass. The fixed branch passes eight new tests plus 33 existing hardware-independent CLI, Pico and gas-sensor tests (41 total). Tests construct HCSR04 with controlled instrument interfaces, verify SQ1/SQ4 cleanup, retain the original exception and check successful distance calculation. Configured Black, Flake8, Bandit and pydocstyle, wheel/sdist and Sphinx builds pass; seven existing documentation warnings remain.
No physical PSLab/HC-SR04 or full hardware integration run was performed. Cleanup still requires a working device transport; it cannot guarantee the output changes if the LOW command itself fails. Current rules, issue claims and all open PR patches were checked; no overlapping cleanup fix found. Developed and tested with Codex assistance.
Summary by Sourcery
Guarantee that HC-SR04 measurement interruptions disable the trigger output before propagating the error.
Bug Fixes:
Tests:
Summary by CodeRabbit