Manages the 1-wire bus
Dependents: oldheating heating
http/http-1wire-class.inc@1:c272b1fcc834, 2019-04-26 (annotated)
- Committer:
- andrewboyson
- Date:
- Fri Apr 26 14:29:44 2019 +0000
- Revision:
- 1:c272b1fcc834
Moved pin set up to a local 1-wire-bus-pin.h file
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 | "}" |