@Gordon
There are a few things going on in this thread!
I'm still a bit confused here - does the existing DS18B20 library not work with ESP8266? My understanding was just that the current one was fine, but it just returned the previous reading (which means the first one returns 85 or something like that).
a. Yes - the code works on the ESP8266
b. Add support ds18s20 as well as ds18s20
@hygyI modifed this code originally, cause the original is does not work with ds18s20 just with 18b20.
c. Callback
@gordon The code above waits 1 second for the callback - seems pretty extreme? I doubt many people would be happy with that.
d. One of the issues with the original code is that the initial reading is bogus. The device returns all 111111's, and this turns out to be a value of 85c. For the next call, the real value is in place as the conversion is done. There is no way of knowing if this is a 'real' 85c or the bogus first value
One solution would be to return undefined until the first conversion is done.
Another, the constructor could be modified to starts a conversion, so that by the time the first call is made to getTemp, however this could not be guaranteed.
e. The original code has function getTemp(verify) - Gets the temperature reading.
the proposed code has function(callback,verify)
So existing code that use getTemp with verify used would fails as the first param is now a callback.
I have not idea how widespread this usage is, however I believe the getTemp should work for older code without having to change params.
f. versioning
The git hash is a good idea, although the .js and .min.js would have different hash, even though they are a 'pair'. If the .js source had a hash comment, at least local projects and SD card modules would have the version details in them.
The idea of the x.y notation like used in node is that if a function signature changes (like e above), the major number x would be incremented to indicate. However without package.json this would not be of much benefit ;-(
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
@Gordon
There are a few things going on in this thread!
a. Yes - the code works on the ESP8266
b. Add support ds18s20 as well as ds18s20
c. Callback
The time it takes for a conversion depends on the resolution and if parasitic mode mode is in use.
http://forum.espruino.com/comments/12612450/
The modified code #21 http://forum.espruino.com/comments/12729356/ takes the resolution into account so, the callback is no longer 1 sec, but depends on the resolution
d. One of the issues with the original code is that the initial reading is bogus. The device returns all 111111's, and this turns out to be a value of 85c. For the next call, the real value is in place as the conversion is done. There is no way of knowing if this is a 'real' 85c or the bogus first value
One solution would be to return
undefined
until the first conversion is done.Another, the constructor could be modified to starts a conversion, so that by the time the first call is made to getTemp, however this could not be guaranteed.
e. The original code has
function getTemp(verify)
- Gets the temperature reading.the proposed code has
function(callback,verify)
So existing code that use getTemp with verify used would fails as the first param is now a callback.
I have not idea how widespread this usage is, however I believe the getTemp should work for older code without having to change params.
f. versioning
The git hash is a good idea, although the .js and .min.js would have different hash, even though they are a 'pair'. If the .js source had a hash comment, at least local projects and SD card modules would have the version details in them.
The idea of the x.y notation like used in node is that if a function signature changes (like e above), the major number x would be incremented to indicate. However without package.json this would not be of much benefit ;-(