Skip to content

fix: ALVIKDEV-108 UART read extremely slow on bytewise access #35

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

Merged
merged 2 commits into from
Nov 19, 2024
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
22 changes: 11 additions & 11 deletions arduino_alvik/arduino_alvik.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ def _flush_uart():
Empties the UART buffer
:return:
"""
while uart.any():
uart.read(1)
uart.read(uart.any())

def _begin_update_thread(self):
"""
Expand Down Expand Up @@ -641,21 +640,22 @@ def _update(self, delay_=1):
self.set_behaviour(2)
if not ArduinoAlvik._update_thread_running:
break
if self._read_message():
self._parse_message()
self._read_message()
sleep_ms(delay_)

def _read_message(self) -> bool:
def _read_message(self) -> None:
"""
Read a message from the uC
:return: True if a message terminator was reached
"""
while uart.any():
b = uart.read(1)[0]
self._packeter.buffer.push(b)
if b == self._packeter.end_index and self._packeter.checkPayload():
return True
return False
buf = bytearray(uart.any())
uart.readinto(buf)
if len(buf):
uart.readinto(buf)
for b in buf:
self._packeter.buffer.push(b)
if b == self._packeter.end_index and self._packeter.checkPayload():
self._parse_message()

def _parse_message(self) -> int:
"""
Expand Down