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

tests/driver_sht2x: avoid negative number after decimal dot #12164

Merged
merged 1 commit into from
Sep 4, 2019

Conversation

keestux
Copy link
Contributor

@keestux keestux commented Sep 3, 2019

This is a similar fix as in #12162 and #12140.

@keestux keestux requested a review from aabadie September 3, 2019 18:56
@keestux
Copy link
Contributor Author

keestux commented Sep 3, 2019

Notice that sht3x has a similar problem too. But that one has a bug as well, I think.

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same logic as in the other two PRs applies.

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Sep 3, 2019
@keestux
Copy link
Contributor Author

keestux commented Sep 3, 2019

In the sht3x test there is this:

        int16_t temp;
        int16_t hum;

        if ((res = sht3x_read(&dev, &temp, &hum)) == SHT3X_OK) {
            printf("Temperature [°C]: %d.%d\n"
                   "Relative Humidity [%%]: %d.%d\n"
                   "+-------------------------------------+\n",
                   temp / 100, temp % 100,
                   hum / 100, hum % 100);
        }

Not only does it need an abs() for the numbers after decimal dot, it has %d for a 2 digit number. This means that a temperature of 10.05 degrees will be printed as 10.5. Same for the humidity. I don't have the device so I can't really test.

@benpicco
Copy link
Contributor

benpicco commented Sep 3, 2019

I don't have the device so I can't really test.

I mean the format string is device independent, no?
If we assume the documentation is right, temp will be

Temperature in hundredths of a degree Celsius

so we can set int16_t temp = -1005; and test the behavior of printf() locally.

@aabadie
Copy link
Contributor

aabadie commented Sep 3, 2019

There's indeed a problem, the formatter for temperature should be %d.%02d (also tested this locally).

@aabadie
Copy link
Contributor

aabadie commented Sep 3, 2019

There's indeed a problem, the formatter for temperature should be %d.%02d (also tested this locally).

well, in fact it's not needed since the number after decimal dot is divided by 10. But this division could be removed if you use %d.%02d. This should be better.
I checked and bmx280 driver application has the same behaviour.

@benpicco benpicco added the Area: tests Area: tests and testing framework label Sep 3, 2019
@aabadie aabadie merged commit aa6f9e5 into RIOT-OS:master Sep 4, 2019
@keestux keestux deleted the driver_sht2x_cleanup branch September 8, 2019 15:32
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants