add "read_latest()" API to avoid old/lagging data#53
Draft
peter-mitrano-ar wants to merge 3 commits into
Draft
Conversation
added 2 commits
June 29, 2026 22:10
…ring and slow read loops
Reviewer's GuideImplements proper non-blocking behavior tracking in the device, introduces a new read_latest() API for draining buffered input in non-blocking mode, and updates documentation/examples/CLI to prefer blocking mode for simple loops and read_latest() for slower loops while clarifying device discovery output. Sequence diagram for nonblocking open and read_latest() behaviorsequenceDiagram
actor User
participant pyspacemouse
participant SpaceMouseDevice as mouse
participant hid_device
User->>pyspacemouse: open(nonblocking=True)
pyspacemouse->>pyspacemouse: _create_and_open_device(nonblocking=True)
pyspacemouse->>mouse: mouse.open()
pyspacemouse->>hid_device: set_nonblocking(True)
pyspacemouse->>mouse: mouse._nonblocking = True
pyspacemouse-->>User: mouse
loop slow_loop
User->>mouse: read_latest()
alt nonblocking is True
mouse->>hid_device: read(bytes_to_read)
opt data available
mouse->>mouse: _process(data)
mouse->>hid_device: read(bytes_to_read)
end
else nonblocking is False
mouse-->>User: RuntimeError
end
mouse-->>User: SpaceMouseState
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Add a new function for reading the latest data, even from a slow loop, without getting old data.
Also realized that
examples/05_discovery.pyneeds to count devices, since there could be multiple. But that's not related to reading.