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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion arduino_alvik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

__author__ = "Lucio Rossi <[email protected]>, Giovanni Bruno <[email protected]>"
__license__ = "MPL 2.0"
__version__ = "1.1.1"
__version__ = "1.1.2"
__maintainer__ = "Lucio Rossi <[email protected]>, Giovanni Bruno <[email protected]>"
__required_firmware_version__ = "1.1.0"

Expand Down
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
["github:arduino/ucPack-mpy", "0.1.7"],
["github:arduino/arduino-runtime-mpy", "0.4.0"]
],
"version": "1.1.1"
"version": "1.1.2"
}