Manages the 1-wire bus
Dependents: oldheating heating
web/web-1wire-class.js@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.js@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 |
andrewboyson | 1:c272b1fcc834 | 2 | 'use strict'; |
andrewboyson | 1:c272b1fcc834 | 3 | |
andrewboyson | 1:c272b1fcc834 | 4 | class OneWire |
andrewboyson | 1:c272b1fcc834 | 5 | { |
andrewboyson | 1:c272b1fcc834 | 6 | static DS18B20ToString(text) |
andrewboyson | 1:c272b1fcc834 | 7 | { |
andrewboyson | 1:c272b1fcc834 | 8 | switch (text) |
andrewboyson | 1:c272b1fcc834 | 9 | { |
andrewboyson | 1:c272b1fcc834 | 10 | case '7FFF': return 'CRC error' ; |
andrewboyson | 1:c272b1fcc834 | 11 | case '7FFE': return 'ROM not found' ; |
andrewboyson | 1:c272b1fcc834 | 12 | case '7FFD': return 'Timed out' ; |
andrewboyson | 1:c272b1fcc834 | 13 | case '7FFC': return 'No device detected after reset'; |
andrewboyson | 1:c272b1fcc834 | 14 | case '7FFB': return 'Device removed during search' ; |
andrewboyson | 1:c272b1fcc834 | 15 | } |
andrewboyson | 1:c272b1fcc834 | 16 | let isNegative = false; |
andrewboyson | 1:c272b1fcc834 | 17 | switch(text.charAt(0)) |
andrewboyson | 1:c272b1fcc834 | 18 | { |
andrewboyson | 1:c272b1fcc834 | 19 | case '8': text = '7' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 20 | case '9': text = '6' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 21 | case 'A': text = '5' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 22 | case 'B': text = '4' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 23 | case 'C': text = '3' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 24 | case 'D': text = '2' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 25 | case 'E': text = '1' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 26 | case 'F': text = '0' + text.substr(1, 3); isNegative = true; break; |
andrewboyson | 1:c272b1fcc834 | 27 | } |
andrewboyson | 1:c272b1fcc834 | 28 | let value = parseInt(text, 16) / 16.0; |
andrewboyson | 1:c272b1fcc834 | 29 | if (isNegative) value = -value; |
andrewboyson | 1:c272b1fcc834 | 30 | return value.toFixed(1); |
andrewboyson | 1:c272b1fcc834 | 31 | } |
andrewboyson | 1:c272b1fcc834 | 32 | } |