Skip to content

Fall back between HID backends within a single run - #152

Merged
carlossless merged 8 commits into
masterfrom
feat/runtime-backend-fallback
Sep 3, 2026
Merged

Fall back between HID backends within a single run#152
carlossless merged 8 commits into
masterfrom
feat/runtime-backend-fallback

Conversation

@carlossless

@carlossless carlossless commented Sep 2, 2026

Copy link
Copy Markdown
Owner

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:

  • Api in the selector: open, refresh_devices, device_list, open_path.
  • ISPHandle in 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::open makes it in the Native arm instead of testing at run time which backend it got. ISPHandle is a plain newtype on wasm, where WebHID is the only backend.

Testing

fmt, clippy, cargo test --workspace --lib --bins, the wasm build, nix build, and cargo check --bins for x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc and x86_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.

`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.
@carlossless
carlossless marked this pull request as ready for review September 3, 2026 20:07
@carlossless
carlossless merged commit 335bb3d into master Sep 3, 2026
9 checks passed
@carlossless
carlossless deleted the feat/runtime-backend-fallback branch September 3, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant