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

convertTo2sComplement() needs to be removed #6

Open
torriem opened this issue Jan 6, 2020 · 1 comment
Open

convertTo2sComplement() needs to be removed #6

torriem opened this issue Jan 6, 2020 · 1 comment

Comments

@torriem
Copy link

torriem commented Jan 6, 2020

I'm a baffled as to why there's a member function called, convertTo2sComplement(). Integers of any size in C are by definition two's complement already. There's nothing to convert.

Furthermore, the result of convertTo2sComplement() for any negative value is always 2, which is clearly incorrect.

The solution is to remove the function entirely. It's not needed and no other MMA8252 library I've looked at has one. They all just write the uint8_t offset values directly to the appropriate I2C registers.

@torriem torriem changed the title convertTo2scomplement() needs to be removed convertTo2sComplement() needs to be removed Jan 6, 2020
@akupila
Copy link
Owner

akupila commented Jan 9, 2020

The code is 6 years old so it's hard to say why anything is the way it is. Looks like this is a typo that never surfaced as it only affects setOffsets. The typo is the double &&, which should be &:

value = (0xFF && ~value) + 1;

I believe you're correct in the method being unnecessary but i'm inclined to not touch this code too much as i have no way of testing it. If you put together a PR, i'll trust you to verify it works and accept it.

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

No branches or pull requests

2 participants