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

fix tmp102 negative calculation #6320

Merged
merged 1 commit into from
Mar 4, 2024
Merged

fix tmp102 negative calculation #6320

merged 1 commit into from
Mar 4, 2024

Conversation

ssieb
Copy link
Member

@ssieb ssieb commented Mar 4, 2024

What does this implement/fix?

Corrects the change in #6316.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@ssieb ssieb marked this pull request as ready for review March 4, 2024 07:10
@probot-esphome
Copy link

probot-esphome bot commented Mar 4, 2024

Hey there @timsavage, mind taking a look at this pull request as it has been labeled with an integration (tmp102) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@ssieb ssieb added this to the 2024.2.2 milestone Mar 4, 2024
@jesserockz jesserockz enabled auto-merge (squash) March 4, 2024 07:21
@@ -39,9 +39,6 @@ void TMP102Component::update() {
return;
}
raw_temperature = i2c::i2ctohs(raw_temperature);
if (raw_temperature & 0x8000) {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

@jesserockz jesserockz merged commit 56837b0 into dev Mar 4, 2024
57 checks passed
@jesserockz jesserockz deleted the ssieb-patch-1 branch March 4, 2024 07:33
jesserockz pushed a commit that referenced this pull request Mar 5, 2024
@jesserockz jesserockz mentioned this pull request Mar 5, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants