Clarify MotorHat disposal/ownership semantics in README - #2584
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix unclear documentation around disposing of DCMotor with MotorHat
Clarify MotorHat disposal/ownership semantics in README
Jul 1, 2026
raffaeler
approved these changes
Jul 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the MotorHat device documentation to clarify resource ownership and disposal behavior when creating motors/servos/PWM channels from MotorHat, aiming to prevent confusion about whether returned objects must be disposed and in what order.
Changes:
- Adds a new “Resource management (disposing)” section describing
MotorHatownership and cleanup responsibilities. - Provides updated usage guidance and a wrapper-class example that forwards disposal to
MotorHat.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
krwq
reviewed
Jul 30, 2026
Comment on lines
+85
to
+88
| { | ||
| // Disposing the MotorHat stops and releases every motor/channel it created. | ||
| // If you dispose motors explicitly, dispose them before disposing the MotorHat. | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| { | |
| // Disposing the MotorHat stops and releases every motor/channel it created. | |
| // If you dispose motors explicitly, dispose them before disposing the MotorHat. | |
| } | |
| { | |
| // Dispose motors first (their Dispose stops the PWM channels), | |
| // then dispose the MotorHat which releases the underlying PCA9685 + I2C device. | |
| foreach (var motor in _motors) | |
| { | |
| motor.Dispose(); | |
| } | |
| _motorHat.Dispose(); | |
| } |
Contributor
Author
There was a problem hiding this comment.
Done — updated the Dispose example with the motors-first loop and correct indentation in dbdd54a.
krwq
approved these changes
Jul 30, 2026
pgrawehr
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The MotorHat README showed a
DCMotorbeing created but never disposed, leaving it unclear whether motors need separate disposal, whether dispose order matters, and whether disposing both theMotorHatand its motors causes conflicts.Confirmed from the source that there is no conflict:
MotorHat.Dispose()stops all channels it created and disposes the underlying PCA9685, whileDCMotor3Pwm.Dispose()only stops its PWM pins (never disposes them). Disposal is therefore idempotent and order-independent.Changes
src/devices/MotorHat/README.mdcovering the ownership model:MotorHatalone releases every motor/servo/PWM channel it handed out.PumpController-style example forwarding disposal to theMotorHat.