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

Below zero values don't make sense #5

Closed
rjcorwin opened this issue Jul 18, 2014 · 3 comments
Closed

Below zero values don't make sense #5

rjcorwin opened this issue Jul 18, 2014 · 3 comments

Comments

@rjcorwin
Copy link

When below zero is reached, the temperature jumps to -127 with the current conversion.

@TimPietrusky Your code uses the same conversion.

Any idea on how to fix this? Reading the raw values I'm not sure what the trick is.

@jwyse
Copy link
Contributor

jwyse commented Jan 16, 2016

Here's how I fixed it. I arrived at this after decompiling the Windows app that shipped with the device, hacking at it until I got it to work, and then trying to optimize and simplify it. Note that the manufacturer's Windows app even has a bug -- it returns an error when reading temps just under zero (between 0.0C and -1.0C, if I remember correctly -- whenever the high bit == 255). This is fixed in the following code:

exports.toDegreeCelcius = function(hiByte, loByte) {
if ((hiByte & 128) == 128) {
return -((256-hiByte) + (1 + ~(loByte >> 4)) / 16.0);
}
return hiByte + ((loByte >> 4) / 16.0);
}

I've tested with the full range of possible high+low bytes (0-255), and the results appear to be correct. There's probably a more concise way of representing this, but I haven't had much experience with bitwise operations like this before.

@asmuelle
Copy link
Owner

Thanks, will incorporate your fix as soon as possible!

@jwyse
Copy link
Contributor

jwyse commented Jan 17, 2016

I have submitted a pull request that contains this fix, as well as toDegreeFahrenheit() and a handful of other minor changes.

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

No branches or pull requests

3 participants