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

Changing Datatypes of _pulse and _totalpulse to avoid overflow #3

Merged
merged 2 commits into from
Jan 18, 2023

Conversation

hjmhardsoft
Copy link
Contributor

Hi Hafidhh
During the tests of the library measuring running water in a residence, it was found that the variable _totalpulse periodically took negative values due an overflow.
I have made a change in the data types of the variables _pulse and _totalpulse, which were defined as "int" to type "unsigned long" to avoid overflow when reaching 32767. Now it is possible to measure up to 9.5 million liters (2^ 32-1=4E9, that is, 4294967295, which I divide by 450 pulses per liter, allows us to measure 4294967295/450=9.5444 million liters of water).

I first made 3 commits on outdated fork, then cancell it, and re-sync my fork to library v1.1.0 and then submit commits again and ask for this Pull.

Regards

Hugo

		During the tests of the library measuring running water in a residence, it was found that the variable _totalpulse periodically took negative values due an overflow.
I have made a change in the data types of the variables _pulse and _totalpulse, which were defined as "int" to type "unsigned long" to avoid overflow when reaching 32767. Now it is possible to measure up to 9.5 million liters (2^ 32-1=4E9, that is, 4294967295, which I divide by 450 pulses per liter, allows us to measure 4294967295/450=9.5444 million liters of water).
		During the tests of the library measuring running water in a residence, it was found that the variable _totalpulse periodically took negative values due an overflow.
I have made a change in the data types of the variables _pulse and _totalpulse, which were defined as "int" to type "unsigned long" to avoid overflow when reaching 32767. Now it is possible to measure up to 9.5 million liters (2^ 32-1=4E9, that is, 4294967295, which I divide by 450 pulses per liter, allows us to measure 4294967295/450=9.5444 million liters of water).
@hafidhh hafidhh merged commit 58e641c into hafidhh:master Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants