Simple DS1621 temperature acquisition.

Dependents:   S3_DS1621

Files at this revision

API Documentation at this revision

Comitter:
dupuyb
Date:
Mon Mar 21 16:51:22 2011 +0000
Parent:
2:3160631567f2
Commit message:

Changed in this revision

ds1621.cpp Show annotated file Show diff for this revision Revisions of this file
ds1621.h Show annotated file Show diff for this revision Revisions of this file
diff -r 3160631567f2 -r d6310fd6df8e ds1621.cpp
--- a/ds1621.cpp	Mon Mar 07 08:12:27 2011 +0000
+++ b/ds1621.cpp	Mon Mar 21 16:51:22 2011 +0000
@@ -5,22 +5,18 @@
 ************************************************************/
 #include "ds1621.h"
 
-DS1621::DS1621(I2C* interface, uint8_t address, Serial* pc) {
+DS1621::DS1621(I2C* interface, uint8_t address) {
     i2c = interface;
-    dbx = pc;
-    if (dbx) dbx->printf("Constructor DS1621\n\r");
 }
 
-float DS1621::getTemp(uint8_t address) { // Return degrees C (-55 to +125)
-    if (dbx) dbx->printf("DS1621::getTemp DS1621 address=0x%X\n\r",address);
+float DS1621::read(uint8_t address) { // Return degrees C (-55 to +125)
+    if (dbx) printf("DS1621::read DS1621 address=0x%X\n\r",address);
     float temperature = 0.0;
     uint16_t temp16;
     char temp8[2];
     int8_t data;
     if (i2c) {
         address &= 0x0E;
-        data = 0xEE; // Start Convert T [EEh]
-        i2c->write(DS1621_Write|address,(char *)&data,sizeof(data));
         data = 0xAA; // Read Temperature [AAh]
         i2c->write(DS1621_Write|address,(char *)&data,sizeof(data));
         i2c->read(DS1621_Read|address, temp8 ,sizeof(temp8), false);
@@ -35,9 +31,17 @@
             temperature = ((float) temp16 / 2);
             temperature = -1.0 * temperature;
         }
-        if (dbx)  dbx->printf("DS1621::getTemp temp8[0]=0x%X, temp8[1]=0x%X, temp16=0x%X\n\r",temp8[0],temp8[1],temp16);
+        if (dbx) printf("DS1621::read temp8[0]=0x%X, temp8[1]=0x%X, temp16=0x%X\n\r",temp8[0],temp8[1],temp16);
     } else {
-       if (dbx)  dbx->printf("DS1621::getTemp interface I2C is not initialized\n\r");
+        if (dbx) printf("DS1621::read interface I2C is not initialized\n\r");
     }
     return temperature;
+}
+
+void DS1621::init(uint8_t address) {
+    if (dbx) printf("DS1621::init DS1621 address=0x%X\n\r",address);
+    address &= 0x0E;
+    char data;
+    data = 0xEE; // Start Convert T [EEh]
+    i2c->write(DS1621_Write|address,(char *)&data,sizeof(data));
 }
\ No newline at end of file
diff -r 3160631567f2 -r d6310fd6df8e ds1621.h
--- a/ds1621.h	Mon Mar 07 08:12:27 2011 +0000
+++ b/ds1621.h	Mon Mar 21 16:51:22 2011 +0000
@@ -3,7 +3,8 @@
 //------------includes-----------------
 #include "mbed.h"
 //------------
-/** DS1621 simple control class,
+/**
+* DS1621 simple control class,
 *
 * Example:
 * @code
@@ -20,20 +21,21 @@
 *
 * Serial pc(USBTX, USBRX);  // Declare usb (see screen /dev/ttyUSB0 on linux)
 * I2C    i2c(p28, p27);     // Declare I2C (pullup resistors 2.2k from p28 and p27 to +3.3v)
-* DS1621 ds(&i2c, DS1621_ADDR, &pc);  // Declare ds1621 throught i2c interface with debugger on
+* DS1621 ds(&i2c, DS1621_ADDR);  // Declare ds1621 throught i2c interface
 *
 *int main() {
 *    i2c.frequency(5000); //5khz
 *    pc.printf("-----------------------\n\rMain\n\r");
 *    char count = 0;
 *    float temp = 0.0;
+*    ds.init(DS1621_ADDR);
 *    while (1) {
 *        myled1 = count & 0x01;
 *        myled2 = count & 0x02;
 *        myled3 = count & 0x04;
 *        myled4 = count & 0x08;
 *        count++;
-*        temp = ds.getTemp(DS1621_ADDR);
+*        temp = ds.read(DS1621_ADDR);
 *        pc.printf("Measurment at start + %d seconds, Temperature=%3.1f\n\r",(count*5),temp);
 *        wait(5.0);
 *    }
@@ -51,37 +53,29 @@
     *@brief Constructor, initializes the ds1621 on I2C interface.
     *@param interface
     *@param address DS1621 i2c address on bus
-    *@param dbx Debugging intreface if != NULL
     *@return none
     */
-    DS1621 (I2C* interface, uint8_t address, Serial* dbx = NULL);
+    DS1621 (I2C* interface, uint8_t address);
 
     /**
     *@brief Get temperature as float to the ds1621
     *@param address DS1621 i2c address on bus
     *@return current temperature as a float number in degrees Celsius
     */
-    float getTemp(uint8_t address);
-
+    float read(uint8_t address);
+    
     /**
-    *@brief Get the debugger interfave
-    *@return interface debugger used
+    *@brief Initialize DS1621
+    *@param address DS1621 i2c address on bus
+    *@return none
     */
-    Serial* getDebugger() {
-        return dbx;
-    }
+    void init(uint8_t address);
 
-    /**
-    *@brief Set the debugger interface
-    *@param dbx new debugger interface
-    */
-    void setDebugger(Serial* d) {
-        dbx = d;
-    }
+public:
+    bool dbx; // True activate debug message
 //---------- local variables ----------
 private:
     I2C* i2c; // Communication interface
-    Serial* dbx; // Debugger interface if != Null
 //-------------------------------------
 };
 #endif
\ No newline at end of file