Fall back between HID backends within a single run - #152
Merged
Conversation
`Backend::available()` replaces the hand-rolled filter over a hardcoded list, and an empty list now falls back to `Backend::default()` instead of indexing out of bounds. The explicit `nusb` feature is redundant now that hidra enables it by default.
The path patch only resolved on a checkout that happened to sit next to a hidra clone, so CI failed to read ../hidra/Cargo.toml before it got as far as compiling anything.
hidra selects its backend by type now, so a field that can hold either is this crate's to declare. That is `Api` in the selector, forwarding the three methods it uses, and `IspHandle` in the library, forwarding the three the protocol needs. Rotating between backends works as before. The macOS exclusive-open call is inherent to the native backend, so it no longer needs a run-time check that the backend is the right one.
The git patch was a stopgap while the backend API was unreleased.
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.
Depends on hidra 0.0.4, where the backend became a type parameter rather than a run-time enum.
Because the two backends are now distinct types, a field that can hold either is this crate's to declare, which is the point: sinowisp is the only consumer that swaps backends mid-run, and doing it here costs far less than the dispatch layer hidra was carrying for everyone.
Two small enums, forwarding only what is actually used:
Apiin the selector:open,refresh_devices,device_list,open_path.ISPHandlein the library:send_feature_report,get_feature_report,get_report_descriptor.Rotating between backends in the retry loop works exactly as before; each still sees devices the other cannot, and ISP mode still swaps which.
The macOS exclusive-open call is inherent to the native backend now, so
Api::openmakes it in theNativearm instead of testing at run time which backend it got.ISPHandleis a plain newtype on wasm, where WebHID is the only backend.Testing
fmt, clippy,
cargo test --workspace --lib --bins, the wasm build,nix build, andcargo check --binsforx86_64-unknown-linux-gnu,x86_64-pc-windows-msvcandx86_64-apple-darwin. The Windows cross-check matters here: that two-handle path is#[cfg(target_os = "windows")], so a Linux build does not compile it, and it needed fixing twice during this change.