-
Notifications
You must be signed in to change notification settings - Fork 247
feat: reset usb when needed #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a smart USB reset mechanism that attempts to configure USB gadgets without resetting first, and only resets when necessary. The changes add a UsbResetMode enum with three modes: UsbResetNever, UsbResetAlways, and UsbResetOnDemand. The on-demand mode tries configuration without reset, and if it fails, performs a reset and retries.
- Added
UsbResetModeenum to control USB reset behavior - Refactored USB gadget configuration to support retry logic with on-demand resets
- Updated mass storage and device configuration functions to use appropriate reset modes
- Fixed TypeScript async callback declarations in UI routes
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/usbgadget/config.go | Introduced UsbResetMode enum and refactored configureUsbGadget to implement retry logic with on-demand USB reset |
| usb_mass_storage.go | Updated mass storage functions to use UsbResetOnDemand mode and replaced direct file writes with OverrideGadgetConfig |
| jsonrpc.go | Modified updateUsbRelatedConfig to accept UsbResetMode parameter and updated all call sites with appropriate reset modes |
| ui/src/routes/devices.$id.settings.general.update.tsx | Added async modifier to onClose callback to properly handle async operations |
| ui/src/routes/devices.$id.settings.general.reboot.tsx | Added async modifier to onClose callback and imported sleep utility |
| ui/src/routes/devices.$id.settings.advanced.tsx | Added async modifier to reset config button's onClick handler and imported sleep utility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| // if the initial attempt failed, try to configure the gadget again with the resetUsb flag | ||
| if resetUsbMode == UsbResetOnDemand { | ||
| u.log.Warn().Err(err).Msg("initial attempt to configure the gadget failed, resetting USB gadget then trying again") | ||
| // NOTES: do not use the RebindUsb method here because it will block the transaction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...do not use the public RebindUsb method...
I completely misread this the first time ;)
|
Unmounting an mounted image breaks the USB gadget, so there is no mouse or keyboard after unmounting.
Rebooting is the only thing that solves the problem |
Fixes #244