library for ADT7410 temperature sensor first version

Revision:
1:131a836c6b79
Parent:
0:204e0aff1242
Child:
2:d12dffd027a8
--- a/adt7410.h	Wed Apr 16 23:21:24 2014 +0000
+++ b/adt7410.h	Sat Apr 26 18:12:59 2014 +0000
@@ -0,0 +1,95 @@
+/*
+  @file adt7410.h
+  
+  @brief Temperature Sensor ADT7410 Breakout I2C Library      
+
+  @Author lukasz uszko(luszko@op.pl)
+
+  Tested on FRDM-KL46Z
+  
+  Copyright (c) 2014 luszko
+  Released under the MIT License (see http://mbed.org/license/mit)
+
+  Documentation regarding the ADT7410 can be found here: 
+  http://www.analog.com/static/imported-files/data_sheets/ADT7410.pdf
+*/
+
+
+
+#ifndef ADT7410_H
+#define ADT7410_H
+
+#include "mbed.h"
+
+
+#define ADT7410_I2C_ADDRESS 0x4B    //A0 and A1 PIN are conected to VDD
+
+
+
+class ADT7410{
+    
+   public:
+
+    /** Create an ADT7410 instance
+     * @param sda pin 
+     * @param scl pin 
+     * @param address: I2C slave address 
+     */
+    ADT7410(PinName sda, PinName scl, int address = ADT7410_I2C_ADDRESS); 
+
+    /** Create a ADT7410 instance
+     * @param i2c object
+     * @param address: I2C slave address 
+     */
+    ADT7410(I2C& i2c, int address = ADT7410_I2C_ADDRESS); 
+
+    /** Initialization: set member values and read ADT7410 calibration parameter
+     * @returns
+     *    1 on success,
+     *    0 on error
+     */
+    int init(void );
+
+    /** Read temperature from the ADT7410.
+     * @param temperature (C) 
+     * @returns
+     *   1 on success,
+     *   0 on error
+     */    
+    int readTemp(float* pTemperature = NULL);
+
+    /** Get temperature from a previous measurement 
+     *  
+     * @returns
+     *   temperature (C)
+     */    
+    float getTemperature() {return m_temperature;};
+
+
+protected:
+
+    float m_temperature;     
+    I2C m_i2c;   
+    int m_addr;
+    char m_data[4];    
+    
+private: 
+
+    /** Write data to the given register
+     *  
+     * @returns
+     *   1 on success,
+     *   0 on error
+     */  
+    bool write(uint8_t regAddress, uint8_t data);
+    
+    int read(uint8_t regAddress);
+    
+    int read(uint8_t regAddress, uint8_t* data,int length);
+    
+    
+        
+
+};
+
+#endif
\ No newline at end of file