-
Notifications
You must be signed in to change notification settings - Fork 45
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
API V2 Review - DS18x20 Component #644
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 tasks
tyeth
reviewed
Oct 18, 2024
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.
Was initially confused to see changes to the SensorModel class in src/components/sensor/model.cpp and .h, but they're presumably no longer used.
tyeth
reviewed
Oct 18, 2024
tyeth
reviewed
Oct 18, 2024
tyeth
reviewed
Oct 18, 2024
tyeth
reviewed
Oct 18, 2024
100% agree that's what I believe it does too.
The comment confused me though as it doesn't mention the division ( /16)
instead talking about a 16bit integer data type.
I only understood after visiting the getTemp2 function
…On Tue, 22 Oct 2024, 21:05 Brent Rubell, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/components/ds18x20/hardware.cpp
<#644 (comment)>
:
> + _drv_therm.convertTemp(_sensorId, DSTherm::MAX_CONV_TIME, false);
+
+ if (ec != OneWireNg::EC_SUCCESS)
+ return false;
+
+ // Scratchpad placeholder is static to allow reuse of the associated
+ // sensor id while reissuing readScratchpadSingle() calls.
+ // Note, due to its storage class the placeholder is zero initialized.
+ static Placeholder<DSTherm::Scratchpad> scrpd;
+ ec = _drv_therm.readScratchpad(_sensorId, scrpd);
+ if (ec != OneWireNg::EC_SUCCESS)
+ return false;
+
+ // Read the temperature from the sensor
+ long temp = scrpd->getTemp2();
+ _temp_c = temp / 16.0; // Convert from 16-bit int to float
@tyeth <https://github.com/tyeth> I could be wrong! This is why we review
each other's math.
Here's what I think this does,
- getTemp2() is the "Temperature in Celsius degrees returned as
fixed-point integer with multiplier 16"
- e.g. 20.125 C is returned as 322.
- We read temp as a long, scaled by x16
- To get the real temperature, we divide that long value by 16
- Then, we assign the value to a float, _temp_c
—
Reply to this email directly, view it on GitHub
<#644 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTBZ45QWHKFEWSSWG7QMJ3Z42VZ7AVCNFSM6AAAAABQGEAR2SVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGOBWGE4DCNBUGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
.com>
|
I'm going to adjust the comment to reflect this conversation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've cherry-picked only the commits for the DS18x20 component and selected the base as the migration branch, the file sto review should mostly reflect the DS18x20 API.
Please do not merge this branch, this is a review-only PR.
Resolves #638