-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
fix for ds18b20 negative decimals #2322
Conversation
ds18b20 decimals do not take into account the sign bit. Since the original calculation was not so readable, rewritten in readable way that also fixes the bug. Same code as PR against master.
@fetchbot you're the original author of this module, could you please verify this fix? |
I've just taken a look at this code and some of the logic here is plain bizarre. I am talking about the original module, though @peturdainn's mods don't help.
So taking an example what should a reading of - 1.4°C return on integer builds?
|
I don't see how 1, -400 is a good representation for -1.4 The patch makes it return -1, -400 so you can do something like before the patch it would return -1, 600 |
@peturdainn Petur if you are going to start fixing things then why no do this properly? For example:
lua_pushnumber(L, ((lua_Number)ds18b20_raw_temp) / 16);
#ifdef LUA_NUMBER_INTEGRAL
lua_pushinteger(L, ((ds18b20_raw_temp&0xf)*1000)/16 - (ds18b20_raw_temp>0 ? 0: 1000));
#else
lua_pushinteger(L, 0);
#endif though why the OP needed the And either way can you update the |
I am not familiar with the nodemcu codebase (or much of lua), I just happened to stumble over this bug and offered something that fixed just that. I don't have the time right now to go fix the other problems in this module (just because I offered this fix). |
That's life, I guess, but what your PR is doing is to fix only a part of the problem, the other parts being the lack of complete integer vs. float support and the confusion in the documentation. Is it worth a PR so solve 33% of the related issues. My feeling is -½, but I will defer to the other committers. @pjsg what are your thoughts, since you are tracking this? |
The doc will need edit anyway, without the fix the user should be warned that negative temps are wrong and particularly bad around 0 when trying to calibrate sensors with ice water, temps between 0 and -1 are reported positive. I understand you want the code perfect, but it pushes away incremental patch contributors. I'm a big fan of Pieter Hintjens in that regard. |
My answer is clear; I'm quite pragmatic. Any PR that solves a problem, or even a fraction thereof, is worth merging if a) it is in line with our guidelines 83% complete is better than 82%, isn't it? I see no reason why we would want to miss out on that 1%. Any developer who devotes time and energy to get from 82 to 83 does a lot more for our project than all the others who couldn't be bothered. |
Thanks Marcel, you're actually motivating me to work on this in a later time-frame |
As I said I will defer to the other committers, but once committed I will then raise a new issue to cover the other outstanding items so that they are logged and not forgotten. |
I can't deny this being part of the motivation behind my comment 😜 You're welcome around here anytime. |
@pjsg / @devsaurus you've also been involved in the discussions on the issue. Would you be willing to approve this? |
@marcelstoer the fix does fix the bug. I can confirm this. The issue isn't of approval, but of policy: should we accept PR which makes a module less flawed rather then fixes all know related issues? I suggest that we decouple the policy discussion from this point issue. |
Fixes ds18b20 negative decimals bug by changing the way temp and temp_dec are calculated, taking care not to lose the sign of the decimals part
Fixes #2313
dev
branch rather than formaster
.ds18b20 decimals do not take into account the sign bit. Since the original calculation was not so readable, rewritten in readable way that also fixes the bug. Same code as PR against master.