Manages the 1-wire bus
Dependents: oldheating heating
Diff: http/http-1wire-class.inc
- Revision:
- 1:c272b1fcc834
diff -r b4b170ce93a4 -r c272b1fcc834 http/http-1wire-class.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/http/http-1wire-class.inc Fri Apr 26 14:29:44 2019 +0000 @@ -0,0 +1,32 @@ +"//OneWire script\n" +"'use strict';\n" +"\n" +"class OneWire\n" +"{\n" +" static DS18B20ToString(text)\n" +" {\n" +" switch (text)\n" +" {\n" +" case '7FFF': return 'CRC error' ;\n" +" case '7FFE': return 'ROM not found' ;\n" +" case '7FFD': return 'Timed out' ;\n" +" case '7FFC': return 'No device detected after reset';\n" +" case '7FFB': return 'Device removed during search' ;\n" +" }\n" +" let isNegative = false;\n" +" switch(text.charAt(0))\n" +" {\n" +" case '8': text = '7' + text.substr(1, 3); isNegative = true; break;\n" +" case '9': text = '6' + text.substr(1, 3); isNegative = true; break;\n" +" case 'A': text = '5' + text.substr(1, 3); isNegative = true; break;\n" +" case 'B': text = '4' + text.substr(1, 3); isNegative = true; break;\n" +" case 'C': text = '3' + text.substr(1, 3); isNegative = true; break;\n" +" case 'D': text = '2' + text.substr(1, 3); isNegative = true; break;\n" +" case 'E': text = '1' + text.substr(1, 3); isNegative = true; break;\n" +" case 'F': text = '0' + text.substr(1, 3); isNegative = true; break;\n" +" }\n" +" let value = parseInt(text, 16) / 16.0;\n" +" if (isNegative) value = -value;\n" +" return value.toFixed(1);\n" +" }\n" +"}" \ No newline at end of file