-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix tmp102 negative calculation #6320
Conversation
Hey there @timsavage, mind taking a look at this pull request as it has been labeled with an integration ( |
@@ -39,9 +39,6 @@ void TMP102Component::update() { | |||
return; | |||
} | |||
raw_temperature = i2c::i2ctohs(raw_temperature); | |||
if (raw_temperature & 0x8000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for removing this code here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required to move the high bit to allow for negative numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect a proper fix might be to look at the example in the SparkFun library here.
Check if the device is in 12 or 13bit mode and apply the correct bit manipulation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That code isn't moving anything. The high bit is already set, it's a 2s-complement number and the right shift will work correctly. The only change that was required was the data type change. The code that I removed actually modified the value. It would only matter if it was a very negative temperature, but it was incorrect.
What does this implement/fix?
Corrects the change in #6316.
Types of changes
Related issue or feature (if applicable): fixes
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#
Test Environment
Example entry for
config.yaml
:# Example config.yaml
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: