-
Notifications
You must be signed in to change notification settings - Fork 53
Allow uart to go ~100Hz versus 10Hz #50
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
Changes from 3 commits
9820d4d
8483415
7147de8
0879db5
8434806
d73e432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,7 +392,9 @@ def _write_register(self, register, data): # pylint: disable=arguments-differ | |
if not isinstance(data, bytes): | ||
data = bytes([data]) | ||
self._uart.write(bytes([0xAA, 0x00, register, len(data)]) + data) | ||
time.sleep(0.1) | ||
now = time.time() | ||
while self._uart.in_waiting < 2 and time.time() - now < 0.25: | ||
pass | ||
resp = self._uart.read(self._uart.in_waiting) | ||
if len(resp) < 2: | ||
raise OSError("UART access error.") | ||
|
@@ -401,12 +403,27 @@ def _write_register(self, register, data): # pylint: disable=arguments-differ | |
|
||
def _read_register(self, register, length=1): # pylint: disable=arguments-differ | ||
self._uart.write(bytes([0xAA, 0x01, register, length])) | ||
time.sleep(0.1) | ||
now = time.time() | ||
while self._uart.in_waiting < length + 2 and time.time() - now < 0.25: | ||
pass | ||
resp = self._uart.read(self._uart.in_waiting) | ||
|
||
if resp[0] != 0xBB: # Recursion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not recursion because recursion would call _read_register. Why did you add this? It wasn't needed before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My initial plan was to actually do that, but I couldn't think of a good way to add in an exit condition so it didn't just keep going until it reached the recursion limit, and I guess I forgot to remove the comment. It's needed because the, when running in UART mode, even in the version that's currently on master, it raises a UART read error every 3 or 4 reads when you're trying to use the simpletest. I think that before it may have mostly been tested by getting a single value, such as acceleration, at a time. That being said, even though I know the majority of people aren't using this with UART, I am quite surprised that I haven't seen anyone else encountering that issue, so it may be worthwhile for some other people with the sensor to do some testing to ensure that issue doesn't only affect me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the errors go away if you increase the timeout? If you really need it, I think you could just have an outer loop and count how many tries you want to do before raising an error. No need to copy things a second time. |
||
self._uart.write(bytes([0xAA, 0x01, register, length])) | ||
now = time.time() | ||
while self._uart.in_waiting < length + 2 and time.time() - now < 0.25: | ||
pass | ||
resp = self._uart.read(self._uart.in_waiting) | ||
if len(resp) < 2: | ||
raise OSError("UART access error.") | ||
if resp[0] != 0xBB: | ||
raise RuntimeError("UART read error: {}".format(resp[1])) | ||
if length > 1: | ||
return resp[2:] | ||
return int(resp[2]) | ||
|
||
if len(resp) < 2: | ||
raise OSError("UART access error.") | ||
if resp[0] != 0xBB: | ||
raise RuntimeError("UART read error: {}".format(resp[1])) | ||
if length > 1: | ||
return resp[2:] | ||
return int(resp[2]) | ||
|
Uh oh!
There was an error while loading. Please reload this page.