-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
feature: read temperature from last humidity measurement #27
feature: read temperature from last humidity measurement #27
Conversation
Thanks, too be reviewed asap. |
Restarted CI build as something went wrong. |
|
fa553a3
to
8706f69
Compare
Merged from upstream and rebased. Please check if the name of the new method sounds good to you. Functionality is obvious from datasheet, but an example is better. Will update the merge request when done. |
I cannot find the command 0xE0 (0b11100000) in the datasheets I have. |
Found the info in the Si7021 datasheet ==> it might not be compatible with SHT20 and SHT21 et al. |
May bad, I assumed that all models have this command, not only the Si7021. It's makes for a significant performance boost, reducing the acquisition time by ~50%.
Sure, but additionally there are separate constructors for the supported sensor models. Each constructor could set its model type from an enum "Model" to a member variable "model". Then calling readTemperatureForHumidity() could just return false, maybe set a specific error code you should define. Continue? |
That is substantial and really an added value.
The object oriented way to do it is to only implement the function in the derived 7021 class. |
Good idea. Had a look through the datasheets of the supported devices and added the function where supported, effectively all chips from Silicon Labs. The protected method in the base class avoids duplicate code. Also renamed example. |
Code looks OK -
Questions wrt usageAccording to the datasheet the function does Read temperature value from previous RH measurement. What happens if you call the function e.g. multiple times e.g. with 10 seconds interval. What happens if I requestTemperature() first and then call readTemperatureForHumidity()? Depending on the answers maybe readCachedTemperature is more descriptive ? |
What the function basically does is clear from the documentation. But someone who does not read docs might use it differently. So far I did not make "abuse" tests. I suspect that you get a random or fixed reply if you just call it without doing a humidity acquisition first. After a humidity acquisition you will get the same value if you call it more than once. I will make some tests, but as I "only" have a Si7021 one cannot be sure that all Si70xx behave in the same way as they have different firmware. For me it currently boils down to: always call requestHumidity before calling readHumidity or readTemperatureForHumidity. Maybe it is necessary to even call readHumidity before readTemperatureForHumidity returns a valid value. One could try to force a workflow by tracking the calling state and returning an error value if the wrong calling sequence is used. But I think this will make the code unnecessarily complex. An inline comment and a description in the README should be enough. Will post the test results over the weekend. Currently I have the Si7021 at almost 100 °C for a few hours per day by enabling the heater to "burn" off excessive humidity/contamination, as my sensor showed an offset of ~10 %. The first burn was only for 1 hour and the offset did not change after cool-down. But with the longer burns the offset seems to decrease. Not sure jet how this will play out ... |
Appreciated and very true (not even for different batches of Si7021 )
That is what I would expect. |
Test results with a Si7021 with firmware 2.0: reset { readTemperatureForHumidity getTemperature } reset { requestTemperature readCachedTemperature getTemperature } reset { requestTemperature { reqTempReady } readCachedTemperature getTemperature } reset { requestTemperature { reqTempReady } readTemperature getTemperature readCachedTemperature getTemperature } reset { requestHumidity readCachedTemperature getTemperature } reset { requestHumidity { reqHumReady } readCachedTemperature getTemperature } reset { requestHumidity { reqHumReady } readHumidity getHumidity readCachedTemperature getTemperature } reset { requestHumidity { reqHumReady } readTemperature getTemperature } |
Test interpretation:
Recommendations (assuming the other Si70xx behave in the same way):
|
Thanks for the extended tests, in the readme you should link to this PR so the tests can be found easily. We may assume all SI70xx behave the same (until someone proves otherwise). NameWhat about
Furthermore the word last in lastTemperature() is already "taken" by
|
The name "readCachedTemperature" does not sit well with me, as cached typically implies something readily available in the local system, often in RAM. But here it is a register value in the sensor, requiring an I2C bus round trip and this is not really a cache to me. On the other hand the I2C round trip is so much faster than a separate acquisition. In the end these are only semantics and I do not have a better alternative, so "readCachedTemperature" it will be. |
I do not agree it is only semantics, a good function name is self descriptive. But I cannot think of one. |
definitely
please wait for the next commit as I still needed to add the necessary modifications (rename, comments) |
Making the 2 new links work took me 3 tries as they cannot be tested without committing if you do not use the Github online editor. Github uses different rules for the project internal references in README and issue comments. The shortcuts only work in issue comments. |
I will review it and merge it if it looks good. |
@RobTillaart: Thanks for accepting this feature! 👍 Just updated the comment above with the test description to show the same method name as the merged source "readCachedTemperature" to avoid confusion. |
Good additions are always welcome! |
Missed this: readTemperatureForHumidity() needs to be renamed to readCachedTemperature() in keywords.txt. |
And in the changelog too. |
So many dependencies that the compiler does not check ... I just pushed the 2 changes to my feature branch. Should I open a new merge request? |
Ok, no need to update version |
pull request is ready, also fixed another typo in keywords.txt, see #29 |
No description provided.