Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app-shell,usb-bridge): improve flex usb communication #14170

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
format the py side
  • Loading branch information
sfoster1 committed Dec 12, 2023
commit 2d3816c49561af9c0466186a27f2d21b6aa1a3a2
10 changes: 7 additions & 3 deletions usb-bridge/ot3usb/serial_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _try_write_all_data(serial: serial.Serial, data: bytes, packet_limit: int) -
return
while sent < len(data):
try:
sent += serial.write(data[sent:min(sent+packet_limit, len(data))])
sent += serial.write(data[sent : min(sent + packet_limit, len(data))])
except Exception as e:
# Any exception means we need to quit
print(f"Failed to write: {e}")
Expand All @@ -39,7 +39,9 @@ def _worker(queue: QUEUE_TYPE, packet_limit: int) -> None:
_try_write_all_data(ser, data, packet_limit)


def create_worker_thread(packet_limit: int = DEFAULT_PACKET_LIMIT) -> Tuple[threading.Thread, QUEUE_TYPE]:
def create_worker_thread(
packet_limit: int = DEFAULT_PACKET_LIMIT,
) -> Tuple[threading.Thread, QUEUE_TYPE]:
"""Create a serial worker thread. Returns the comms queue.

packet_limit is a maximum size for a single usb packet which is sent no more
Expand All @@ -50,7 +52,9 @@ def create_worker_thread(packet_limit: int = DEFAULT_PACKET_LIMIT) -> Tuple[thre

queue: QUEUE_TYPE = Queue(QUEUE_MAX_ITEMS)
thread = threading.Thread(
target=_worker, name="serial worker", kwargs={"queue": queue, "packet_limit": packet_limit}
target=_worker,
name="serial worker",
kwargs={"queue": queue, "packet_limit": packet_limit},
)

return (thread, queue)
Loading