Skip to content
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

Refactor API proposal #84

Open
RobTillaart opened this issue Oct 17, 2024 · 1 comment
Open

Refactor API proposal #84

RobTillaart opened this issue Oct 17, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@RobTillaart
Copy link
Owner

RobTillaart commented Oct 17, 2024

in #82 a proposal is made to improve the API

  bool readADC(int &value)
Which returns false in case of errors and true as well as value when all is
Ok.

Users can then do
   if(readADC(value))
      handle value
   else
      handle error
  • check for the whole API to apply this pattern
  • update all examples
  • Improving the error's to include possible I2C errors.
  • New API can be implemented while keeping the old interface - optionally as depreciated.

An alternative could be

  int readADC(int &value)

return 0 if OK or the error code, so it does not need to be fetched with getError()
@deKees687
Copy link

Perhaps most users are not interested in error handling. They just want results in the easiest way possible. For those users it is handy to keep readADC() that returns the adc value. Changing this function will break API and cause annoyance to existing users so I would keep that interface.

The longer timeout is no problem because that will never result in extra delays as long as all is OK. And it does not need any changes in user code anyway.

The alternative readADC(&Value)
return 0 if OK, errorcode when error:
This would make user code a little more complicated. It is no longer possible to put the call in an if() statement as you would want to preserve the error code. And you still need to call getError() if you want to clear the internal error code. So you get code like:

int Value;
int Rc = readADC(Value);
if(Rc == ADS1X15_OK )
   Handle value
else 
   Handle Error

So at the end, I would keep the interface as-is. Don't break user code. And update the examples to show how to use the API in the easy way and how to use it in a proper error-handling way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants