Comments (4)
Nice work @linguini1 !!!
Suggestion: run the checkpatch to catch the coding style issues:
$ ./tools/checkpatch.sh -f drivers/sensors/sht4x.c
You can find about our Coding style here: https://nuttx.apache.org/docs/latest/contributing/coding_style.html
If you decide to create a blog post talking about your first experience creating a driver for NuttX, please share it on our Reddit: https://www.reddit.com/r/nuttx/
from nuttx.
Oh yes, I'm sure my work so far violates all the style rules. Saving my formatting until the end. I will be sure to make a post!
from nuttx.
Hi @linguini1!
First of all: the code looks beautiful, understandable and nicely commented, thanks for this.
Also thank you for your motivation and welcome to the NuttX community!
I know that your fork is work-in-progress, but I tried to figure out what is wrong to help you.
During this "review" I have noticed a few things that you are probably not aware of...
These are just suggestions, but they may improve the usability of this driver. :)
1.) Temperature range:
The sensor is capable of measuring temperatures between -40 C and +125 C with a resolution of 0.01 C and an accuracy of 0.1 C (SHT45).
Your choice to store the results in an int16_t represented as mC or mF limits the theoretical measurement range to: -32.768 C ... +32.767 C in Celsius mode and to -35.98 C ... 0.43 C in Fahrenheit mode. This means that in Fahrenheit mode this driver will barely be able to measure any temperature above the freezing point of water (which is fairly suboptimal for many users).
2.) sht4x_calc_temp():
There are massive integer overflows/underflows for huge ranges of valid input values (input values: raw measurement data points). This is related to 1.), see above.
3.) Humidity range:
The sensor is capable of measuring relative humidity between 0 and 100 with a resolution of 0.01 %RH and an accuracy of 1 %RH (SHT45).
You store the result of the measurement with a resolution of 1% RH, therefore you lose two digits precision.
Hint: The accuracy of the sensor is 1%, so losing two digits from the resolution is not necessarily a problem, it depends on the use case.
4.) sht4x_calc_hum():
hum is an unsigned integer (uint16_t), therefore it can never be < 0. Those values, that are supposed to be < 0 will be mapped to 100 instead of 0 because of an integer overflow/underflow. So your clamped output will look like [ ..., 100, 100, 100, 0, 0, 1, 1, ..., 99, 99, 100, 100, 100, 100 ...] instead of [ ..., 0, 0, 0, 0, 1, 1, ..., 99, 99, 100, 100, 100, 100 ...] (note the wrongly mapped values below zero).
5.) sht4x_ioctl():
The ioctl command SNIOC_READ_CONVERT_DATA converts both temperature and humidity using sht4x_calc_temp(), whereby sht4x_read() is using sht4x_calc_temp() and sht4x_calc_hum() respectively. Not sure if this is intended, probably not.
6.) sht4x_register():
This may (or may not) answer your original question, I didn't verify, just looked at your code briefly. You declare the function in include/nuttx/sensors/sht4x.h, but you do not define it anywhere, or at least I haven't found it in the fork you've linked. There is a function named sht21_register() though (defined in drivers/sensors/sht4x.c), I guess it's a typo or copy-paste error.
If this was the problem, feel free to close this issue.
As this is an issue and not a pull request, sooner or later my comment and your code will drift apart. I did not want to comment on the commits inside your fork, so: the last commit on your fork (branch: sht41-sensor) was linguini1@5a367df when this comment was written).
Greetings,
David
p.s.: The second question (dynamically loading drivers) is not answered by this post, so feel free to comment, thank you!
from nuttx.
Thank you for the kind words and great suggestions @davidgnx!
1), 2), 3) You're correct, I didn't consider the integer precisions. I was porting this from another system where I had previously used floats, but wanted integers to be easier for less powerful hardware. Lots of good considerations that I will take into account, thank you!
-
You're very correct, that was not intended. Thanks for the catch!
-
It seems I did forget to rename the register function... never develop late at night I guess!
I will keep this issue open just a little longer to see if there is any information about dynamically registering drivers, if that's alright. Thanks for your help!
from nuttx.
Related Issues (20)
- bug report, armv7-a, arm_addrenv.c, function <up_addrenv_destroy> HOT 1
- What code editor to use with nuttx? HOT 8
- getpid() not working HOT 23
- riscv vfork failed in PROTECTED build
- STM32 Serial driver status HOT 7
- Add "Testimonials" to nuttx.apache.org
- Add "Articles and Thesis" about NuttX to nuttx.apache.org HOT 2
- Add BLE support for esp32s3 HOT 5
- STM32H745I-DISCO Userleds Error HOT 11
- unwind_frame has issues on arm cortext M7 HOT 15
- risc-v/bl808: MMU causes CPU slowdown HOT 18
- esp32s3-devkit:nsh can't boot HOT 2
- esp32s3 boards with ESP32-S3-WROOM-1U can't boot into nsh? HOT 3
- ESP32S3 usbnsh hang on ps command HOT 6
- risc-v/sg2000: Kernel fails to boot with GCC `-O2`
- armv7-m/arm_mpu.c: MPU regions >= 2GB cannot be configured HOT 7
- arm_cache.c: up_disable_dcache() has undefined behavior in write-back mode HOT 1
- Create an Issue template to automatically assigned the label tags when someone open an Issue HOT 2
- OpenAMP CMake configuration error HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuttx.