Library for the DS1620 Digital Thermometer

Files at this revision

API Documentation at this revision

Comitter:
dzoni
Date:
Sat Dec 12 19:29:43 2015 +0000
Parent:
1:f6fbf299550b
Commit message:
1. Warnings resolved: implicit type conversion float to double and back to float; ; 2. Optimization: wait for write operation completion changed from wait(float) to wait_ms(int)

Changed in this revision

DS1620.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f6fbf299550b -r 35526d3a8a04 DS1620.cpp
--- a/DS1620.cpp	Sun Mar 08 00:38:29 2015 +0000
+++ b/DS1620.cpp	Sat Dec 12 19:29:43 2015 +0000
@@ -17,6 +17,8 @@
 #include "mbed.h"
 #include "DS1620.h"
 
+#define WRITE_COMPLETE_TIME_MS   (100)        // time for write to complete (100 msec) 
+
 // Constructor
 DS1620::DS1620(PinName dq, PinName clk, PinName rst) : _dq(dq), _clk(clk), _rst(rst)
 {
@@ -37,25 +39,25 @@
 {
     float temp = 0.0;
     unsigned short rawTemp = readTemperatureRaw();
-    temp = rawTemp / 2.0;
+    temp = rawTemp / 2.0f;
     if (rawTemp >= 0x100) {
-        temp -= 256.0;
+        temp -= 256.0f;
     }
     return temp;
 }
 
 float DS1620::getHighResolutionTemperature()
 {
-    float temp = 0.0;
+    float temp = 0.0f;
     unsigned short rawTemp, counter, slope = 0;
     rawTemp = readTemperatureRaw();
     counter = readCounter();
     loadSlope();
     slope = readCounter();
     
-    temp = (rawTemp >> 1) - 0.25;
+    temp = (rawTemp >> 1) - 0.25f;
     if (rawTemp >= 0x100) {
-        temp -= 256.0;
+        temp -= 256.0f;
     }
     temp += ((float)slope - (float)counter) / (float)slope;   
     return temp;
@@ -92,7 +94,7 @@
     shiftOut(WRITE_CONFIG);
     shiftOut(config);
     _rst = 0;
-    wait(0.1);  // Wait for write to complete
+    wait_ms(WRITE_COMPLETE_TIME_MS);  // wait for write to complete
 }
     
 unsigned short DS1620::readTLRaw()
@@ -120,7 +122,7 @@
     shiftOut(tempLSB);
     shiftOut(tempMSB);
     _rst = 0;
-    wait(0.1);
+    wait_ms(WRITE_COMPLETE_TIME_MS);  // wait for write to complete
 }   
     
         
@@ -149,7 +151,7 @@
     shiftOut(tempLSB);
     shiftOut(tempMSB);
     _rst = 0;
-    wait(0.1);
+    wait_ms(WRITE_COMPLETE_TIME_MS);  // wait for write to complete
 }
         
 unsigned short DS1620::readCounter()