Skip to content

Conversation

@haydenroche5
Copy link
Collaborator

  • Add comments explaining some of the delays used in serial and I2C comms.
  • Refactor internal functions (those with a leading _) to be snake_case. Not changing external functions to preserve backwards compatibility.
  • Change some variable names in _send_payload to improve readability. Also, fix a bug in this function where we weren't sleeping properly between segments (looks to be an indentation error). Finally, sleep 20ms between writing I2C chunks in this function, which is what we document on blues.dev as the "right way" to do it.
  • Factor out reading from the Notecard over I2C into a new internal function, _receive. This is used both by Transaction and Reset. There was also a bug in Transaction that's fixed in this new function. There was a continue statement that was preempting both our timeout check and delaying between chunks.

@haydenroche5 haydenroche5 requested a review from m-mcgowan July 27, 2023 21:38
- Add comments explaining some of the delays used in serial and I2C comms.
- Refactor internal functions (those with a leading _) to be snake_case. Not
changing external functions to preserve backwards compatibility.
- Change some variable names in _send_payload to improve readability. Also, fix
a bug in this function where we weren't sleeping properly between segments
(looks to be an indentation error). Finally, sleep 20ms between writing I2C
chunks in this function, which is what we document on blues.dev as the "right
way" to do it.
- Factor out reading from the Notecard over I2C into a new internal function,
_receive. This is used both by Transaction and Reset. There was also a bug in
Transaction that's fixed in this new function. There was a `continue` statement
that was preempting both our timeout check and delaying between chunks.
- Use the transaction manager in the Command functions for I2C and serial. Also,
use try/finally where appropriate so that the transaction manager always stops
the transaction, even if an exception gets raised.
if sent_in_seg > CARD_REQUEST_SEGMENT_MAX_LEN:
sent_in_seg -= CARD_REQUEST_SEGMENT_MAX_LEN
time.sleep(CARD_REQUEST_SEGMENT_DELAY_MS / 1000)
time.sleep(CARD_REQUEST_SEGMENT_DELAY_MS / 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

"""Reset the Notecard."""
chunk_len = 0

while not self.lock():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a timeout here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, there was no timeout before these changes, so I was trying to keep it that way. I don't think there's a need for one, but perhaps I'm missing something that you're seeing?

@haydenroche5 haydenroche5 merged commit 93927f5 into blues:main Aug 30, 2023
haydenroche5 added a commit to haydenroche5/note-python that referenced this pull request Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants