Repository navigation
refactor: read the battery in one call behind a HID interface seam - #11
Merged
Merged
Conversation
ReportMatch only renamed its variants into Reply inside read_response, so the offline rule was spelled in two adjacent enums. match_report now returns the Reply itself, or None for an unrelated report, and the response carries its Report.
Every function on the request path took the HID interface and the device index as separate arguments, so a mixed-up index compiled silently. A Device handle now pairs them once, and the request, feature lookup, and battery read become its methods; read_response folds into request, its only caller.
The hidpp interface made callers discover a transport, then read it, and classify two failure channels (Discovery and a None status). It now exposes one read_battery(api) that returns a single Reading: a status, no status, offline, or nothing found. HidppTransport, Discovery::map, and the mem::replace/unreachable! handoff are gone. Opening HID interfaces moves behind the seam: read_battery_from takes openers, with hidapi in production and scripted interfaces in tests. Every scripted test now drives that entry point, so the lazy open, open-error, and probe-order glue that had no test is covered, and the probe_and_read/discover_single recompositions are deleted. HID errors from discovery and from the read now share the "Could not read battery level" prefix; "Could not probe Logitech HID++ interface" is gone.
The code now names the seam it probes after HID interfaces, and the bare word "interface" collides with a module's interface.
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.
Summary
hidppnow exposes one call that returns one outcome, and HID interface opening sits behind a seam both production and tests cross.Along the way:
ReportMatchis gone;match_reportreturnsOption<Reply>directly.Device { io, index }handle replaces threading the HID interface and device index through every request function.HidppTransport,Discovery::map, and themem::replace/unreachable!handoff are deleted.Evidence
open_first_working_transportor theProbeSlotglue (the cargo-mutants survivors noted in refactor: trim redundant tests and indirection in the HID++ module #9). Tests rebuild that composition withprobe_and_readanddiscover_single.After: 26 tests pass (
cargo fmt --check,cargo clippy --all-targets -- -D warningsclean). Every scripted test callsread_battery_from, the same entry point production uses. Hand mutations confirm the glue is covered now:Not run against a real GPW2.
Merge Danger
Door: two-way
Internal refactor of a private module; revert is a single squash commit.
Blast Radius: messages
The only user-visible change: HID errors during discovery now print
Could not read battery level: …instead ofCould not probe Logitech HID++ interface: …. The README troubleshooting table never listed the old prefix. Probe order, timeouts, the discovery budget, and the stop-at-first-battery-feature rule are unchanged, so read latency and failure latency are unchanged.