Skip to content

Added error handling #6

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
Aug 22, 2024
Merged

Conversation

ufanders
Copy link
Contributor

I found many avenues where this library could lock the system and patched them so we can always return.

  • Fixed AS7261 hardware ID.
  • Changed protos for all functions with Wire failure potential.
  • Added fcn exits for Wire failures.
  • Added local timeout for measurement fcn.
  • Added retry limit.

ufanders added 2 commits July 25, 2024 23:45
- Changed protos for all functions with Wire failure potential.
- Added fcn exits for Wire failures.
- Added local timeout for measurement fcn.
- Added retry limit.
@nseidle
Copy link
Member

nseidle commented Aug 22, 2024

Thank you for this! Much better with your improvements. But do please explain how the retries line works. We realize it works just fine, but how? It has me and a few fellow engineers debating post increment variable tests.

@nseidle nseidle merged commit ecdbf3f into sparkfun:master Aug 22, 2024
@ufanders
Copy link
Contributor Author

Hi @nseidle, thanks so much for merging I think this will save people a lot of work down the road. The retries line works because post-(in/de)crement operators execute after the variable is used in the conditional statement. pre-(in/de)crement operators execute before the variable is used. More here: https://www.geeksforgeeks.org/pre-increment-and-post-increment-in-c/

=]

@nseidle
Copy link
Member

nseidle commented Aug 23, 2024

Thank you! We assumed this but that doesn't explain how we see x stopping at 255. uint_8 wraps at 255 so:

x = 254
(x++ > x) equates to "is 254 > 254?" No, so x becomes 255

x = 255
(x++ > x) -> is 255 > 255? No -> x=0

x = 0
(0++ > 0) -> is 0 > 0? No-> x=1
...

I know this doesn't reflect reality, but what am I missing?

@ufanders
Copy link
Contributor Author

Durrr yeah I made the assumption the number of retries would never be set to such a high number, so it should break under that condition! 😅

@nseidle
Copy link
Member

nseidle commented Aug 23, 2024

number of retries would never be set to such a high number

I am even more confused. The number of retries is not set as far as I can see. I assumed you were relying on a roll-over trick to cap the retries at 255. Am I mistaken? What was your intent with the retries line?

@ufanders
Copy link
Contributor Author

I define retries as 3 here: https://github.com/sparkfun/SparkFun_AS726X_Arduino_Library/blob/master/src%2FAS726X.h#L172

Other than that, I dunno!

@nseidle
Copy link
Member

nseidle commented Aug 26, 2024

Ah! Now I see you basically have a typo but got really lucky :)

if(retries++ > retries) return 0xFF;

should be

if(retries++ > RETRIES) return 0xFF;

We just got lucky that (retries++ > retries) fails at 255 and not infinity. I'll fix it.

@ufanders
Copy link
Contributor Author

Oh boy, thanks for catching that! Now to make sure I'm not doing the same in my production code...

As an aside, I remember talking directly to you over email sometime when I was in college (2001-2005). I'm thrilled to see how SparkFun has become bedrock for the embedded community, and how responsive the team still is 20 years later.

=]

@nseidle
Copy link
Member

nseidle commented Aug 26, 2024

Np!

Crazy! I'm pleased (and just as shocked as you are!) that we're still around. Thanks again for helping out the open source world. Let us know if anything else pops up.

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