Manages the 1-wire bus
Dependents: oldheating heating
web/web-1wire-class.inc@2:79cad6a51fd0, 2019-04-27 (annotated)
- Committer:
- andrewboyson
- Date:
- Sat Apr 27 09:26:15 2019 +0000
- Revision:
- 2:79cad6a51fd0
- Parent:
- http/http-1wire-class.inc@1:c272b1fcc834
- Child:
- 8:ceafef18cbf7
Updated web library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 1:c272b1fcc834 | 1 | "//OneWire script\n" |
andrewboyson | 1:c272b1fcc834 | 2 | "'use strict';\n" |
andrewboyson | 1:c272b1fcc834 | 3 | "\n" |
andrewboyson | 1:c272b1fcc834 | 4 | "class OneWire\n" |
andrewboyson | 1:c272b1fcc834 | 5 | "{\n" |
andrewboyson | 1:c272b1fcc834 | 6 | " static DS18B20ToString(text)\n" |
andrewboyson | 1:c272b1fcc834 | 7 | " {\n" |
andrewboyson | 1:c272b1fcc834 | 8 | " switch (text)\n" |
andrewboyson | 1:c272b1fcc834 | 9 | " {\n" |
andrewboyson | 1:c272b1fcc834 | 10 | " case '7FFF': return 'CRC error' ;\n" |
andrewboyson | 1:c272b1fcc834 | 11 | " case '7FFE': return 'ROM not found' ;\n" |
andrewboyson | 1:c272b1fcc834 | 12 | " case '7FFD': return 'Timed out' ;\n" |
andrewboyson | 1:c272b1fcc834 | 13 | " case '7FFC': return 'No device detected after reset';\n" |
andrewboyson | 1:c272b1fcc834 | 14 | " case '7FFB': return 'Device removed during search' ;\n" |
andrewboyson | 1:c272b1fcc834 | 15 | " }\n" |
andrewboyson | 1:c272b1fcc834 | 16 | " let isNegative = false;\n" |
andrewboyson | 1:c272b1fcc834 | 17 | " switch(text.charAt(0))\n" |
andrewboyson | 1:c272b1fcc834 | 18 | " {\n" |
andrewboyson | 1:c272b1fcc834 | 19 | " case '8': text = '7' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 20 | " case '9': text = '6' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 21 | " case 'A': text = '5' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 22 | " case 'B': text = '4' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 23 | " case 'C': text = '3' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 24 | " case 'D': text = '2' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 25 | " case 'E': text = '1' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 26 | " case 'F': text = '0' + text.substr(1, 3); isNegative = true; break;\n" |
andrewboyson | 1:c272b1fcc834 | 27 | " }\n" |
andrewboyson | 1:c272b1fcc834 | 28 | " let value = parseInt(text, 16) / 16.0;\n" |
andrewboyson | 1:c272b1fcc834 | 29 | " if (isNegative) value = -value;\n" |
andrewboyson | 1:c272b1fcc834 | 30 | " return value.toFixed(1);\n" |
andrewboyson | 1:c272b1fcc834 | 31 | " }\n" |
andrewboyson | 1:c272b1fcc834 | 32 | "}" |