Manages the 1-wire bus

Dependents:   oldheating heating

Committer:
andrewboyson
Date:
Wed Jun 10 10:02:55 2020 +0000
Revision:
8:ceafef18cbf7
Parent:
2:79cad6a51fd0
Child:
9:6f663ad53c7e
Changed the javascript onewire class routine DS18B20ToString(text) which returned a string to parseDS18B20(text) which returns a value. This allows for calculations rather than just display: for example the boiler temperature rise when heating.

Who changed what in which revision?

UserRevisionLine numberNew 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 8:ceafef18cbf7 6 " static parseDS18B20(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 8:ceafef18cbf7 30 " return value;\n"
andrewboyson 1:c272b1fcc834 31 " }\n"
andrewboyson 1:c272b1fcc834 32 "}"