forked from whitequark/libfx2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for polling USB fds, alongside synchronous calls.
- Loading branch information
1 parent
36563a7
commit 9dac8a6
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import select | ||
|
||
|
||
_cls_select_poll = type(select.poll()) | ||
|
||
|
||
class poll_wrapper: | ||
def __init__(self, wrapped): | ||
self.wrapped = wrapped | ||
|
||
def register(self, *args, **kwargs): | ||
self.wrapped.register(*args, **kwargs) | ||
|
||
def modify(self, *args, **kwargs): | ||
self.wrapped.modify(*args, **kwargs) | ||
|
||
def unregister(self, *args, **kwargs): | ||
self.wrapped.unregister(*args, **kwargs) | ||
|
||
def poll(self, timeout=None): | ||
if timeout is None: | ||
return self.wrapped.poll() | ||
else: | ||
return self.wrapped.poll(round(timeout * 1000)) | ||
|
||
|
||
# As per libusb1 documentation, work around the mismatch of select.poll | ||
# timeout argument (in milliseconds) and the one expected by USBPoller | ||
# (in seconds). | ||
def wrap_poller_for_libusb(poller): | ||
if isinstance(poller, _cls_select_poll): | ||
return poll_wrapper(poller) | ||
else: | ||
return poller |