DS1820 support (forked repo)

Dependents:   HaTemp

Fork of DS1820 by HM Yoong

Revision:
1:980691eb0534
Parent:
0:245af9360f0d
--- a/DS1820.cpp	Tue Feb 28 07:42:07 2012 +0000
+++ b/DS1820.cpp	Thu Mar 17 12:22:16 2016 +0000
@@ -1,5 +1,5 @@
+#include "mbed.h"
 #include "DS1820.h"
-#include "mbed.h"
 
 // Global variables shared between all DS1820 objects
 bool DS1820_done_flag;
@@ -196,54 +196,54 @@
 }
 
 bool DS1820::ROM_checksum_error() {
-    char CRC=0x00;
+    char crc=0x00;
     int i;
     for(i=0;i<7;i++) // Only going to shift the lower 7 bytes
-        CRC = CRC_byte(CRC, ROM[i]);
+        crc = CRC_byte(crc, ROM[i]);
     // After 7 bytes CRC should equal the 8th byte (ROM CRC)
-    return (CRC!=ROM[7]); // will return true if there is a CRC checksum error         
+    return (crc!=ROM[7]); // will return true if there is a CRC checksum error         
 }
 
 bool DS1820::RAM_checksum_error() {
-    char CRC=0x00;
+    char crc=0x00;
     int i;
     read_RAM();
     for(i=0;i<8;i++) // Only going to shift the lower 8 bytes
-        CRC = CRC_byte(CRC, RAM[i]);
+        crc = CRC_byte(crc, RAM[i]);
     // After 8 bytes CRC should equal the 9th byte (RAM CRC)
-    return (CRC!=RAM[8]); // will return true if there is a CRC checksum error         
+    return (crc!=RAM[8]); // will return true if there is a CRC checksum error         
 }
 
-char DS1820::CRC_byte (char CRC, char byte ) {
+char DS1820::CRC_byte(char aCRC, char byte ) {
     int j;
     for(j=0;j<8;j++) {
-        if ((byte & 0x01 ) ^ (CRC & 0x01)) {
+        if ((byte & 0x01 ) ^ (aCRC & 0x01)) {
             // DATA ^ LSB CRC = 1
-            CRC = CRC>>1;
+            aCRC = aCRC>>1;
             // Set the MSB to 1
-            CRC = CRC | 0x80;
+            aCRC = aCRC | 0x80;
             // Check bit 3
-            if (CRC & 0x04) {
-                CRC = CRC & 0xFB; // Bit 3 is set, so clear it
+            if (aCRC & 0x04) {
+                aCRC = aCRC & 0xFB; // Bit 3 is set, so clear it
             } else {
-                CRC = CRC | 0x04; // Bit 3 is clear, so set it
+                aCRC = aCRC | 0x04; // Bit 3 is clear, so set it
             }
             // Check bit 4
-            if (CRC & 0x08) {
-                CRC = CRC & 0xF7; // Bit 4 is set, so clear it
+            if (aCRC & 0x08) {
+                aCRC = aCRC & 0xF7; // Bit 4 is set, so clear it
             } else {
-                CRC = CRC | 0x08; // Bit 4 is clear, so set it
+                aCRC = aCRC | 0x08; // Bit 4 is clear, so set it
             }
         } else {
             // DATA ^ LSB CRC = 0
-            CRC = CRC>>1;
+            aCRC = aCRC>>1;
             // clear MSB
-            CRC = CRC & 0x7F;
+            aCRC = aCRC & 0x7F;
             // No need to check bits, with DATA ^ LSB CRC = 0, they will remain unchanged
         }
         byte = byte>>1;
     }
-return CRC;
+    return aCRC;
 }
 
 void DS1820::convert_temperature(devices device) {
@@ -320,7 +320,7 @@
     return answer;
 }    
 
-float DS1820::temperature(char scale) {
+float DS1820::temperature() {
 // The data specs state that count_per_degree should be 0x10 (16), I found my devices
 // to have a count_per_degree of 0x4B (75). With the standard resolution of 1/2 deg C
 // this allowed an expanded resolution of 1/150th of a deg C. I wouldn't rely on this
@@ -337,11 +337,7 @@
     count_per_degree = RAM[7];
     answer = reading +0.0;
     answer = answer - 0.25 + (count_per_degree - remaining_count) / count_per_degree;
-    if (scale=='C' or scale=='c')
-        answer = answer / 2.0;
-    else
-        // Convert to deg F
-        answer = answer * 9.0 / 10.0 + 32.0;
+    answer = answer / 2.0;
     return answer;
 }