Skip to content

Commit

Permalink
Add more typing to the usb module, and catch transfer.submit() failur…
Browse files Browse the repository at this point in the history
…es that can happen when a device resumes from suspend
  • Loading branch information
C0rn3j committed Oct 28, 2024
1 parent 0d31521 commit bb5ea69
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scc/drivers/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import usb1

if TYPE_CHECKING:
from usb1 import USBDeviceHandle
from usb1 import USBDeviceHandle, USBTransfer

from scc.sccdaemon import SCCDaemon

Expand All @@ -41,7 +41,7 @@ def set_input_interrupt(self, endpoint: int, size: int, callback) -> None:
callback(endpoint, data) is called repeadedly with every packed received.
"""
def callback_wrapper(transfer) -> None:
def callback_wrapper(transfer: USBTransfer) -> None:
if (transfer.getStatus() != usb1.TRANSFER_COMPLETED or
transfer.getActualLength() != size):
return
Expand All @@ -54,7 +54,10 @@ def callback_wrapper(transfer) -> None:
log.error(e)
log.error(traceback.format_exc())
finally:
transfer.submit()
try: # https://github.com/C0rn3j/sc-controller/issues/57
transfer.submit()
except Exception:
log.exception("Failed to submit the transfer!")

transfer = self.handle.getTransfer()
transfer.setInterrupt(
Expand Down Expand Up @@ -134,7 +137,7 @@ def force_restart(self):
_usb._retry_devices.append(tp)


def claim(self, number):
def claim(self, number: int):
"""Remember list of claimed interfaces and allow to unclaim them all at once using unclaim() method
or automatically when device is closed.
Expand Down

0 comments on commit bb5ea69

Please sign in to comment.