Dallas' DS1820 family temperature sensor. For more details see [https://developer.mbed.org/users/hudakz/code/DS1820/wiki/Homepage]

Dependencies:   OneWire

Fork of DS1820 by Zoltan Hudak

Revision:
8:8dfdd1603e4d
Parent:
6:518950e436be
Child:
11:9be3e73c01f1
--- a/DS1820.cpp	Thu Mar 26 20:57:59 2015 +0000
+++ b/DS1820.cpp	Fri Mar 27 12:34:16 2015 +0000
@@ -46,8 +46,8 @@
  */
 DS1820::DS1820(PinName pin) :
     oneWire(pin) {
-    present = 0;
-    type_s = 0;
+    present = false;
+    model_s = false;
 }
 
 /**
@@ -60,15 +60,15 @@
 DS1820::DS1820(char model, PinName pin) :
     oneWire(pin) {
     if((model == 'S') or (model == 's')) {
-        present = 1;
-        type_s = 1;
+        present = true;
+        model_s = true;
     }
     else if((model == 'B') or (model == 'b')) {
-        present = 1;
-        type_s = 0;
+        present = true;
+        model_s = false;
     }
     else
-        present = 0;
+        present = false;
 }
 
 /**
@@ -99,33 +99,33 @@
 #endif
 
     if(OneWire::crc8(addr, 7) == addr[7]) {
-        present = 1;
+        present = true;
 
         // the first ROM byte indicates which chip
         switch(addr[0]) {
         case 0x10:
-            type_s = 1;
+            model_s = true;
 #if DEBUG
             serial.printf("DS18S20 or old DS1820\r\n");
 #endif            
             break;
 
         case 0x28:
-            type_s = 0;
+            model_s = false;
 #if DEBUG
             serial.printf("DS18B20\r\n");
 #endif            
             break;
 
         case 0x22:
-            type_s = 0;
+            model_s = false;
 #if DEBUG
             serial.printf("DS1822\r\n");
 #endif            
             break;
 
         default:
-            present = 0;
+            present = false;
 #if DEBUG
             serial.printf("Device doesn't belong to the DS1820 family\r\n");
 #endif            
@@ -142,6 +142,19 @@
 }
 
 /**
+ * @brief   Informs about presence of a DS1820 sensor.
+ * @note    begin() shall be called before using this function
+ *          if a generic DS1820 instance was created by the user. 
+ *          No need to call begin() for a specific DS1820 instance.
+ * @param
+ * @retval  true:   when a DS1820 sensor is present
+ *          false:  otherwise
+ */
+bool DS1820::isPresent(void) {
+    return present;
+}
+
+/**
  * @brief   Sets temperature-to-digital conversion resolution.
  * @note    The configuration register allows the user to set the resolution
  *          of the temperature-to-digital conversion to 9, 10, 11, or 12 bits.
@@ -156,7 +169,7 @@
         res = 12;
     if(res < 9)
         res = 9;      
-    if(type_s)
+    if(model_s)
         res = 9;
        
     oneWire.reset();
@@ -173,7 +186,6 @@
         oneWire.write(data[i]);
 }
 
-
 /**
  * @brief   Starts temperature conversion
  * @note    The time to complete the converion depends on the selected resolution:
@@ -213,7 +225,7 @@
         serial.printf("raw = %#x\r\n", *p_word);
 #endif            
 
-        if(type_s) {
+        if(model_s) {
             *p_word = *p_word << 3;         // 9-bit resolution
             if(data[7] == 0x10) {
 
@@ -264,3 +276,4 @@
         return (float(word) / 256.0f);
 }
 
+